Skip to content

Commit

Permalink
Update Path initalizer ExpressibleByStringLiteral
Browse files Browse the repository at this point in the history
  • Loading branch information
jihoonahn committed Jun 25, 2023
1 parent e66ff9e commit f9e0280
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
12 changes: 12 additions & 0 deletions Sources/PLFile/Path/PLFile+Path.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,18 @@ public struct Path {
}
}

extension Path: ExpressibleByStringLiteral {
public init(stringLiteral value: StringLiteralType) {
self.init(value)
}
public init(unicodeScalarLiteral value: String) {
self.init(value)
}
public init(extendedGraphemeClusterLiteral value: String) {
self.init(value)
}
}

//MARK: - subscript
extension Path {
/// A subscript that identifies the position of the path.
Expand Down
11 changes: 6 additions & 5 deletions Tests/PLFileTests/PLFileTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ final class PLFileTests: XCTestCase {
private var folder: PLFile.Folder!
override func setUp() {
super.setUp()
folder = try! PLFile.Folder(path: .home).createSubfolder(at: Path(".plfileTest"))
folder = try! PLFile.Folder(path: .home).createSubfolder(at: ".plfileTest")
try! folder.empty()
}

Expand All @@ -15,7 +15,7 @@ final class PLFileTests: XCTestCase {
}

func testingCreateFile() {
let file = try! folder.createFile(at: Path("test.swift"))
let file = try! folder.createFile(at: "test.swift")
XCTAssertEqual(file.name, "test.swift")
XCTAssertEqual(file.store.path.rawValue, folder.store.path.rawValue + "test.swift")
XCTAssertEqual(file.extension, "swift")
Expand All @@ -24,15 +24,16 @@ final class PLFileTests: XCTestCase {
}

func testingFileWrite() {
let file = try! folder.createFile(at: Path("testWrite.swift"))
let file = try! folder.createFile(at: "testWrite.swift")
try! file.write("print(1)")

try XCTAssertEqual(String(data: file.read(), encoding: .utf8), "print(1)")
}

func testingFileMove() {
let originFolder = try! folder.createSubfolder(at: Path("folderA"))
let targetFolder = try! folder.createSubfolder(at: Path("folderB"))
let originFolder = try! folder.createSubfolder(at: "folderA")
let targetFolder = try! folder.createSubfolder(at: "folderB")

try! originFolder.move(to: targetFolder)
XCTAssertEqual(originFolder.store.path.rawValue, folder.store.path.rawValue + "folderB/folderA/" )
}
Expand Down

0 comments on commit f9e0280

Please sign in to comment.