1 | import * as assert from 'assert';
|
---|
2 | import test, { describe } from 'node:test';
|
---|
3 | import stringify, { unsafeStringify } from '../stringify.js';
|
---|
4 | const BYTES = Uint8Array.of(0x0f, 0x5a, 0xbc, 0xd1, 0xc1, 0x94, 0x47, 0xf3, 0x90, 0x5b, 0x2d, 0xf7, 0x26, 0x3a, 0x08, 0x4b);
|
---|
5 | describe('stringify', () => {
|
---|
6 | test('Stringify Array (unsafe)', () => {
|
---|
7 | assert.equal(unsafeStringify(BYTES), '0f5abcd1-c194-47f3-905b-2df7263a084b');
|
---|
8 | });
|
---|
9 | test('Stringify w/ offset (unsafe)', () => {
|
---|
10 | const bytes = new Uint8Array(19).fill(0);
|
---|
11 | bytes.set(BYTES, 3);
|
---|
12 | assert.equal(unsafeStringify(bytes, 3), '0f5abcd1-c194-47f3-905b-2df7263a084b');
|
---|
13 | });
|
---|
14 | test('Stringify Array (safe)', () => {
|
---|
15 | assert.equal(stringify(BYTES), '0f5abcd1-c194-47f3-905b-2df7263a084b');
|
---|
16 | });
|
---|
17 | test('Throws on not enough values (safe)', () => {
|
---|
18 | const bytes = BYTES.slice(0, 15);
|
---|
19 | assert.throws(() => stringify(bytes));
|
---|
20 | });
|
---|
21 | });
|
---|