public void MixReadAndReadBufferWithMultipleStreams() { var stack = new BinaryStreamStack(Encoding.UTF8); stack.Push(TestUtil.StringToByteNoBom("7inners")); stack.Push(TestUtil.StringToByteNoBom("6chars")); var buffer = new byte[2]; Assert.Equal(stack.Read(), '6'); int amountRead = stack.Read(buffer, 0, buffer.Length); Assert.Equal(Encoding.UTF8.GetString(buffer), "ch"); Assert.Equal(amountRead, 2); Assert.Equal(stack.Read(), 'a'); Assert.Equal(stack.Read(), 'r'); amountRead = stack.Read(buffer, 0, buffer.Length); Assert.Equal(Encoding.UTF8.GetString(buffer), "s7"); Assert.Equal(amountRead, 2); Assert.Equal(stack.Read(), 'i'); Assert.Equal(stack.Read(), 'n'); Assert.Equal(stack.Read(), 'n'); Assert.Equal(stack.Read(), 'e'); amountRead = stack.Read(buffer, 0, buffer.Length); Assert.Equal(Encoding.UTF8.GetString(buffer), "rs"); Assert.Equal(amountRead, 2); }
public void MixReadAndReadBufferWithMultipleStreams() { var stack = new BinaryStreamStack(Encoding.UTF8); stack.Push(TestUtil.StringToByteNoBom("7inners")); stack.Push(TestUtil.StringToByteNoBom("6chars")); var buffer = new byte[2]; Assert.Equal('6', stack.Read()); int amountRead = stack.Read(buffer, 0, buffer.Length); Assert.Equal("ch", Encoding.UTF8.GetString(buffer)); Assert.Equal(2, amountRead); Assert.Equal('a', stack.Read()); Assert.Equal('r', stack.Read()); amountRead = stack.Read(buffer, 0, buffer.Length); Assert.Equal("s7", Encoding.UTF8.GetString(buffer)); Assert.Equal(2, amountRead); Assert.Equal('i', stack.Read()); Assert.Equal('n', stack.Read()); Assert.Equal('n', stack.Read()); Assert.Equal('e', stack.Read()); amountRead = stack.Read(buffer, 0, buffer.Length); Assert.Equal("rs", Encoding.UTF8.GetString(buffer)); Assert.Equal(2, amountRead); }
public void CanReadMultipleUnicodeCharacters() { var stack = new BinaryStreamStack(Encoding.UTF8); stack.Push(TestUtil.StringToByteNoBom("تست")); Assert.Equal('ت', stack.Read()); Assert.Equal('س', stack.Read()); Assert.Equal('ت', stack.Read()); }
public void CanReadSingleCharacterBuffer() { var stack = new BinaryStreamStack(Encoding.UTF8); stack.Push(TestUtil.StringToByteNoBom("abc")); Assert.Equal('a', stack.Read()); Assert.Equal('b', stack.Read()); Assert.Equal('c', stack.Read()); }
public void CanReadMultipleUnicodeCharactersOverBuffers() { var stack = new BinaryStreamStack(Encoding.UTF8); stack.Push(TestUtil.StringToByteNoBom("ست")); stack.Push(TestUtil.StringToByteNoBom("ت")); Assert.AreEqual(stack.Read(), 'ت'); Assert.AreEqual(stack.Read(), 'س'); Assert.AreEqual(stack.Read(), 'ت'); }
public void ReadCorrectlyHandlesSmallerBufferThenStream() { var stack = new BinaryStreamStack(Encoding.UTF8); stack.Push(TestUtil.StringToByteNoBom("6chars")); var buffer = new byte[4]; stack.Read(buffer, 0, buffer.Length); Assert.Equal("6cha", Encoding.UTF8.GetString(buffer)); buffer = new byte[2]; stack.Read(buffer, 0, buffer.Length); Assert.Equal("rs", Encoding.UTF8.GetString(buffer)); }
public void MixReadAndReadLineWithInterrupt() { var stack = new BinaryStreamStack(Encoding.UTF8); stack.Push(TestUtil.StringToByteNoBom("6chars" + Environment.NewLine + "Resume" + Environment.NewLine)); Assert.Equal('6', stack.Read()); Assert.Equal("chars", stack.ReadLine()); stack.Push(TestUtil.StringToByteNoBom("Interrupt" + Environment.NewLine)); Assert.Equal("Interrupt", stack.ReadLine()); Assert.Equal('R', stack.Read()); Assert.Equal("esume", stack.ReadLine()); }
public void CanReadSingleUnicodeCharacter() { var stack = new BinaryStreamStack(Encoding.UTF8); stack.Push(TestUtil.StringToByteNoBom("é")); Assert.Equal('é', stack.Read()); }
public void ReadReturnsZeroOnNoData() { var stack = new BinaryStreamStack(Encoding.UTF8); var buffer = new byte[6]; int amountRead = stack.Read(buffer, 0, buffer.Length); Assert.Equal("\0\0\0\0\0\0", Encoding.UTF8.GetString(buffer)); Assert.Equal(0, amountRead); }
public void ReadCorrectlyHandlesLargerBufferThenStream() { var stack = new BinaryStreamStack(Encoding.UTF8); stack.Push(TestUtil.StringToByteNoBom("6chars")); var buffer = new byte[10]; int amountRead = stack.Read(buffer, 0, buffer.Length); Assert.Equal("6chars\0\0\0\0", Encoding.UTF8.GetString(buffer)); Assert.Equal(6, amountRead); }
public void CanReadAcrossMultipleBuffers() { var stack = new BinaryStreamStack(Encoding.UTF8); stack.Push(TestUtil.StringToByteNoBom("ars")); stack.Push(TestUtil.StringToByteNoBom("6ch")); var buffer = new byte[6]; stack.Read(buffer, 0, buffer.Length); Assert.Equal("6chars", Encoding.UTF8.GetString(buffer)); }
public void CanReadSingleBuffer() { var stack = new BinaryStreamStack(Encoding.UTF8); stack.Push(TestUtil.StringToByteNoBom("6chars")); var buffer = new byte[Encoding.UTF8.GetByteCount("6chars")]; stack.Read(buffer, 0, buffer.Length); string result = Encoding.UTF8.GetString(buffer); Assert.Equal("6chars", result); }
public void ReadCanResumeInterruptedStream() { var stack = new BinaryStreamStack(Encoding.UTF8); stack.Push(TestUtil.StringToByteNoBom("6chars")); var buffer = new byte[4]; int amountRead = stack.Read(buffer, 0, buffer.Length); Assert.Equal("6cha", Encoding.UTF8.GetString(buffer)); Assert.Equal(4, amountRead); stack.Push(TestUtil.StringToByteNoBom("14intermission")); buffer = new byte[14]; amountRead = stack.Read(buffer, 0, buffer.Length); Assert.Equal("14intermission", Encoding.UTF8.GetString(buffer)); Assert.Equal(14, amountRead); buffer = new byte[2]; amountRead = stack.Read(buffer, 0, buffer.Length); Assert.Equal("rs", Encoding.UTF8.GetString(buffer)); Assert.Equal(2, amountRead); }
public void CanReadMixedUnicodeAndAsciiCharacters() { var stack = new BinaryStreamStack(Encoding.UTF8); stack.Push(TestUtil.StringToByteNoBom("تست.jpg")); Assert.Equal('ت', stack.Read()); Assert.Equal('س', stack.Read()); Assert.Equal('ت', stack.Read()); Assert.Equal('.', stack.Read()); Assert.Equal('j', stack.Read()); Assert.Equal('p', stack.Read()); Assert.Equal('g', stack.Read()); }
public void CanReadMixedUnicodeAndAsciiCharacters() { var stack = new BinaryStreamStack(Encoding.UTF8); stack.Push(TestUtil.StringToByteNoBom("تست.jpg")); Assert.AreEqual(stack.Read(), 'ت'); Assert.AreEqual(stack.Read(), 'س'); Assert.AreEqual(stack.Read(), 'ت'); Assert.AreEqual(stack.Read(), '.'); Assert.AreEqual(stack.Read(), 'j'); Assert.AreEqual(stack.Read(), 'p'); Assert.AreEqual(stack.Read(), 'g'); }
public void CanReadSingleCharacterOverBuffers() { var stack = new BinaryStreamStack(Encoding.UTF8); stack.Push(TestUtil.StringToByteNoBom("def")); stack.Push(TestUtil.StringToByteNoBom("abc")); Assert.Equal(stack.Read(), 'a'); Assert.Equal(stack.Read(), 'b'); Assert.Equal(stack.Read(), 'c'); Assert.Equal(stack.Read(), 'd'); Assert.Equal(stack.Read(), 'e'); Assert.Equal(stack.Read(), 'f'); }