public void FindFirstCharToEncodeUtf8_IllFormedData_ReturnsIndexOfIllFormedSubsequence(byte[] utf8Data, int expectedIndex) { // Arrange var encoder = new ConfigurableScalarTextEncoder(_ => true /* allow everything */); // Act int actualIndex = encoder.FindFirstCharacterToEncodeUtf8(utf8Data); // Assert Assert.Equal(expectedIndex, actualIndex); }
public void FindFirstCharToEncodeUtf8_EmptyInput_ReturnsNegOne() { // Arrange var encoder = new ConfigurableScalarTextEncoder(_ => false /* disallow everything */); // Act int idxOfFirstByteToEncode = encoder.FindFirstCharacterToEncodeUtf8(ReadOnlySpan <byte> .Empty); // Assert Assert.Equal(-1, idxOfFirstByteToEncode); }
public void FindFirstCharToEncodeUtf8_WellFormedData_SomeCharsDisallowed() { // Arrange byte[] inputBytes = Encoding.UTF8.GetBytes("\U00000040\U00000400\U00004000\U00040000"); // code units of different lengths var encoder = new ConfigurableScalarTextEncoder(codePoint => codePoint != 0x4000 /* disallow U+4000, allow all else */); // Act int idxOfFirstByteToEncode = encoder.FindFirstCharacterToEncodeUtf8(inputBytes); // Assert Assert.Equal(3, idxOfFirstByteToEncode); }
public void FindFirstCharToEncodeUtf8_WellFormedData_AllCharsAllowed() { // Arrange byte[] inputBytes = Encoding.UTF8.GetBytes("\U00000040\U00000400\U00004000\U00040000"); // code units of different lengths var encoder = new ConfigurableScalarTextEncoder(_ => true /* allow everything */); // Act int idxOfFirstByteToEncode = encoder.FindFirstCharacterToEncodeUtf8(inputBytes); // Assert Assert.Equal(-1, idxOfFirstByteToEncode); }