Skip to content

Commit 6420b98

Browse files
committed
thorough testing code from Swift lib to match
1 parent c519e4b commit 6420b98

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

TestFoundation/TestNSString.swift

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -940,17 +940,32 @@ class TestNSString : XCTestCase {
940940

941941
//[SR-1988] Ranges of String.UTF16View.Index have negative count
942942
func test_utf16StringRangeCount(){
943-
let str = "How many elements do I contain?".utf16
944-
let indices: Range = str.startIndex ..< str.endIndex
945-
XCTAssertEqual(indices.count , 31, "Range should be 31")
943+
let testStrings = ["", "\u{0000}", "a", "aa", "ab", "\u{007f}", "\u{0430}", "\u{0430}\u{0431}\u{0432}","\u{1f425}"]
946944

947-
let blank = "".utf16
948-
let blankindices: Range = blank.startIndex ..< blank.endIndex
949-
XCTAssertTrue(blankindices.count == 0, "Range should be 0")
945+
func checkStrideable<S : Strideable>(
946+
instances: [S],
947+
distances: [S.Stride],
948+
distanceOracle: (Int, Int) -> S.Stride
949+
) {
950+
for i in instances.indices {
951+
let first = instances[i]
952+
for j in instances.indices {
953+
let second = instances[j]
954+
XCTAssertTrue(distanceOracle(i, j) == first.distance(to: second))
955+
XCTAssertTrue(second == first.advanced(by: distanceOracle(i, j)))
956+
}
957+
}
958+
}
950959

951-
let one = "1".utf16
952-
let oneindices: Range = one.startIndex ..< one.endIndex
953-
XCTAssertTrue(oneindices.count == 1, "Range should be 1")
960+
testStrings.forEach{
961+
let utf16 = $0.utf16
962+
var indicies = Array(utf16.indices)
963+
indicies.append(utf16.indices.endIndex)
964+
965+
checkStrideable(instances: indicies,
966+
distances: Array(0..<utf16.count),
967+
distanceOracle: {$1 - $0})
968+
}
954969

955970
}
956971

0 commit comments

Comments
 (0)