-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from daltonclaybrook/feature/extension-tests
Add tests for extensions
- Loading branch information
Showing
4 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import XCTest | ||
@testable import SettlerFramework | ||
|
||
final class ArrayAdditionsTests: XCTestCase { | ||
func testMutableForEach() { | ||
var nums = [1, 2, 3] | ||
nums.mutableForEach { $0 *= 2 } | ||
XCTAssertEqual(nums, [2, 4, 6]) | ||
} | ||
|
||
func testMapEachCombination() { | ||
let nums = [1, 2, 3, 4] | ||
let result = nums.mapEachCombination { $0 + $1 } | ||
XCTAssertEqual(result, [3, 4, 5, 5, 6, 7]) | ||
} | ||
|
||
func testFlatMapEachCombination() { | ||
let nums = [1, 2, 3, 4] | ||
let result = nums.flatMapEachCombination { [$0 + $1, -1] } | ||
XCTAssertEqual(result, [3, -1, 4, -1, 5, -1, 5, -1, 6, -1, 7, -1]) | ||
} | ||
|
||
func testReduceEachCombinationInto() { | ||
let nums = [1, 2, 3] | ||
let result = nums.reduceEachCombination(into: ["0"]) { result, first, second in | ||
result.append("\(first)\(second)") | ||
} | ||
XCTAssertEqual(result, ["0", "12", "13", "23"]) | ||
} | ||
|
||
func testCompactMapRemoving() { | ||
var nums = [0, 1, 2, 3, 4, 5, 6] | ||
let result = nums.compactMapRemoving { $0 % 2 == 0 ? $0 : nil } | ||
XCTAssertEqual(nums, [1, 3, 5]) | ||
XCTAssertEqual(result, [0, 2, 4, 6]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import XCTest | ||
@testable import SettlerFramework | ||
|
||
final class StringAdditionsTests: XCTestCase { | ||
func testPrefixIsStripped() { | ||
let key = "Key.Foo" | ||
let stripped = key.strippingPrefix("Key.") | ||
XCTAssertEqual(stripped, "Foo") | ||
} | ||
|
||
func testSuffixIsStripped() { | ||
let key = "Key.Foo" | ||
let stripped = key.strippingSuffix(".Foo") | ||
XCTAssertEqual(stripped, "Key") | ||
} | ||
|
||
func testPrefixAndSuffixAreStripped() { | ||
let key = "Lazy<Key.Foo>" | ||
let stripped = key.stripping(prefix: "Lazy<", andSuffix: ">") | ||
XCTAssertEqual(stripped, "Key.Foo") | ||
} | ||
|
||
func testSuffixIsNotStrippedWithoutPrefix() { | ||
let key = "Key.Foo>" | ||
let stripped = key.stripping(prefix: "Lazy<", andSuffix: ">") | ||
XCTAssertEqual(stripped, "Key.Foo>") | ||
} | ||
|
||
func testPrefixIsNotStrippedWithoutSuffix() { | ||
let key = "Lazy<Key.Foo" | ||
let stripped = key.stripping(prefix: "Lazy<", andSuffix: ">") | ||
XCTAssertEqual(stripped, "Lazy<Key.Foo") | ||
} | ||
|
||
func testDotPathIsExpandedCorrectly() { | ||
let relativePath = "./Sources" | ||
let absolutePath = relativePath.bridge().absolutePathRepresentation() | ||
let currentDirectory = FileManager.default.currentDirectoryPath | ||
let expected = "\(currentDirectory)/Sources" | ||
XCTAssertEqual(absolutePath, expected) | ||
} | ||
|
||
func testTildeIsExpandedCorrectly() { | ||
let tildePath = "~/Sources" | ||
let absolutePath = tildePath.bridge().absolutePathRepresentation() | ||
let homeDirectory = NSHomeDirectory() | ||
let expected = "\(homeDirectory)/Sources" | ||
XCTAssertEqual(absolutePath, expected) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters