Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace all internal var with let #71

Merged
merged 3 commits into from
Feb 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions Sources/PathKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,35 @@ 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

// 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<S : Collection>(components: S) where S.Iterator.Element == String {
let path: String
if components.isEmpty {
path = "."
} else if components.first == Path.separator && components.count > 1 {
Expand All @@ -46,6 +56,7 @@ public struct Path {
} else {
path = components.joined(separator: Path.separator)
}
self.init(path)
}
}

Expand All @@ -65,7 +76,7 @@ extension Path : ExpressibleByStringLiteral {
}

public init(stringLiteral value: StringLiteralType) {
self.path = value
self.init(value)
}
}

Expand Down
6 changes: 2 additions & 4 deletions Tests/PathKitTests/PathKitSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -167,17 +167,15 @@ 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()
}

$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("~")
}
Expand Down