Skip to content

Commit

Permalink
Add method declaration and appropriate tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ikhsan committed Jan 16, 2018
1 parent 9d25d1c commit 8e0fdb9
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Sources/Files.swift
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,29 @@ public final class File: FileSystem.Item, FileSystemIterable {

try write(data: data)
}

/**
* Append data to the end of the file
*
* - parameter data: The data to append to the file
*
* - throws: `File.Error.writeFailed` if the file couldn't be written to
*/
public func append(data: Data) throws {
// TODO: Implement
}

/**
* Append a string to the end of the file
*
* - parameter string: The string to append to the file
* - parameter encoding: Optionally give which encoding that the string should be encoded in (defaults to UTF-8)
*
* - throws: `File.Error.writeFailed` if the string couldn't be encoded, or written to the file
*/
public func append(string: String, encoding: String.Encoding = .utf8) throws {
// TODO: Implement
}

/**
* Copy this file to a new folder
Expand Down
25 changes: 25 additions & 0 deletions Tests/FilesTests/FilesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,29 @@ class FilesTests: XCTestCase {
try XCTAssertEqual(file.read(), "New content".data(using: .utf8))
}
}

func testAppendingDataToFile() {
performTest {
let file = try folder.createFile(named: "file")
let data = "Old content\n".data(using: .utf8)!
try file.write(data: data)

let newData = "I'm the appended content 💯\n".data(using: .utf8)!
try file.append(data: newData)
try XCTAssertEqual(file.read(), "Old content\nI'm the appended content 💯\n".data(using: .utf8))
}
}

func testAppendingStringToFile() {
performTest {
let file = try folder.createFile(named: "file")
try file.write(string: "Old content\n")

let newString = "I'm the appended content 💯\n"
try file.append(string: newString)
try XCTAssertEqual(file.read(), "Old content\nI'm the appended content 💯\n".data(using: .utf8))
}
}

func testFileDescription() {
performTest {
Expand Down Expand Up @@ -717,6 +740,8 @@ class FilesTests: XCTestCase {
("testDeletingNonExistingFileThrows", testDeletingNonExistingFileThrows),
("testWritingDataToFile", testWritingDataToFile),
("testWritingStringToFile", testWritingStringToFile),
("testAppendingDataToFile", testAppendingDataToFile),
("testAppendingStringToFile", testAppendingStringToFile),
("testFileDescription", testFileDescription),
("testFolderDescription", testFolderDescription),
("testMovingFolderContents", testMovingFolderContents),
Expand Down

0 comments on commit 8e0fdb9

Please sign in to comment.