From fdd8b71b338511b62b0643b1b2442a58a33dadb3 Mon Sep 17 00:00:00 2001 From: Roman Podymov Date: Thu, 14 Nov 2019 23:15:58 +0100 Subject: [PATCH 1/3] internal var -> internal let --- Sources/PathKit.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/PathKit.swift b/Sources/PathKit.swift index df1b047..c4f9c44 100644 --- a/Sources/PathKit.swift +++ b/Sources/PathKit.swift @@ -19,11 +19,11 @@ public struct Path { public static let separator = "/" /// The underlying string representation - internal var path: String + internal let path: String - internal static var fileManager = FileManager.default + internal static let fileManager = FileManager.default - internal var fileSystemInfo: FileSystemInfo = DefaultFileSystemInfo() + internal let fileSystemInfo: FileSystemInfo = DefaultFileSystemInfo() // MARK: Init From 23df1d4edc573f522635fb7c616e1254c1bb6608 Mon Sep 17 00:00:00 2001 From: Roman Podymov Date: Fri, 15 Nov 2019 14:19:19 +0100 Subject: [PATCH 2/3] New init functions --- Sources/PathKit.swift | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Sources/PathKit.swift b/Sources/PathKit.swift index c4f9c44..d298571 100644 --- a/Sources/PathKit.swift +++ b/Sources/PathKit.swift @@ -23,21 +23,31 @@ public struct Path { internal static let fileManager = FileManager.default - internal let fileSystemInfo: FileSystemInfo = DefaultFileSystemInfo() + internal let fileSystemInfo: FileSystemInfo // MARK: Init public init() { - self.path = "" + self.init("") } /// Create a Path from a given String public init(_ path: String) { + self.init(path, fileSystemInfo: DefaultFileSystemInfo()) + } + + internal init(_ path: String, fileSystemInfo: FileSystemInfo) { self.path = path + self.fileSystemInfo = fileSystemInfo } + internal init(fileSystemInfo: FileSystemInfo) { + self.init("", fileSystemInfo: fileSystemInfo) + } + /// Create a Path by joining multiple path components together public init(components: S) where S.Iterator.Element == String { + let path: String if components.isEmpty { path = "." } else if components.first == Path.separator && components.count > 1 { @@ -46,6 +56,7 @@ public struct Path { } else { path = components.joined(separator: Path.separator) } + self.init(path) } } @@ -65,7 +76,7 @@ extension Path : ExpressibleByStringLiteral { } public init(stringLiteral value: StringLiteralType) { - self.path = value + self.init(value) } } From e4d96ab0f9a85f05541c2ff24b959056b0fcfd9c Mon Sep 17 00:00:00 2001 From: Roman Podymov Date: Fri, 15 Nov 2019 14:22:56 +0100 Subject: [PATCH 3/3] Fixed tests --- Tests/PathKitTests/PathKitSpec.swift | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Tests/PathKitTests/PathKitSpec.swift b/Tests/PathKitTests/PathKitSpec.swift index e683d99..03efbf2 100644 --- a/Tests/PathKitTests/PathKitSpec.swift +++ b/Tests/PathKitTests/PathKitSpec.swift @@ -167,8 +167,7 @@ describe("PathKit") { $0.it("can abbreviate paths on a case sensitive fs") { let home = Path.home.string let fakeFSInfo = FakeFSInfo(caseSensitive: true) - var path = Path("\(home.uppercased())") - path.fileSystemInfo = fakeFSInfo + let path = Path("\(home.uppercased())", fileSystemInfo: fakeFSInfo) try expect(path.abbreviate().string) == home.uppercased() } @@ -176,8 +175,7 @@ describe("PathKit") { $0.it("can abbreviate paths on a case insensitive fs") { let home = Path.home.string let fakeFSInfo = FakeFSInfo(caseSensitive: false) - var path = Path("\(home.uppercased())") - path.fileSystemInfo = fakeFSInfo + let path = Path("\(home.uppercased())", fileSystemInfo: fakeFSInfo) try expect(path.abbreviate()) == Path("~") }