-
-
Notifications
You must be signed in to change notification settings - Fork 915
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: stringify unit test and benchmark
- Loading branch information
Showing
4 changed files
with
121 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import assert from 'assert'; | ||
import stringify from '../../src/stringify.js'; | ||
|
||
const BYTES = [ | ||
0x0f, | ||
0x5a, | ||
0xbc, | ||
0xd1, | ||
0xc1, | ||
0x94, | ||
0x47, | ||
0xf3, | ||
0x90, | ||
0x5b, | ||
0x2d, | ||
0xf7, | ||
0x26, | ||
0x3a, | ||
0x08, | ||
0x4b, | ||
]; | ||
|
||
describe('stringify', () => { | ||
test('Stringify Array', () => { | ||
assert.deepStrictEqual(stringify(BYTES), '0f5abcd1-c194-47f3-905b-2df7263a084b'); | ||
}); | ||
|
||
test('Stringify TypedArray', () => { | ||
assert.deepStrictEqual( | ||
stringify(Uint8Array.from(BYTES)), | ||
'0f5abcd1-c194-47f3-905b-2df7263a084b', | ||
); | ||
assert.deepStrictEqual( | ||
stringify(Int32Array.from(BYTES)), | ||
'0f5abcd1-c194-47f3-905b-2df7263a084b', | ||
); | ||
}); | ||
|
||
test('Stringify w/ offset', () => { | ||
assert.deepStrictEqual( | ||
stringify([0, 0, 0, ...BYTES], 3), | ||
'0f5abcd1-c194-47f3-905b-2df7263a084b', | ||
); | ||
}); | ||
|
||
test('Throws on not enough values', () => { | ||
const bytes = [...BYTES]; | ||
bytes.length = 15; | ||
assert.throws(() => stringify(bytes)); | ||
}); | ||
|
||
test('Throws on undefined value', () => { | ||
const bytes = [...BYTES]; | ||
delete bytes[3]; | ||
bytes.length = 15; | ||
assert.throws(() => stringify(bytes)); | ||
}); | ||
|
||
test('Throws on invalid value', () => { | ||
const bytes = [...BYTES]; | ||
bytes[3] = 256; | ||
assert.throws(() => stringify(bytes)); | ||
}); | ||
}); |