public void ReserveAndWriteUtf8Subsequence() { String usAscii = "Some UTF-8 like äÄ∏ŒŒ"; IByteBuffer buf = Unpooled.Buffer(16); buf.WriteBytes(TextEncodings.UTF8NoBOM.GetBytes(usAscii.Substring(5, 18 - 5))); IByteBuffer buf2 = Unpooled.Buffer(16); int count = ByteBufferUtil.ReserveAndWriteUtf8(buf2, usAscii.AsSpan(5, 18 - 5), 16); Assert.Equal(buf, buf2); Assert.Equal(buf.ReadableBytes, count); buf.Release(); buf2.Release(); }
public void ReserveAndWriteUtf8InvalidSubsequences(int start, int end) { IByteBuffer buf = Unpooled.Buffer(16); try { ByteBufferUtil.ReserveAndWriteUtf8(buf, (AsciiString)"Some UTF-8 like äÄ∏ŒŒ", start, end, 32); Assert.False(true, "Did not throw IndexOutOfBoundsException for range (" + start + ", " + end + ")"); } catch (IndexOutOfRangeException) { // expected } finally { Assert.False(buf.IsReadable()); buf.Release(); } }