diff options
author | Oliver Lenehan <sunsetkookaburra+git@outlook.com.au> | 2020-06-09 08:58:55 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-08 18:58:55 -0400 |
commit | 6f22bc827893d6b2500014ac40b51ebbb283677c (patch) | |
tree | 37e6d225db333db86b4a913c996a3966e0b9d4f8 /std/encoding/binary_test.ts | |
parent | 5e01e14f08d807a3ae80f5788c5a4beea8d8fd2a (diff) |
feat(std/encoding/binary): add varnumBytes(), varbigBytes() (#5173)
Diffstat (limited to 'std/encoding/binary_test.ts')
-rw-r--r-- | std/encoding/binary_test.ts | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/std/encoding/binary_test.ts b/std/encoding/binary_test.ts index ebd0b0b41..6213bc2e3 100644 --- a/std/encoding/binary_test.ts +++ b/std/encoding/binary_test.ts @@ -12,6 +12,8 @@ import { varnum, writeVarbig, writeVarnum, + varbigBytes, + varnumBytes, } from "./binary.ts"; Deno.test("testGetNBytes", async function (): Promise<void> { @@ -160,3 +162,29 @@ Deno.test("testWriteVarnumLittleEndian", async function (): Promise<void> { await buff.read(data); assertEquals(data, new Uint8Array([0x01, 0x02, 0x03, 0x04])); }); + +Deno.test("testVarbigBytes", function (): void { + const rslt = varbigBytes(0x0102030405060708n); + assertEquals( + rslt, + new Uint8Array([0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08]) + ); +}); + +Deno.test("testVarbigBytesLittleEndian", function (): void { + const rslt = varbigBytes(0x0807060504030201n, { endian: "little" }); + assertEquals( + rslt, + new Uint8Array([0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08]) + ); +}); + +Deno.test("testVarnumBytes", function (): void { + const rslt = varnumBytes(0x01020304); + assertEquals(rslt, new Uint8Array([0x01, 0x02, 0x03, 0x04])); +}); + +Deno.test("testVarnumBytesLittleEndian", function (): void { + const rslt = varnumBytes(0x04030201, { endian: "little" }); + assertEquals(rslt, new Uint8Array([0x01, 0x02, 0x03, 0x04])); +}); |