Skip to content

Commit

Permalink
Improved 7-bit length encoding compatibility in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sakno committed Dec 7, 2024
1 parent 312c65e commit 1a64ce6
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/DotNext.Tests/IO/StreamExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,28 +101,38 @@ public static async Task ReadWriteBlittableTypeAsync()
Equal(10M, (await ms.ReadAsync<Blittable<decimal>>(buffer)).Value);
}

[Fact]
public static async Task BinaryReaderInterop()
[Theory]
[InlineData(7)]
[InlineData(16)]
[InlineData(0x7F)]
[InlineData(0x80)]
public static async Task BinaryReaderInterop(int length)
{
var expected = Random.Shared.NextString(Alphabet + AlphabetUpperCase + Numbers, length);
using var ms = new MemoryStream();
await ms.EncodeAsync("ABC".AsMemory(), Encoding.UTF8, LengthFormat.Compressed, new byte[16]);
await ms.EncodeAsync(expected.AsMemory(), Encoding.UTF8, LengthFormat.Compressed, new byte[16]);
ms.Position = 0;
using var reader = new BinaryReader(ms, Encoding.UTF8, true);
Equal("ABC", reader.ReadString());
Equal(expected, reader.ReadString());
}

[Fact]
public static async Task BinaryWriterInterop()
[Theory]
[InlineData(7)]
[InlineData(16)]
[InlineData(0x7F)]
[InlineData(0x80)]
public static async Task BinaryWriterInterop(int length)
{
var expected = Random.Shared.NextString(Alphabet + AlphabetUpperCase + Numbers, length);
using var ms = new MemoryStream();
using (var writer = new BinaryWriter(ms, Encoding.UTF8, true))
await using (var writer = new BinaryWriter(ms, Encoding.UTF8, true))
{
writer.Write("ABC");
writer.Write(expected);
}
ms.Position = 0;

using var result = await ms.DecodeAsync(Encoding.UTF8, LengthFormat.Compressed, new byte[16]);
Equal("ABC", result.ToString());
Equal(expected, result.Span);
}

[Fact]
Expand Down

0 comments on commit 1a64ce6

Please sign in to comment.