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 CanReadLineMultiplesLineInSingleBuffer()
        {
            var stack = new BinaryStreamStack(Encoding.UTF8);

            stack.Push(TestUtil.StringToByteNoBom("al" + Environment.NewLine));
            stack.Push(TestUtil.StringToByteNoBom("6chars" + Environment.NewLine + "5char" + Environment.NewLine + "Parti"));

            Assert.Equal("6chars", stack.ReadLine());
            Assert.Equal("5char", stack.ReadLine());
            Assert.Equal("Partial", stack.ReadLine());
        }
        public void CanReadMultipleUnicodeCharactersOverBuffers()
        {
            var stack = new BinaryStreamStack(Encoding.UTF8);

            stack.Push(TestUtil.StringToByteNoBom("ست"));
            stack.Push(TestUtil.StringToByteNoBom("ت"));

            Assert.Equal('ت', stack.Read());
            Assert.Equal('س', stack.Read());
            Assert.Equal('ت', stack.Read());
        }
        public void ReadLineCanReadAcrossInterruption()
        {
            var stack = new BinaryStreamStack(Encoding.UTF8);

            stack.Push(TestUtil.StringToByteNoBom("6chars" + Environment.NewLine + "Resume" + Environment.NewLine));

            Assert.Equal("6chars", stack.ReadLine());

            stack.Push(TestUtil.StringToByteNoBom("Interrupt "));

            Assert.Equal("Interrupt Resume", stack.ReadLine());
        }
        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));
        }
예제 #7
0
        public void ReadLineCanResumeInterruptedStream()
        {
            var stack = new BinaryStreamStack(Encoding.UTF8);

            stack.Push(TestUtil.StringToByteNoBom("6chars" + Environment.NewLine + "Resume" + Environment.NewLine));

            Assert.AreEqual(stack.ReadLine(), "6chars");

            stack.Push(TestUtil.StringToByteNoBom("Interrupt" + Environment.NewLine));

            Assert.AreEqual(stack.ReadLine(), "Interrupt");
            Assert.AreEqual(stack.ReadLine(), "Resume");
        }
예제 #8
0
        public void CanReadSingleCharacterOverBuffers()
        {
            var stack = new BinaryStreamStack(Encoding.UTF8);

            stack.Push(TestUtil.StringToByteNoBom("def"));
            stack.Push(TestUtil.StringToByteNoBom("abc"));

            Assert.AreEqual(stack.Read(), 'a');
            Assert.AreEqual(stack.Read(), 'b');
            Assert.AreEqual(stack.Read(), 'c');
            Assert.AreEqual(stack.Read(), 'd');
            Assert.AreEqual(stack.Read(), 'e');
            Assert.AreEqual(stack.Read(), 'f');
        }
        public void CanReadSingleCharacterOverBuffers()
        {
            var stack = new BinaryStreamStack(Encoding.UTF8);

            stack.Push(TestUtil.StringToByteNoBom("def"));
            stack.Push(TestUtil.StringToByteNoBom("abc"));

            Assert.Equal('a', stack.Read());
            Assert.Equal('b', stack.Read());
            Assert.Equal('c', stack.Read());
            Assert.Equal('d', stack.Read());
            Assert.Equal('e', stack.Read());
            Assert.Equal('f', stack.Read());
        }
        public void CanReadLineAcrossMultipleBuffers()
        {
            var stack = new BinaryStreamStack(Encoding.UTF8);

            stack.Push(TestUtil.StringToByteNoBom("13anotherline" + Environment.NewLine));
            stack.Push(TestUtil.StringToByteNoBom("ars" + Environment.NewLine));
            stack.Push(TestUtil.StringToByteNoBom("6ch"));

            string line = stack.ReadLine();

            Assert.Equal("6chars", line);

            line = stack.ReadLine();
            Assert.Equal("13anotherline", line);
        }
        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 CanReadLineNearEnd()
        {
            var stack = new BinaryStreamStack(Encoding.UTF8);

            stack.Push(TestUtil.StringToByteNoBom("\r\n--endboundary--"));

            Assert.Equal(stack.ReadLine(), string.Empty);
            Assert.Equal("--endboundary--", stack.ReadLine());
        }
예제 #14
0
        public void CanReadMultipleUnicodeCharacters()
        {
            var stack = new BinaryStreamStack(Encoding.UTF8);

            stack.Push(TestUtil.StringToByteNoBom("تست"));

            Assert.AreEqual(stack.Read(), 'ت');
            Assert.AreEqual(stack.Read(), 'س');
            Assert.AreEqual(stack.Read(), 'ت');
        }
        public void ReturnsRemainderOnNoNewline()
        {
            var stack = new BinaryStreamStack(Encoding.UTF8);

            stack.Push(TestUtil.StringToByteNoBom("noline"));

            string noline = stack.ReadLine();

            Assert.Equal("noline", noline);
        }
        public void CanReadLineSingleBuffer()
        {
            var stack = new BinaryStreamStack(Encoding.UTF8);

            stack.Push(TestUtil.StringToByteNoBom("6chars" + Environment.NewLine));

            string result = stack.ReadLine();

            Assert.Equal("6chars", result);
        }
        public void CanReadLineSingleBuffer()
        {
            var stack = new BinaryStreamStack(Encoding.UTF8);

            stack.Push(TestUtil.StringToByteNoBom("6chars" + Environment.NewLine));

            var    buffer = new byte[Encoding.UTF8.GetByteCount("6chars" + Environment.NewLine)];
            string result = stack.ReadLine();

            Assert.Equal(result, "6chars");
        }
        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 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());
        }
예제 #22
0
        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 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));
        }