@@ -262,3 +262,41 @@ fn test_reverse_search_shared_bytes() {
262
262
[ InRange ( 37 , 40 ) , Rejects ( 34 , 37 ) , InRange ( 10 , 13 ) , Rejects ( 8 , 10 ) , Done ]
263
263
) ;
264
264
}
265
+
266
+ #[ test]
267
+ fn double_ended_regression_test ( ) {
268
+ // https://github.com/rust-lang/rust/issues/47175
269
+ // Ensures that double ended searching comes to a convergence
270
+ search_asserts ! ( "abcdeabcdeabcde" , 'a' , "alternating double ended search" ,
271
+ [ next_match, next_match_back, next_match, next_match_back] ,
272
+ [ InRange ( 0 , 1 ) , InRange ( 10 , 11 ) , InRange ( 5 , 6 ) , Done ]
273
+ ) ;
274
+ search_asserts ! ( "abcdeabcdeabcde" , 'a' , "triple double ended search for a" ,
275
+ [ next_match, next_match_back, next_match_back, next_match_back] ,
276
+ [ InRange ( 0 , 1 ) , InRange ( 10 , 11 ) , InRange ( 5 , 6 ) , Done ]
277
+ ) ;
278
+ search_asserts ! ( "abcdeabcdeabcde" , 'd' , "triple double ended search for d" ,
279
+ [ next_match, next_match_back, next_match_back, next_match_back] ,
280
+ [ InRange ( 3 , 4 ) , InRange ( 13 , 14 ) , InRange ( 8 , 9 ) , Done ]
281
+ ) ;
282
+ search_asserts ! ( STRESS , 'Á' , "Double ended search for two-byte Latin character" ,
283
+ [ next_match, next_match_back, next_match, next_match_back] ,
284
+ [ InRange ( 0 , 2 ) , InRange ( 32 , 34 ) , InRange ( 8 , 10 ) , Done ]
285
+ ) ;
286
+ search_asserts ! ( STRESS , '각' , "Reverse double ended search for three-byte Hangul character" ,
287
+ [ next_match_back, next_back, next_match, next, next_match_back, next_match] ,
288
+ [ InRange ( 34 , 37 ) , Rejects ( 32 , 34 ) , InRange ( 19 , 22 ) , Rejects ( 22 , 25 ) , InRange ( 28 , 31 ) , Done ]
289
+ ) ;
290
+ search_asserts ! ( STRESS , 'ก' , "Double ended search for three-byte Thai character" ,
291
+ [ next_match, next_back, next, next_match_back, next_match] ,
292
+ [ InRange ( 22 , 25 ) , Rejects ( 47 , 48 ) , Rejects ( 25 , 28 ) , InRange ( 40 , 43 ) , Done ]
293
+ ) ;
294
+ search_asserts ! ( STRESS , '😁' , "Double ended search for four-byte emoji" ,
295
+ [ next_match_back, next, next_match, next_back, next_match] ,
296
+ [ InRange ( 43 , 47 ) , Rejects ( 0 , 2 ) , InRange ( 15 , 19 ) , Rejects ( 40 , 43 ) , Done ]
297
+ ) ;
298
+ search_asserts ! ( STRESS , 'ꁁ' , "Double ended search for three-byte Yi character with repeated bytes" ,
299
+ [ next_match, next, next_match_back, next_back, next_match] ,
300
+ [ InRange ( 10 , 13 ) , Rejects ( 13 , 14 ) , InRange ( 37 , 40 ) , Rejects ( 34 , 37 ) , Done ]
301
+ ) ;
302
+ }
0 commit comments