File tree Expand file tree Collapse file tree 2 files changed +9
-1
lines changed Expand file tree Collapse file tree 2 files changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ extension String.UTF16View.Index : Strideable {
21
21
}
22
22
23
23
public func distance( to other: String . UTF16View . Index ) -> Int {
24
- return other . _offset. distance ( to: _offset)
24
+ return _offset. distance ( to: other . _offset)
25
25
}
26
26
27
27
public func advanced( by n: Int ) -> String . UTF16View . Index {
Original file line number Diff line number Diff line change @@ -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,13 @@ 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 not be negative " )
946
+ }
947
+
940
948
func test_mutableStringConstructor( ) {
941
949
let mutableString = NSMutableString ( string: " Test " )
942
950
XCTAssertEqual ( mutableString, " Test " )
You can’t perform that action at this time.
0 commit comments