public void PeekReturnsByteWithoutMoving() { var reader = new ReadOnlyBufferReader(Factory.CreateWithContent(new byte[] { 1, 2 })); Assert.Equal(1, reader.Peek()); Assert.Equal(1, reader.Peek()); }
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()); }
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()); }
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]); }
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()); }
public void CtorFindsFirstNonEmptySegment() { var buffer = Factory.CreateWithContent(new byte[] { 1 }); var reader = new ReadOnlyBufferReader(buffer); Assert.Equal(1, reader.Peek()); }
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); }
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()); }
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()); }
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()); }
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); }