7
7
using System . Linq ;
8
8
using System . Runtime . ExceptionServices ;
9
9
using System . Runtime . InteropServices ;
10
+ using System . Runtime . Intrinsics . X86 ;
10
11
using System . Threading ;
11
12
using System . Threading . Tasks ;
12
13
using Microsoft . DotNet . RemoteExecutor ;
@@ -313,6 +314,7 @@ public static void IndexOfAny_InvalidUtf16()
313
314
IndexOfAny ( StringComparison . OrdinalIgnoreCase , - 1 , " foO\uD801 bar" , "oo\uD800 baR, bar\uD800 foo" ) ;
314
315
315
316
// Low surrogate without the high surrogate.
317
+ IndexOfAny ( StringComparison . OrdinalIgnoreCase , 1 , "\uD801 \uDCD8 \uD8FB \uDCD8 " , "\uDCD8 " ) ;
316
318
IndexOfAny ( StringComparison . OrdinalIgnoreCase , 1 , "\uD801 \uDCD8 \uD8FB \uDCD8 " , "foo, \uDCD8 " ) ;
317
319
}
318
320
@@ -337,6 +339,15 @@ public static void IndexOfAny_InvalidUtf16()
337
339
[ InlineData ( "abcd!" ) ]
338
340
[ InlineData ( "abcdefgh" ) ]
339
341
[ 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" ) ]
340
351
// Multiple values, but they all share the same prefix
341
352
[ InlineData ( "abc" , "ab" , "abcd" ) ]
342
353
// These should hit the Aho-Corasick implementation
@@ -406,9 +417,25 @@ static void TestCore(string[] valuesArray)
406
417
Values_ImplementsSearchValuesBase ( StringComparison . OrdinalIgnoreCase , valuesArray ) ;
407
418
408
419
string values = string . Join ( ", " , valuesArray ) ;
420
+ string text = valuesArray [ 0 ] ;
409
421
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
+ }
412
439
}
413
440
}
414
441
@@ -499,6 +526,20 @@ public static void TestIndexOfAny_RandomInputs_Stress()
499
526
{
500
527
RunStress ( ) ;
501
528
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
+
502
543
if ( CanTestInvariantCulture )
503
544
{
504
545
RunUsingInvariantCulture ( static ( ) => RunStress ( ) ) ;
0 commit comments