From 6f22bc827893d6b2500014ac40b51ebbb283677c Mon Sep 17 00:00:00 2001 From: Oliver Lenehan Date: Tue, 9 Jun 2020 08:58:55 +1000 Subject: feat(std/encoding/binary): add varnumBytes(), varbigBytes() (#5173) --- std/encoding/binary_test.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'std/encoding/binary_test.ts') 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 { @@ -160,3 +162,29 @@ Deno.test("testWriteVarnumLittleEndian", async function (): Promise { 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])); +}); -- cgit v1.2.3