예제 #1
0
        public void PeekReturnsByteWithoutMoving()
        {
            var reader = new ReadOnlyBufferReader(Factory.CreateWithContent(new byte[] { 1, 2 }));

            Assert.Equal(1, reader.Peek());
            Assert.Equal(1, reader.Peek());
        }
예제 #2
0
        public void EmptySegmentsAreSkippedOnMoveNext()
        {
            var buffer = Factory.CreateWithContent(new byte[] { 1, 2 });
            var reader = new ReadOnlyBufferReader(buffer);

            Assert.Equal(1, reader.Peek());
            reader.Skip(1);
            Assert.Equal(2, reader.Peek());
        }
예제 #3
0
        public void PeekWorkesWithEmptySegments()
        {
            var buffer = Factory.CreateWithContent(new byte[] { 1 });
            var reader = new ReadOnlyBufferReader(buffer);

            Assert.Equal(0, reader.Index);
            Assert.Equal(1, reader.Span.Length);
            Assert.Equal(1, reader.Peek());
            Assert.Equal(1, reader.Take());
            Assert.Equal(-1, reader.Peek());
            Assert.Equal(-1, reader.Take());
        }
예제 #4
0
            public void SkipSingleBufferSkipsBytes()
            {
                var reader = new ReadOnlyBufferReader(BufferUtilities.CreateBuffer(new byte[] { 1, 2, 3, 4, 5 }));

                reader.Skip(2);
                Assert.Equal(2, reader.Index);
                Assert.Equal(3, reader.Span[reader.Index]);
                Assert.Equal(3, reader.Peek());
                reader.Skip(2);
                Assert.Equal(5, reader.Peek());
                Assert.Equal(4, reader.Index);
                Assert.Equal(5, reader.Span[reader.Index]);
            }
예제 #5
0
        public void PeekTraversesSegments()
        {
            var buffer = Factory.CreateWithContent(new byte[] { 1, 2 });
            var reader = new ReadOnlyBufferReader(buffer);

            Assert.Equal(1, reader.Span[reader.Index]);
            Assert.Equal(1, reader.Take());

            Assert.Equal(2, reader.Span[reader.Index]);
            Assert.Equal(2, reader.Peek());
            Assert.Equal(2, reader.Take());
            Assert.Equal(-1, reader.Peek());
            Assert.Equal(-1, reader.Take());
        }
예제 #6
0
        public void CtorFindsFirstNonEmptySegment()
        {
            var buffer = Factory.CreateWithContent(new byte[] { 1 });
            var reader = new ReadOnlyBufferReader(buffer);

            Assert.Equal(1, reader.Peek());
        }
예제 #7
0
        public void PeekGoesToEndIfAllEmptySegments()
        {
            var buffer = BufferUtilities.CreateBuffer(new[] { new byte[] { }, new byte[] { }, new byte[] { }, new byte[] { } });
            var reader = new ReadOnlyBufferReader(buffer);

            Assert.Equal(-1, reader.Peek());
            Assert.True(reader.End);
        }
예제 #8
0
        public void SkipToEndThenPeekReturnsMinusOne()
        {
            var reader = new ReadOnlyBufferReader(Factory.CreateWithContent(new byte[] { 1, 2, 3, 4, 5 }));

            reader.Skip(5);
            Assert.True(reader.End);
            Assert.Equal(-1, reader.Peek());
        }
예제 #9
0
        public void PeekReturnsMinuOneByteInTheEnd()
        {
            var reader = new ReadOnlyBufferReader(Factory.CreateWithContent(new byte[] { 1, 2 }));

            Assert.Equal(1, reader.Take());
            Assert.Equal(2, reader.Take());
            Assert.Equal(-1, reader.Peek());
        }
예제 #10
0
        public void WorkesWithEmptyBuffer()
        {
            var reader = new ReadOnlyBufferReader(Factory.CreateWithContent(new byte[] { }));

            Assert.Equal(0, reader.Index);
            Assert.Equal(0, reader.Span.Length);
            Assert.Equal(-1, reader.Peek());
            Assert.Equal(-1, reader.Take());
        }
예제 #11
0
        public void SlicingBufferReturnsCorrectCursor()
        {
            var buffer = Factory.CreateWithContent(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 });
            var sliced = buffer.Slice(2);

            var reader = new ReadOnlyBufferReader(sliced);

            Assert.Equal(sliced.ToArray(), buffer.Slice(reader.Cursor).ToArray());
            Assert.Equal(2, reader.Peek());
            Assert.Equal(0, reader.Index);
        }