@@ -188,6 +188,7 @@ public void BadSequences(Utf8ValidationDelegate utf8ValidationDelegate)
188
188
fixed ( byte * pInput = input )
189
189
{
190
190
ValidateUtf8 ( input , utf8ValidationDelegate ) ;
191
+ ValidateCount ( input , utf8ValidationDelegate ) ;
191
192
}
192
193
}
193
194
}
@@ -249,6 +250,7 @@ public void NoError(Utf8ValidationDelegate utf8ValidationDelegate)
249
250
bool isValidUtf8 = ValidateUtf8 ( utf8 , utf8ValidationDelegate ) ;
250
251
string utf8HexString = BitConverter . ToString ( utf8 ) . Replace ( "-" , " " ) ;
251
252
Assert . True ( isValidUtf8 , $ "Failure NoErrorTest. Sequence: { utf8HexString } ") ;
253
+ ValidateCount ( utf8 , utf8ValidationDelegate ) ;
252
254
}
253
255
}
254
256
}
@@ -310,6 +312,7 @@ private void RunTestForByteLength(int byteLength,Utf8ValidationDelegate utf8Vali
310
312
byte [ ] utf8 = generator . Generate ( outputLength , byteLength ) . ToArray ( ) ;
311
313
bool isValidUtf8 = ValidateUtf8 ( utf8 , utf8ValidationDelegate ) ;
312
314
Assert . True ( isValidUtf8 , $ "Failure for { byteLength } -byte UTF8 of length { outputLength } in trial { trial } ") ;
315
+ ValidateCount ( utf8 , utf8ValidationDelegate ) ;
313
316
}
314
317
}
315
318
}
@@ -369,6 +372,7 @@ public void BadHeaderBits(Utf8ValidationDelegate utf8ValidationDelegate)
369
372
utf8 [ i ] = 0b11111000 ; // Forcing a header bits error
370
373
Assert . False ( ValidateUtf8 ( utf8 , utf8ValidationDelegate ) ) ;
371
374
Assert . True ( InvalidateUtf8 ( utf8 , i , utf8ValidationDelegate ) ) ;
375
+ ValidateCount ( utf8 , utf8ValidationDelegate ) ;
372
376
utf8 [ i ] = oldByte ; // Restore the original byte
373
377
}
374
378
}
@@ -432,6 +436,7 @@ public void TooShortError(Utf8ValidationDelegate utf8ValidationDelegate)
432
436
utf8 [ i ] = 0b11100000 ; // Forcing a too short error
433
437
Assert . False ( ValidateUtf8 ( utf8 , utf8ValidationDelegate ) ) ;
434
438
Assert . True ( InvalidateUtf8 ( utf8 , i , utf8ValidationDelegate ) ) ;
439
+ ValidateCount ( utf8 , utf8ValidationDelegate ) ;
435
440
utf8 [ i ] = oldByte ; // Restore the original byte
436
441
}
437
442
}
@@ -498,6 +503,7 @@ public void TooLongError(Utf8ValidationDelegate utf8ValidationDelegate)
498
503
utf8 [ i ] = 0b10000000 ; // Forcing a too long error
499
504
Assert . False ( ValidateUtf8 ( utf8 , utf8ValidationDelegate ) ) ;
500
505
Assert . True ( InvalidateUtf8 ( utf8 , i , utf8ValidationDelegate ) ) ;
506
+ ValidateCount ( utf8 , utf8ValidationDelegate ) ;
501
507
utf8 [ i ] = oldByte ; // Restore the original byte
502
508
}
503
509
}
@@ -577,6 +583,7 @@ public void OverlongError(Utf8ValidationDelegate utf8ValidationDelegate)
577
583
578
584
Assert . False ( ValidateUtf8 ( utf8 , utf8ValidationDelegate ) ) ;
579
585
Assert . True ( InvalidateUtf8 ( utf8 , i , utf8ValidationDelegate ) ) ;
586
+ ValidateCount ( utf8 , utf8ValidationDelegate ) ;
580
587
581
588
utf8 [ i ] = old ;
582
589
utf8 [ i + 1 ] = secondOld ;
@@ -665,6 +672,8 @@ public void TooShortErrorAtEnd(Utf8ValidationDelegate utf8ValidationDelegate)
665
672
666
673
byte * dotnetResult = DotnetRuntime . Utf8Utility . GetPointerToFirstInvalidByte ( pInput , i + offset , out SimdUnicodeUtf16Adjustment , out SimdUnicodeScalarCountAdjustment ) ;
667
674
Assert . True ( dotnetResult == pInput + i + offset ) ;
675
+
676
+ ValidateCount ( utf8 , utf8ValidationDelegate ) ;
668
677
}
669
678
670
679
}
@@ -737,6 +746,7 @@ public void Invalid0xf50xff(Utf8ValidationDelegate utf8ValidationDelegate)
737
746
738
747
Assert . False ( ValidateUtf8 ( utf8 , utf8ValidationDelegate ) ) ; // Expect the validation to fail due to the invalid byte
739
748
Assert . True ( InvalidateUtf8 ( utf8 , position , utf8ValidationDelegate ) ) ;
749
+ ValidateCount ( utf8 , utf8ValidationDelegate ) ;
740
750
}
741
751
}
742
752
}
@@ -819,6 +829,7 @@ public void TooLargeError(Utf8ValidationDelegate utf8ValidationDelegate)
819
829
820
830
Assert . False ( ValidateUtf8 ( utf8 , utf8ValidationDelegate ) ) ;
821
831
Assert . True ( InvalidateUtf8 ( utf8 , i , utf8ValidationDelegate ) ) ;
832
+ ValidateCount ( utf8 , utf8ValidationDelegate ) ;
822
833
utf8 [ i ] = old ;
823
834
}
824
835
}
@@ -888,6 +899,7 @@ public void TooLargeErrorAtEnd(Utf8ValidationDelegate utf8ValidationDelegate)
888
899
889
900
Assert . False ( ValidateUtf8 ( filler , utf8ValidationDelegate ) ) ;
890
901
Assert . True ( InvalidateUtf8 ( filler , outputLength - 1 , utf8ValidationDelegate ) ) ;
902
+ ValidateCount ( filler , utf8ValidationDelegate ) ;
891
903
}
892
904
893
905
@@ -963,6 +975,7 @@ public void SurrogateErrorTest(Utf8ValidationDelegate utf8ValidationDelegate)
963
975
964
976
Assert . False ( ValidateUtf8 ( utf8 , utf8ValidationDelegate ) ) ;
965
977
Assert . True ( InvalidateUtf8 ( utf8 , i , utf8ValidationDelegate ) ) ;
978
+ ValidateCount ( utf8 , utf8ValidationDelegate ) ;
966
979
}
967
980
968
981
utf8 [ i ] = old ;
@@ -1044,6 +1057,7 @@ public void BruteForceTest(Utf8ValidationDelegate utf8ValidationDelegate)
1044
1057
// Validate the modified sequence with both methods
1045
1058
bool isValidPrimary = ValidateUtf8 ( modifiedUtf8 , utf8ValidationDelegate ) ;
1046
1059
bool isValidFuschia = ValidateUtf8Fuschia ( modifiedUtf8 ) ;
1060
+ ValidateCount ( modifiedUtf8 , utf8ValidationDelegate ) ;
1047
1061
1048
1062
// Ensure both methods agree on the validation result
1049
1063
Assert . Equal ( isValidPrimary , isValidFuschia ) ;
0 commit comments