77using  System . Linq ; 
88using  System . Runtime . ExceptionServices ; 
99using  System . Runtime . InteropServices ; 
10+ using  System . Runtime . Intrinsics . X86 ; 
1011using  System . Threading ; 
1112using  System . Threading . Tasks ; 
1213using  Microsoft . DotNet . RemoteExecutor ; 
@@ -313,6 +314,7 @@ public static void IndexOfAny_InvalidUtf16()
313314            IndexOfAny ( StringComparison . OrdinalIgnoreCase ,  - 1 ,  " foO\uD801 bar" ,  "oo\uD800 baR, bar\uD800 foo" ) ; 
314315
315316            // Low surrogate without the high surrogate. 
317+             IndexOfAny ( StringComparison . OrdinalIgnoreCase ,  1 ,  "\uD801 \uDCD8 \uD8FB \uDCD8 " ,  "\uDCD8 " ) ; 
316318            IndexOfAny ( StringComparison . OrdinalIgnoreCase ,  1 ,  "\uD801 \uDCD8 \uD8FB \uDCD8 " ,  "foo, \uDCD8 " ) ; 
317319        } 
318320
@@ -337,6 +339,15 @@ public static void IndexOfAny_InvalidUtf16()
337339        [ InlineData ( "abcd!" ) ] 
338340        [ InlineData ( "abcdefgh" ) ] 
339341        [ InlineData ( "abcdefghi" ) ] 
342+         [ InlineData ( "123456789" ) ] 
343+         [ InlineData ( "123456789a" ) ] 
344+         [ InlineData ( "123456789ab" ) ] 
345+         [ InlineData ( "123456789abc" ) ] 
346+         [ InlineData ( "123456789abcd" ) ] 
347+         [ InlineData ( "123456789abcde" ) ] 
348+         [ InlineData ( "123456789abcdef" ) ] 
349+         [ InlineData ( "123456789abcdefg" ) ] 
350+         [ InlineData ( "123456789abcdefgh" ) ] 
340351        // Multiple values, but they all share the same prefix 
341352        [ InlineData ( "abc" ,  "ab" ,  "abcd" ) ] 
342353        // These should hit the Aho-Corasick implementation 
@@ -406,9 +417,25 @@ static void TestCore(string[] valuesArray)
406417                Values_ImplementsSearchValuesBase ( StringComparison . OrdinalIgnoreCase ,  valuesArray ) ; 
407418
408419                string  values  =  string . Join ( ", " ,  valuesArray ) ; 
420+                 string  text  =  valuesArray [ 0 ] ; 
409421
410-                 IndexOfAny ( StringComparison . Ordinal ,  0 ,  valuesArray [ 0 ] ,  values ) ; 
411-                 IndexOfAny ( StringComparison . OrdinalIgnoreCase ,  0 ,  valuesArray [ 0 ] ,  values ) ; 
422+                 IndexOfAny ( StringComparison . Ordinal ,  0 ,  text ,  values ) ; 
423+                 IndexOfAny ( StringComparison . OrdinalIgnoreCase ,  0 ,  text ,  values ) ; 
424+ 
425+                 // Replace every position in the text with a different character. 
426+                 foreach  ( StringComparison  comparisonType  in  new [ ]  {  StringComparison . Ordinal ,  StringComparison . OrdinalIgnoreCase  } ) 
427+                 { 
428+                     SearchValues < string >  stringValues  =  SearchValues . Create ( valuesArray ,  comparisonType ) ; 
429+ 
430+                     for  ( int  i  =  0 ;  i  <  text . Length  -  1 ;  i ++ ) 
431+                     { 
432+                         foreach  ( char  replacement  in  "AaBb _!\u00F6 " ) 
433+                         { 
434+                             string  newText  =  $ "{ text . AsSpan ( 0 ,  i ) } { replacement } { text . AsSpan ( i  +  1 ) } "; 
435+                             Assert . Equal ( IndexOfAnyReferenceImpl ( newText ,  valuesArray ,  comparisonType ) ,  newText . IndexOfAny ( stringValues ) ) ; 
436+                         } 
437+                     } 
438+                 } 
412439            } 
413440        } 
414441
@@ -499,6 +526,20 @@ public static void TestIndexOfAny_RandomInputs_Stress()
499526        { 
500527            RunStress ( ) ; 
501528
529+             if  ( RemoteExecutor . IsSupported  &&  Avx512F . IsSupported ) 
530+             { 
531+                 var  psi  =  new  ProcessStartInfo ( ) ; 
532+                 psi . Environment . Add ( "DOTNET_EnableAVX512F" ,  "0" ) ; 
533+                 RemoteExecutor . Invoke ( RunStress ,  new  RemoteInvokeOptions  {  StartInfo  =  psi ,  TimeOut  =  10  *  60  *  1000  } ) . Dispose ( ) ; 
534+             } 
535+ 
536+             if  ( RemoteExecutor . IsSupported  &&  Avx2 . IsSupported ) 
537+             { 
538+                 var  psi  =  new  ProcessStartInfo ( ) ; 
539+                 psi . Environment . Add ( "DOTNET_EnableAVX2" ,  "0" ) ; 
540+                 RemoteExecutor . Invoke ( RunStress ,  new  RemoteInvokeOptions  {  StartInfo  =  psi ,  TimeOut  =  10  *  60  *  1000  } ) . Dispose ( ) ; 
541+             } 
542+ 
502543            if  ( CanTestInvariantCulture ) 
503544            { 
504545                RunUsingInvariantCulture ( static  ( )  =>  RunStress ( ) ) ; 
0 commit comments