Skip to content

Commit

Permalink
add writespan test
Browse files Browse the repository at this point in the history
  • Loading branch information
itn3000 committed Nov 18, 2019
1 parent aff5ba8 commit be6f177
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions PooledStream.Test/TestPooledMemoryStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,28 @@ public void TestWriteTwice()
}
}
[Fact]
public void TestWriteSpanTwice()
{
var data = (new byte[] { 1, 2, 3, 4 }).AsSpan();
using (var stm = new PooledMemoryStream(ArrayPool<byte>.Shared))
{
Assert.True(stm.CanWrite);
Assert.True(stm.CanRead);
Assert.Equal(0, stm.Length);
Assert.Equal(0, stm.Position);
stm.Write(data);
Assert.Equal(4, stm.Length);
Assert.Equal(4, stm.Position);
var ar = stm.ToArray();
Assert.Equal(data.ToArray(), ar);
stm.Write(data);
Assert.Equal(8, stm.Length);
Assert.Equal(8, stm.Position);
ar = stm.ToArray();
Assert.Equal(data.ToArray().Concat(data.ToArray()), ar);
}
}
[Fact]
public void TestWriteMiddle()
{
var data = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8};
Expand All @@ -44,6 +66,19 @@ public void TestWriteMiddle()
}
}
[Fact]
public void TestWriteSpanMiddle()
{
var data = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8};
using (var stm = new PooledMemoryStream(ArrayPool<byte>.Shared))
{
stm.Write(data.AsSpan());
stm.Seek(4, SeekOrigin.Begin);
stm.Write(data.AsSpan());
var ar = stm.ToArray();
Assert.Equal(data.Take(4).Concat(data), ar);
}
}
[Fact]
public void TestReadOnly()
{
var data = new byte[] { 1, 2, 3, 4 };
Expand Down

0 comments on commit be6f177

Please sign in to comment.