public void IsWellFormedUtf8String_WithStringOfAllPossibleScalarValues_ReturnsTrue() { // Arrange byte[] allScalarsAsUtf8 = _utf8EncodingWithoutReplacement.GetBytes(_stringWithAllScalars.Value); var buffer = NativeMemory.AllocateFromExistingData(allScalarsAsUtf8, PoisonPagePlacement.AfterSpan); buffer.MakeReadonly(); // Act & assert Assert.True(Utf8Utility.IsWellFormedUtf8String(buffer.Span)); buffer.Dispose(); }
public void IsWellFormedUtf8String_WithCorruptedStringOfAllPossibleScalarValues_ReturnsFalse() { // Arrange byte[] allScalarsAsUtf8 = _utf8EncodingWithoutReplacement.GetBytes(_stringWithAllScalars.Value); allScalarsAsUtf8[0x1000] ^= 0x80; // modify the high bit of one of the characters, which will corrupt the header var buffer = NativeMemory.AllocateFromExistingData(allScalarsAsUtf8, PoisonPagePlacement.AfterSpan); buffer.MakeReadonly(); // Act & assert Assert.False(Utf8Utility.IsWellFormedUtf8String(buffer.Span)); buffer.Dispose(); }