@@ -87,6 +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
91
( " test_reflection " , { _ in test_reflection } ) ,
91
92
]
92
93
}
@@ -937,6 +938,22 @@ class TestNSString : XCTestCase {
937
938
}
938
939
}
939
940
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 not be negative " )
950
+
951
+ let one = " 1 " . utf16
952
+ let oneindices : Range = one. startIndex ..< one. endIndex
953
+ XCTAssertTrue ( oneindices. count == 1 , " Range should be 1 " )
954
+
955
+ }
956
+
940
957
func test_mutableStringConstructor( ) {
941
958
let mutableString = NSMutableString ( string: " Test " )
942
959
XCTAssertEqual ( mutableString, " Test " )
0 commit comments