|
1 | 1 | import assert from 'assert';
|
2 |
| -import stringify from '../../src/stringify.js'; |
| 2 | +import stringify, { unsafeStringify } from '../../src/stringify.js'; |
3 | 3 |
|
4 | 4 | const BYTES = [
|
5 | 5 | 0x0f, 0x5a, 0xbc, 0xd1, 0xc1, 0x94, 0x47, 0xf3, 0x90, 0x5b, 0x2d, 0xf7, 0x26, 0x3a, 0x08, 0x4b,
|
6 | 6 | ];
|
7 | 7 |
|
8 |
| -describe('stringify', () => { |
9 |
| - test('Stringify Array', () => { |
10 |
| - assert.equal(stringify(BYTES), '0f5abcd1-c194-47f3-905b-2df7263a084b'); |
11 |
| - }); |
| 8 | +describe('unsafeStringify', () => { |
| 9 | + describe('default', () => { |
| 10 | + test('Stringify Array', () => { |
| 11 | + assert.equal(unsafeStringify(BYTES), '0f5abcd1-c194-47f3-905b-2df7263a084b'); |
| 12 | + }); |
12 | 13 |
|
13 |
| - test('Stringify TypedArray', () => { |
14 |
| - assert.equal(stringify(Uint8Array.from(BYTES)), '0f5abcd1-c194-47f3-905b-2df7263a084b'); |
15 |
| - assert.equal(stringify(Int32Array.from(BYTES)), '0f5abcd1-c194-47f3-905b-2df7263a084b'); |
16 |
| - }); |
| 14 | + test('Stringify TypedArray', () => { |
| 15 | + assert.equal(unsafeStringify(Uint8Array.from(BYTES)), '0f5abcd1-c194-47f3-905b-2df7263a084b'); |
| 16 | + assert.equal(unsafeStringify(Int32Array.from(BYTES)), '0f5abcd1-c194-47f3-905b-2df7263a084b'); |
| 17 | + }); |
17 | 18 |
|
18 |
| - test('Stringify w/ offset', () => { |
19 |
| - assert.equal(stringify([0, 0, 0, ...BYTES], 3), '0f5abcd1-c194-47f3-905b-2df7263a084b'); |
| 19 | + test('Stringify w/ offset', () => { |
| 20 | + assert.equal(unsafeStringify([0, 0, 0, ...BYTES], 3), '0f5abcd1-c194-47f3-905b-2df7263a084b'); |
| 21 | + }); |
20 | 22 | });
|
21 | 23 |
|
22 |
| - test('Throws on not enough values', () => { |
23 |
| - const bytes = [...BYTES]; |
24 |
| - bytes.length = 15; |
25 |
| - assert.throws(() => stringify(bytes)); |
26 |
| - }); |
| 24 | + describe('safe', () => { |
| 25 | + test('Stringify Array', () => { |
| 26 | + assert.equal(stringify(BYTES), '0f5abcd1-c194-47f3-905b-2df7263a084b'); |
| 27 | + }); |
27 | 28 |
|
28 |
| - test('Throws on undefined value', () => { |
29 |
| - const bytes = [...BYTES]; |
30 |
| - delete bytes[3]; |
31 |
| - bytes.length = 15; |
32 |
| - assert.throws(() => stringify(bytes)); |
33 |
| - }); |
| 29 | + test('Throws on not enough values', () => { |
| 30 | + const bytes = [...BYTES]; |
| 31 | + bytes.length = 15; |
| 32 | + assert.throws(() => stringify(bytes)); |
| 33 | + }); |
| 34 | + |
| 35 | + test('Throws on undefined value', () => { |
| 36 | + const bytes = [...BYTES]; |
| 37 | + delete bytes[3]; |
| 38 | + bytes.length = 15; |
| 39 | + assert.throws(() => stringify(bytes)); |
| 40 | + }); |
34 | 41 |
|
35 |
| - test('Throws on invalid value', () => { |
36 |
| - const bytes = [...BYTES]; |
37 |
| - bytes[3] = 256; |
38 |
| - assert.throws(() => stringify(bytes)); |
| 42 | + test('Throws on invalid value', () => { |
| 43 | + const bytes = [...BYTES]; |
| 44 | + bytes[3] = 256; |
| 45 | + assert.throws(() => stringify(bytes)); |
| 46 | + }); |
39 | 47 | });
|
40 | 48 | });
|
0 commit comments