Skip to content

Commit

Permalink
Check difference between LEB128 and ULEB128
Browse files Browse the repository at this point in the history
  • Loading branch information
sakno committed Dec 7, 2024
1 parent 7a488a1 commit 6df2774
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/DotNext.Tests/Buffers/Binary/Leb128Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,17 @@ public static void CompatibilityWithBinaryWriter(int expected)
True(Leb128<uint>.TryParse(stream.GetBuffer(), out var actual, out _));
Equal((uint)expected, actual);
}

[Fact]
public static void DifferenceBetweenSignedAndUnsignedEncoding()
{
Equal(Leb128<int>.MaxSizeInBytes, Leb128<uint>.MaxSizeInBytes);

Span<byte> buffer = stackalloc byte[Leb128<int>.MaxSizeInBytes];
True(Leb128<uint>.TryGetBytes(0x7Fu, buffer, out var bytesWritten));
Equal(1, bytesWritten);

True(Leb128<int>.TryGetBytes(0x7F, buffer, out bytesWritten));
Equal(2, bytesWritten);
}
}

0 comments on commit 6df2774

Please sign in to comment.