private void assertStringEncoded(String hex, String @string) { ByteString expectedUtf8 = ByteString.DecodeHex(hex); // Confirm our implementation matches those expectations. ByteString actualUtf8 = new EasyBuffer().WriteUtf8(@string).ReadByteString(); Assert.AreEqual(expectedUtf8, actualUtf8); //// Confirm our expectations are consistent with the platform. //ByteString platformUtf8 = ByteString.Of(Encoding.UTF8.GetBytes(@string)); //Assert.AreEqual(expectedUtf8, platformUtf8); // Confirm we are consistent when writing one code point at a time. var bufferUtf8 = new EasyBuffer(); for (int i = 0; i < @string.Length;) { int c = @string.CodePointAt(i); bufferUtf8.WriteUtf8CodePoint(c); i += Character.CharCount(c); } Assert.AreEqual(expectedUtf8, bufferUtf8.ReadByteString()); // Confirm we are consistent when measuring lengths. Assert.AreEqual(expectedUtf8.Size(), Utf8.Size(@string)); Assert.AreEqual(expectedUtf8.Size(), Utf8.Size(@string, 0, @string.Length())); }