@@ -87,7 +87,7 @@ class TestNSString : XCTestCase {
87
87
( " test_ExternalRepresentation " , test_ExternalRepresentation) ,
88
88
( " test_mutableStringConstructor " , test_mutableStringConstructor) ,
89
89
( " test_PrefixSuffix " , test_PrefixSuffix) ,
90
- ( " test_utf16StringRangeCount " , test_utf16StringRangeCount ) ,
90
+ ( " test_utf16StringRangeCount " , test_StringUTF16ViewIndexStrideableRange ) ,
91
91
( " test_reflection " , { _ in test_reflection } ) ,
92
92
]
93
93
}
@@ -939,19 +939,31 @@ class TestNSString : XCTestCase {
939
939
}
940
940
941
941
//[SR-1988] Ranges of String.UTF16View.Index have negative count
942
- 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 " )
946
-
947
- let blank = " " . utf16
948
- let blankindices : Range = blank. startIndex ..< blank. endIndex
949
- XCTAssertTrue ( blankindices. count == 0 , " Range should be 0 " )
950
-
951
- let one = " 1 " . utf16
952
- let oneindices : Range = one. startIndex ..< one. endIndex
953
- XCTAssertTrue ( oneindices. count == 1 , " Range should be 1 " )
942
+ func test_StringUTF16ViewIndexStrideableRange( ) {
943
+ let testStrings = [ " " , " \u{0000} " , " a " , " aa " , " ab " , " \u{007f} " , " \u{0430} " , " \u{0430} \u{0431} \u{0432} " , " \u{1f425} " ]
954
944
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
+ }
959
+ testStrings. forEach {
960
+ let utf16 = $0. utf16
961
+ var indicies = Array ( utf16. indices)
962
+ indicies. append ( utf16. indices. endIndex)
963
+ checkStrideable ( instances: indicies,
964
+ distances: Array ( 0 ..< utf16. count) ,
965
+ distanceOracle: { $1 - $0} )
966
+ }
955
967
}
956
968
957
969
func test_mutableStringConstructor( ) {
0 commit comments