add test files
This commit is contained in:
parent
301fbda0cf
commit
e610a52281
|
@ -7,14 +7,15 @@
|
|||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
259EE6222133C6D1005ECA44 /* Info.swift in Sources */ = {isa = PBXBuildFile; fileRef = 259EE6212133C6D1005ECA44 /* Info.swift */; };
|
||||
259EE6242133C915005ECA44 /* BasicOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 259EE6232133C915005ECA44 /* BasicOperation.swift */; };
|
||||
25BACE361F9F9E25000D5127 /* Errors.swift in Sources */ = {isa = PBXBuildFile; fileRef = 25BACE351F9F9E25000D5127 /* Errors.swift */; };
|
||||
25BACE381F9F9E6C000D5127 /* BasicOperation+Fileable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 25BACE371F9F9E6C000D5127 /* BasicOperation+Fileable.swift */; };
|
||||
25BACE3A1F9F9EB3000D5127 /* Info+Fileable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 25BACE391F9F9EB3000D5127 /* Info+Fileable.swift */; };
|
||||
25BACE3C1F9F9EDE000D5127 /* Utils+Fileable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 25BACE3B1F9F9EDE000D5127 /* Utils+Fileable.swift */; };
|
||||
25BACE3E1F9F9F12000D5127 /* iOS+Fileable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 25BACE3D1F9F9F12000D5127 /* iOS+Fileable.swift */; };
|
||||
25BACE401F9F9F36000D5127 /* Linux+Fileable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 25BACE3F1F9F9F36000D5127 /* Linux+Fileable.swift */; };
|
||||
25BACE401F9F9F36000D5127 /* FHS+Fileable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 25BACE3F1F9F9F36000D5127 /* FHS+Fileable.swift */; };
|
||||
D93F1CA21EAEDB6E009A7474 /* Fileable.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D93F1C981EAEDB6E009A7474 /* Fileable.framework */; };
|
||||
D93F1CA71EAEDB6E009A7474 /* FileableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D93F1CA61EAEDB6E009A7474 /* FileableTests.swift */; };
|
||||
D93F1CB31EAEDCC9009A7474 /* Fileable.swift in Sources */ = {isa = PBXBuildFile; fileRef = D93F1CB21EAEDCC9009A7474 /* Fileable.swift */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
|
@ -29,16 +30,17 @@
|
|||
/* End PBXContainerItemProxy section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
259EE6212133C6D1005ECA44 /* Info.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Info.swift; sourceTree = "<group>"; };
|
||||
259EE6232133C915005ECA44 /* BasicOperation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BasicOperation.swift; sourceTree = "<group>"; };
|
||||
25BACE351F9F9E25000D5127 /* Errors.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Errors.swift; sourceTree = "<group>"; };
|
||||
25BACE371F9F9E6C000D5127 /* BasicOperation+Fileable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "BasicOperation+Fileable.swift"; sourceTree = "<group>"; };
|
||||
25BACE391F9F9EB3000D5127 /* Info+Fileable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Info+Fileable.swift"; sourceTree = "<group>"; };
|
||||
25BACE3B1F9F9EDE000D5127 /* Utils+Fileable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Utils+Fileable.swift"; sourceTree = "<group>"; };
|
||||
25BACE3D1F9F9F12000D5127 /* iOS+Fileable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "iOS+Fileable.swift"; sourceTree = "<group>"; };
|
||||
25BACE3F1F9F9F36000D5127 /* Linux+Fileable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Linux+Fileable.swift"; sourceTree = "<group>"; };
|
||||
25BACE3F1F9F9F36000D5127 /* FHS+Fileable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "FHS+Fileable.swift"; sourceTree = "<group>"; };
|
||||
D93F1C981EAEDB6E009A7474 /* Fileable.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Fileable.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
D93F1C9C1EAEDB6E009A7474 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
D93F1CA11EAEDB6E009A7474 /* FileableTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = FileableTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
D93F1CA61EAEDB6E009A7474 /* FileableTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileableTests.swift; sourceTree = "<group>"; };
|
||||
D93F1CA81EAEDB6E009A7474 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
D93F1CB21EAEDCC9009A7474 /* Fileable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Fileable.swift; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
@ -71,7 +73,7 @@
|
|||
25BACE391F9F9EB3000D5127 /* Info+Fileable.swift */,
|
||||
25BACE3B1F9F9EDE000D5127 /* Utils+Fileable.swift */,
|
||||
25BACE3D1F9F9F12000D5127 /* iOS+Fileable.swift */,
|
||||
25BACE3F1F9F9F36000D5127 /* Linux+Fileable.swift */,
|
||||
25BACE3F1F9F9F36000D5127 /* FHS+Fileable.swift */,
|
||||
);
|
||||
path = Fileable;
|
||||
sourceTree = "<group>";
|
||||
|
@ -107,8 +109,9 @@
|
|||
D93F1CA51EAEDB6E009A7474 /* Tests */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
D93F1CA61EAEDB6E009A7474 /* FileableTests.swift */,
|
||||
D93F1CA81EAEDB6E009A7474 /* Info.plist */,
|
||||
259EE6212133C6D1005ECA44 /* Info.swift */,
|
||||
259EE6232133C915005ECA44 /* BasicOperation.swift */,
|
||||
);
|
||||
path = Tests;
|
||||
sourceTree = "<group>";
|
||||
|
@ -237,7 +240,7 @@
|
|||
25BACE3A1F9F9EB3000D5127 /* Info+Fileable.swift in Sources */,
|
||||
25BACE361F9F9E25000D5127 /* Errors.swift in Sources */,
|
||||
25BACE381F9F9E6C000D5127 /* BasicOperation+Fileable.swift in Sources */,
|
||||
25BACE401F9F9F36000D5127 /* Linux+Fileable.swift in Sources */,
|
||||
25BACE401F9F9F36000D5127 /* FHS+Fileable.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -245,7 +248,8 @@
|
|||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
D93F1CA71EAEDB6E009A7474 /* FileableTests.swift in Sources */,
|
||||
259EE6242133C915005ECA44 /* BasicOperation.swift in Sources */,
|
||||
259EE6222133C6D1005ECA44 /* Info.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>IDEDidComputeMac32BitWarning</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
|
@ -36,6 +36,7 @@ github "shotastage/Fileable"
|
|||
| `func home() -> Strings` | Get home directory path.|
|
||||
| `func isFile(file: String) -> Bool` | Check the file exists or not. |
|
||||
| `func isDir(path: String) -> Bool ` | Check the directory exists or not.|
|
||||
| `func ext(path: String) -> Bool ` | Check the directory exists or not.|
|
||||
| `func cd(path: String) throws`| Change directory like a `cd` command.|
|
||||
| `func mkdir(path: String) throws` | Make directory. |
|
||||
| `func rm(target: String) throws`| Remove directory or file. |
|
||||
|
|
|
@ -10,7 +10,7 @@ import Foundation
|
|||
|
||||
extension Fileable {
|
||||
|
||||
public func cd(_ path: String) throws {
|
||||
public static func cd(_ path: String) throws {
|
||||
if !Fileable.fm.changeCurrentDirectoryPath(path) {
|
||||
if !Fileable.fm.fileExists(atPath: path) {
|
||||
throw FileableError.NotExists
|
||||
|
@ -20,7 +20,7 @@ extension Fileable {
|
|||
}
|
||||
}
|
||||
|
||||
public func mkdir(_ path: String) throws {
|
||||
public static func mkdir(_ path: String) throws {
|
||||
try Fileable.fm.createDirectory(atPath: path, withIntermediateDirectories: true, attributes: nil)
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
//
|
||||
// Linux+Fileable.swift
|
||||
// Fileable
|
||||
//
|
||||
// Created by Shota Shimazu on 2017/10/25.
|
||||
// Copyright © 2017-2018 Shota Shimazu. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
public typealias UNIXfs = FHS
|
||||
|
||||
public enum FHS {
|
||||
|
||||
case root
|
||||
case settings
|
||||
case optional
|
||||
|
||||
var path: String! {
|
||||
switch self {
|
||||
case .root:
|
||||
return "/"
|
||||
case .settings:
|
||||
return "/etc/"
|
||||
case .optional:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
}
|
|
@ -10,9 +10,6 @@ import Foundation
|
|||
|
||||
open class Fileable {
|
||||
|
||||
// Define typealias
|
||||
public typealias Path = String
|
||||
|
||||
// Path
|
||||
internal var path: String
|
||||
|
||||
|
@ -22,10 +19,11 @@ open class Fileable {
|
|||
|
||||
// Initializers
|
||||
public init() {
|
||||
self.path = ""
|
||||
self.path = Fileable.pwd
|
||||
}
|
||||
|
||||
public init(_ path: String) {
|
||||
self.path = path
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,14 +15,14 @@ extension Fileable {
|
|||
|
||||
/// Get current working directory.
|
||||
/// - returns: Return current directory path as a string.
|
||||
public func pwd() -> String {
|
||||
public static var pwd: String {
|
||||
let path = Fileable.fm.currentDirectoryPath
|
||||
return path
|
||||
}
|
||||
|
||||
/// Get home directory.
|
||||
/// - returns: Return home directory path as a string.
|
||||
public func home() -> String {
|
||||
public static var home: String {
|
||||
let path = NSHomeDirectory()
|
||||
return path
|
||||
}
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
//
|
||||
// Linux+Fileable.swift
|
||||
// Fileable
|
||||
//
|
||||
// Created by Shota Shimazu on 2017/10/25.
|
||||
// Copyright © 2017-2018 Shota Shimazu. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
struct UbuntuFileSystem {
|
||||
let formatType = "ext4"
|
||||
let root = "/"
|
||||
let settings = "/etc"
|
||||
let optional = "/opt"
|
||||
}
|
|
@ -13,10 +13,12 @@ import Foundation
|
|||
|
||||
extension Fileable {
|
||||
|
||||
@available(*, unavailable, renamed: "iOSFileSystem.document.path")
|
||||
static func appDocument() -> String {
|
||||
return NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
|
||||
}
|
||||
|
||||
@available(*, unavailable, renamed: "iOSFileSystem.cache.path")
|
||||
static func appCache() -> String {
|
||||
return NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true)[0]
|
||||
}
|
||||
|
@ -25,11 +27,11 @@ import Foundation
|
|||
//
|
||||
// URL Converter
|
||||
//
|
||||
static func toURL(string: String) -> URL {
|
||||
public static func toURL(string: String) -> URL {
|
||||
return URL(fileURLWithPath: string)
|
||||
}
|
||||
|
||||
static func toString(fileURL: URL) throws -> String {
|
||||
public static func toString(fileURL: URL) throws -> String {
|
||||
|
||||
let stringURL: String
|
||||
do {
|
||||
|
@ -42,5 +44,25 @@ import Foundation
|
|||
return stringURL
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public typealias MobileFS = iOSFileSystem
|
||||
|
||||
public enum iOSFileSystem {
|
||||
case document
|
||||
case cache
|
||||
|
||||
var path: String! {
|
||||
switch self {
|
||||
|
||||
case .document:
|
||||
return NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
|
||||
case .cache:
|
||||
return NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true)[0]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
//
|
||||
// BasicOperation.swift
|
||||
// FileableTests
|
||||
//
|
||||
// Created by Shota Shimazu on 2018/08/27.
|
||||
// Copyright © 2018 Shota Shimazu. All rights reserved.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
@testable import Fileable
|
||||
|
||||
|
||||
class BasicOperation: XCTestCase {
|
||||
|
||||
override func setUp() {
|
||||
// Put setup code here. This method is called before the invocation of each test method in the class.
|
||||
}
|
||||
|
||||
override func tearDown() {
|
||||
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
||||
}
|
||||
|
||||
func testCd() {
|
||||
// This is an example of a functional test case.
|
||||
// Use XCTAssert and related functions to verify your tests produce the correct results.
|
||||
|
||||
let current: String = Fileable.pwd
|
||||
|
||||
try? Fileable.cd(Fileable.pwd)
|
||||
|
||||
let moved: String = Fileable.pwd
|
||||
|
||||
XCTAssertEqual(current, moved)
|
||||
}
|
||||
|
||||
|
||||
func testMkdir() {
|
||||
try? Fileable.mkdir("TEST_DIR")
|
||||
|
||||
XCTAssertTrue(Fileable(Fileable.pwd + "/TEST_DIR").isDir)
|
||||
}
|
||||
|
||||
func testPerformanceExample() {
|
||||
// This is an example of a performance test case.
|
||||
self.measure {
|
||||
// Put the code you want to measure the time of here.
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
//
|
||||
// Info.swift
|
||||
// FileableTests
|
||||
//
|
||||
// Created by Shota Shimazu on 2018/08/27.
|
||||
// Copyright © 2018 Shota Shimazu. All rights reserved.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
@testable import Fileable
|
||||
|
||||
|
||||
class Info: XCTestCase {
|
||||
|
||||
override func setUp() {
|
||||
// Put setup code here. This method is called before the invocation of each test method in the class.
|
||||
}
|
||||
|
||||
override func tearDown() {
|
||||
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
||||
}
|
||||
|
||||
func testCaseIsDir() {
|
||||
// This is an example of a functional test case.
|
||||
// Use XCTAssert and related functions to verify your tests produce the correct results.
|
||||
let path: String = Fileable.home
|
||||
|
||||
XCTAssertTrue(Fileable(path).isDir)
|
||||
}
|
||||
|
||||
func testCaseIsFile() {
|
||||
// This is an example of a functional test case.
|
||||
// Use XCTAssert and related functions to verify your tests produce the correct results.
|
||||
let file: String = Fileable.home
|
||||
|
||||
XCTAssertFalse(Fileable(file).isFile)
|
||||
|
||||
}
|
||||
|
||||
func testPerformanceExample() {
|
||||
// This is an example of a performance test case.
|
||||
|
||||
let path: String = Fileable.home
|
||||
|
||||
self.measure {
|
||||
if Fileable(path).isDir {
|
||||
NSLog(path, "is", "directory", ".")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue