@@ -157,6 +157,28 @@ func checkStringComparison(
157157 expectEqual ( expected. isGE ( ) , lhs >= rhs, stackTrace: stackTrace)
158158 expectEqual ( expected. isGT ( ) , lhs > rhs, stackTrace: stackTrace)
159159 checkComparable ( expected, lhs, rhs, stackTrace: stackTrace. withCurrentLoc ( ) )
160+
161+ // Substring / Substring
162+ // Matching slices of != Strings may still be ==, but not vice versa
163+ if expected. isEQ ( ) {
164+ for i in 0 ..< Swift . min ( lhs. count, rhs. count) {
165+ let lhsSub = lhs. dropFirst ( i)
166+ let rhsSub = rhs. dropFirst ( i)
167+
168+ expectEqual ( expected. isEQ ( ) , lhsSub == rhsSub, stackTrace: stackTrace)
169+ expectEqual ( expected. isNE ( ) , lhsSub != rhsSub, stackTrace: stackTrace)
170+ checkHashable (
171+ expectedEqual: expected. isEQ ( ) ,
172+ lhs, rhs, stackTrace: stackTrace. withCurrentLoc ( ) )
173+
174+ expectEqual ( expected. isLT ( ) , lhsSub < rhsSub, stackTrace: stackTrace)
175+ expectEqual ( expected. isLE ( ) , lhsSub <= rhsSub, stackTrace: stackTrace)
176+ expectEqual ( expected. isGE ( ) , lhsSub >= rhsSub, stackTrace: stackTrace)
177+ expectEqual ( expected. isGT ( ) , lhsSub > rhsSub, stackTrace: stackTrace)
178+ checkComparable (
179+ expected, lhsSub, rhsSub, stackTrace: stackTrace. withCurrentLoc ( ) )
180+ }
181+ }
160182
161183#if _runtime(_ObjC)
162184 // NSString / NSString
@@ -471,5 +493,15 @@ StringTests.test("Regression/corelibs-foundation") {
471493 expectEqual ( substring ( of: s5, with: NSFakeRange ( 1 , 6 ) ) , " \n cats� " )
472494}
473495
496+ StringTests . test ( " Regression/radar-87371813 " ) {
497+ let s1 = " what♕/ " . dropFirst ( 5 )
498+ let s2 = " / " [ ... ]
499+ let s3 = " /⚅ " . dropLast ( )
500+ expectEqual ( s1, s2)
501+ expectEqual ( s1, s3)
502+ expectEqual ( s1, s3)
503+ expectEqual ( s1. hashValue, s2. hashValue)
504+ expectEqual ( s2. hashValue, s3. hashValue)
505+ }
474506
475507runAllTests ( )
0 commit comments