import { assertEquals, assertThrows } from "@std/assert"; import { describe, it } from "@std/testing/bdd"; import { bufferToBase } from "./bases.ts"; describe("bufferToBase", () => { it("returns an empty string for an empty Uint8Array", () => { assertEquals(bufferToBase(new Uint8Array([]), 16), ""); }); it("converts bytes to hexadecimal (base 16)", () => { const input = new Uint8Array([0, 1, 15, 16, 255]); const expected = "00010f10ff"; assertEquals(bufferToBase(input, 16), expected); }); it("converts bytes to binary (base 2)", () => { const input = new Uint8Array([255, 0, 1]); const expected = "111111110000000000000001"; assertEquals(bufferToBase(input, 2), expected); }); it("converts bytes to octal (base 8)", () => { const input = new Uint8Array([8, 64, 255]); const expected = "010100377"; assertEquals(bufferToBase(input, 8), expected); }); it("throws on invalid base", () => { assertThrows(() => bufferToBase(new Uint8Array([1, 2]), 1), RangeError); assertThrows(() => bufferToBase(new Uint8Array([1, 2]), 37), RangeError); }); });