public void PeekReturnsByteWithoutMoving() { var reader = new ReadableBufferReader(Factory.CreateWithContent(new byte[] { 1, 2 })); Assert.Equal(1, reader.Peek()); Assert.Equal(1, reader.Peek()); }
public void PeekReturnsByteWithoutMoving() { var reader = new ReadableBufferReader(ReadableBuffer.Create(new byte[] { 1, 2 }, 0, 2)); Assert.Equal(1, reader.Peek()); Assert.Equal(1, reader.Peek()); }
public void EmptySegmentsAreSkippedOnMoveNext() { var buffer = BufferUtilities.CreateBuffer(new[] { new byte[] { 1 }, new byte[] { }, new byte[] { }, new byte[] { 2 } }); var reader = new ReadableBufferReader(buffer); Assert.Equal(1, reader.Peek()); reader.Skip(1); Assert.Equal(2, reader.Peek()); }
public void SkipSingleBufferSkipsBytes() { var reader = new ReadableBufferReader(ReadableBuffer.Create(new byte[] { 1, 2, 3, 4, 5 }, 0, 5)); reader.Skip(2); Assert.Equal(3, reader.Peek()); reader.Skip(2); Assert.Equal(5, reader.Peek()); }
public void EmptySegmentsAreSkippedOnMoveNext() { var buffer = Factory.CreateWithContent(new byte[] { 1, 2 }); var reader = new ReadableBufferReader(buffer); Assert.Equal(1, reader.Peek()); reader.Skip(1); Assert.Equal(2, reader.Peek()); }
public void PeekWorkesWithEmptySegments() { var buffer = BufferUtilities.CreateBuffer(new[] { new byte[] { }, new byte[] { 1 } }); var reader = new ReadableBufferReader(buffer); Assert.Equal(1, reader.Peek()); Assert.Equal(1, reader.Take()); Assert.Equal(-1, reader.Peek()); Assert.Equal(-1, reader.Take()); }
public void PeekTraversesSegments() { var buffer = BufferUtilities.CreateBuffer(new[] { new byte[] { 1 }, new byte[] { 2 } }); var reader = new ReadableBufferReader(buffer); Assert.Equal(1, reader.Take()); Assert.Equal(2, reader.Peek()); Assert.Equal(2, reader.Take()); Assert.Equal(-1, reader.Peek()); Assert.Equal(-1, reader.Take()); }
public void PeekWorkesWithEmptySegments() { var buffer = Factory.CreateWithContent(new byte[] { 1 }); var reader = new ReadableBufferReader(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 ReadableBufferReader(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 ReadableBufferReader(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 WorkesWithEmptyBuffer() { var reader = new ReadableBufferReader(ReadableBuffer.Create(new byte[] { 0 }, 0, 0)); Assert.Equal(-1, reader.Peek()); Assert.Equal(-1, reader.Take()); }
public void PeekReturnsMinuOneByteInTheEnd() { var reader = new ReadableBufferReader(ReadableBuffer.Create(new byte[] { 1, 2 }, 0, 2)); Assert.Equal(1, reader.Take()); Assert.Equal(2, reader.Take()); Assert.Equal(-1, reader.Peek()); }
public void CtorFindsFirstNonEmptySegment() { var buffer = BufferUtilities.CreateBuffer(new[] { new byte[] { }, new byte[] { 1 } }); var reader = new ReadableBufferReader(buffer); Assert.Equal(1, reader.Peek()); }
public void CtorFindsFirstNonEmptySegment() { var buffer = Factory.CreateWithContent(new byte[] { 1 }); var reader = new ReadableBufferReader(buffer); Assert.Equal(1, reader.Peek()); }
public void SkipToEndThenPeekReturnsMinusOne() { var reader = new ReadableBufferReader(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 ReadableBufferReader(Factory.CreateWithContent(new byte[] { 1, 2 })); Assert.Equal(1, reader.Take()); Assert.Equal(2, reader.Take()); Assert.Equal(-1, reader.Peek()); }
public void PeekGoesToEndIfAllEmptySegments() { var buffer = BufferUtilities.CreateBuffer(new[] { new byte[] { }, new byte[] { }, new byte[] { }, new byte[] { } }); var reader = new ReadableBufferReader(buffer); Assert.Equal(-1, reader.Peek()); Assert.True(reader.End); }
public void SkipToEndThenPeekReturnsMinusOne() { var reader = new ReadableBufferReader(ReadableBuffer.Create(new byte[] { 1, 2, 3, 4, 5 }, 0, 5)); reader.Skip(5); Assert.True(reader.End); Assert.Equal(-1, reader.Peek()); Assert.True(reader.Cursor.IsEnd); }
public void WorkesWithEmptyBuffer() { var reader = new ReadableBufferReader(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 = ReadableBuffer.Create(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 0, 10); var sliced = buffer.Slice(2); var reader = new ReadableBufferReader(sliced); Assert.Equal(sliced.Start, reader.Cursor); Assert.Equal(2, reader.Peek()); }
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 ReadableBufferReader(sliced); Assert.Equal(sliced.ToArray(), buffer.Slice(reader.Cursor).ToArray()); Assert.Equal(2, reader.Peek()); Assert.Equal(0, reader.Index); }
public async Task PeekTraversesSegments() { using (var factory = new PipelineFactory()) { var readerWriter = factory.Create(); var w = readerWriter.Alloc(); w.Append(ReadableBuffer.Create(new byte[] { 1 }, 0, 1)); w.Append(ReadableBuffer.Create(new byte[] { 2 }, 0, 1)); await w.FlushAsync(); var result = await readerWriter.ReadAsync(); var buffer = result.Buffer; var reader = new ReadableBufferReader(buffer); Assert.Equal(1, reader.Take()); Assert.Equal(2, reader.Peek()); Assert.Equal(2, reader.Take()); Assert.Equal(-1, reader.Peek()); Assert.Equal(-1, reader.Take()); } }
public async Task PeekWorkesWithEmptySegments() { using (var channelFactory = new ChannelFactory()) { var channel = channelFactory.CreateChannel(); var w = channel.Alloc(); w.Append(ReadableBuffer.Create(new byte[] { 0 }, 0, 0)); w.Append(ReadableBuffer.Create(new byte[] { 1 }, 0, 1)); await w.FlushAsync(); var result = await channel.ReadAsync(); var buffer = result.Buffer; var reader = new ReadableBufferReader(buffer); Assert.Equal(1, reader.Peek()); Assert.Equal(1, reader.Take()); Assert.Equal(-1, reader.Peek()); Assert.Equal(-1, reader.Take()); } }
public async Task PeekTraversesSegments() { using (var factory = new PipeFactory()) { var readerWriter = factory.Create(); var w = readerWriter.Writer.Alloc(); w.Append(ReadableBuffer.Create(new byte[] { 1 }, 0, 1)); w.Append(ReadableBuffer.Create(new byte[] { 2 }, 0, 1)); await w.FlushAsync(); var result = await readerWriter.Reader.ReadAsync(); var buffer = result.Buffer; var reader = new ReadableBufferReader(buffer); Assert.Equal(1, reader.Take()); Assert.Equal(2, reader.Peek()); Assert.Equal(2, reader.Take()); Assert.Equal(-1, reader.Peek()); Assert.Equal(-1, reader.Take()); } }