Skip to content

Commit

Permalink
extra VLC encoding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mikera committed Sep 21, 2024
1 parent 8e37166 commit d7f82d3
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions convex-core/src/test/java/convex/core/data/FormatTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,19 @@ public class FormatTest {
assertBadVLCEncoding("80ffffffffffffffffff7f"); // too long
assertBadVLCEncoding("ff80808080808080808000"); // long negative

// TODO: fix this
// assertBadVLCEncoding("8000"); // excess leading bytes
assertBadVLCEncoding("8000"); // excess leading bytes
assertBadVLCEncoding("8080"); // no termination

assertEquals(Format.MAX_VLC_LONG_LENGTH,Format.getVLCLength(Long.MAX_VALUE));
assertEquals(Format.MAX_VLC_LONG_LENGTH,Format.getVLCLength(Long.MIN_VALUE));
}

private void assertBadVLCEncoding(String hex) {
Blob b=Blob.fromHex(hex);
assertThrows(BadFormatException.class,()->Format.readVLCLong(b.getInternalArray(), b.getInternalOffset()));
assertThrows(BadFormatException.class,()->{
long val=Format.readVLCLong(b.getInternalArray(), b.getInternalOffset());
if (Format.getVLCLength(val)!=b.count()) throw new BadFormatException("Wrong length");
});
}

private void checkVLCEncoding(String hex, long a) {
Expand Down

0 comments on commit d7f82d3

Please sign in to comment.