Skip to content

Commit

Permalink
Make TestCode And ReadMeFile And Source Update
Browse files Browse the repository at this point in the history
gp
  • Loading branch information
jihoonahn committed Mar 9, 2023
1 parent 8e2203d commit 815dbdc
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 10 deletions.
51 changes: 50 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,52 @@
# PLFile

A description of this package.
Pelagornis File Management Library 📁

## Installation
PLFile was deployed as Swift Package Manager. Package to install in a project. Add as a dependent item within the swift manifest.
```swift
let package = Package(
...
dependencies: [
.package(url: "https://github.com/Pelagornis/PLFile.git", from: "1.0.0")
],
...
)
```
Then import the PLFile from thr location you want to use.

```swift
import PLFile
```

## Using

Path Setting.
```swift
let path = Path("/Users/ji-hoonahn/Desktop/") // example
```

Easy access path.
```swift
Path.root
Path.home
Path.current
Path.temporary
```

Create, Write file and Folder!
```swift
let folder = try! PLFile.Folder(path: .home)
let file = try! folder.createFile(at: Path("test.swift"))
try! file.write("print(1)")
```

And you can delete files and folders if you want.

```swift
try! file.delete()
try! folder.delete()
```

## License
**PLFile** is under MIT license. See the [LICENSE](LICENSE) file for more info.
6 changes: 1 addition & 5 deletions Sources/PLFile/Folder/PLFile+Folder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ extension PLFile.Folder {
public static var type: PLFileType {
return .folder
}
/// system Temporary
public static var temporary: PLFile.Folder {
return try! PLFile.Folder(path: Path(NSTemporaryDirectory()))
}


/// sequence contain all of this folder subfolder
var subfolders: ChildSequence<PLFile.Folder> {
return store.makeChildSequence()
Expand Down
3 changes: 3 additions & 0 deletions Sources/PLFile/Path/PLFile+Path.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ public struct Path {
/// home path
public static var home = Path("~")

/// system Temporary path
public static var temporary = Path(NSTemporaryDirectory())

/// standardized path
public var standardized: Path {
return Path((self.rawValue as NSString).standardizingPath)
Expand Down
22 changes: 18 additions & 4 deletions Tests/PLFileTests/PLFileTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import XCTest

final class PLFileTests: XCTestCase {
private var folder: PLFile.Folder!

override func setUp() {
super.setUp()
folder = try! PLFile.Folder(path: .home).createSubfolder(at: Path(".plfileTest"))
Expand All @@ -15,11 +14,26 @@ final class PLFileTests: XCTestCase {
super.tearDown()
}

func testingCreateFileAndDeleteFile() {
func testingCreateFile() {
let file = try! folder.createFile(at: Path("test.swift"))
print("Test: ⚠️ \(file.store.path)")
XCTAssertEqual(file.name, "test.swift")
XCTAssertEqual(file.store.path.rawValue, folder.store.path.rawValue + "test.swift")
XCTAssertEqual(file.extension, "swift")

try XCTAssertEqual(file.read(), Data())
}

func testingFileWrite() {
let file = try! folder.createFile(at: Path("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"))
try! originFolder.move(to: targetFolder)
XCTAssertEqual(originFolder.store.path.rawValue, folder.store.path.rawValue + "folderB/folderA/" )
}
}

0 comments on commit 815dbdc

Please sign in to comment.