1 | "use strict";
|
---|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
3 | const assert = require("assert");
|
---|
4 | const node_test_1 = require("node:test");
|
---|
5 | const parse_js_1 = require("../parse.js");
|
---|
6 | const stringify_js_1 = require("../stringify.js");
|
---|
7 | const v4_js_1 = require("../v4.js");
|
---|
8 | function splitmix32(a) {
|
---|
9 | return function () {
|
---|
10 | a |= 0;
|
---|
11 | a = (a + 0x9e3779b9) | 0;
|
---|
12 | let t = a ^ (a >>> 16);
|
---|
13 | t = Math.imul(t, 0x21f0aaad);
|
---|
14 | t = t ^ (t >>> 15);
|
---|
15 | t = Math.imul(t, 0x735a2d97);
|
---|
16 | return ((t = t ^ (t >>> 15)) >>> 0) / 4294967296;
|
---|
17 | };
|
---|
18 | }
|
---|
19 | const rand = splitmix32(0x12345678);
|
---|
20 | function rng(bytes = new Uint8Array(16)) {
|
---|
21 | for (let i = 0; i < 16; i++) {
|
---|
22 | bytes[i] = rand() * 256;
|
---|
23 | }
|
---|
24 | return bytes;
|
---|
25 | }
|
---|
26 | (0, node_test_1.describe)('parse', () => {
|
---|
27 | (0, node_test_1.default)('String -> bytes parsing', () => {
|
---|
28 | assert.deepStrictEqual((0, parse_js_1.default)('0f5abcd1-c194-47f3-905b-2df7263a084b'), Uint8Array.from([
|
---|
29 | 0x0f, 0x5a, 0xbc, 0xd1, 0xc1, 0x94, 0x47, 0xf3, 0x90, 0x5b, 0x2d, 0xf7, 0x26, 0x3a, 0x08,
|
---|
30 | 0x4b,
|
---|
31 | ]));
|
---|
32 | });
|
---|
33 | (0, node_test_1.default)('String -> bytes -> string symmetry for assorted uuids', () => {
|
---|
34 | for (let i = 0; i < 1000; i++) {
|
---|
35 | const uuid = (0, v4_js_1.default)({ rng });
|
---|
36 | assert.equal((0, stringify_js_1.default)((0, parse_js_1.default)(uuid)), uuid);
|
---|
37 | }
|
---|
38 | });
|
---|
39 | (0, node_test_1.default)('Case neutrality', () => {
|
---|
40 | assert.deepStrictEqual((0, parse_js_1.default)('0f5abcd1-c194-47f3-905b-2df7263a084b'), (0, parse_js_1.default)('0f5abcd1-c194-47f3-905b-2df7263a084b'.toUpperCase()));
|
---|
41 | });
|
---|
42 | (0, node_test_1.default)('Null UUID case', () => {
|
---|
43 | assert.deepStrictEqual((0, parse_js_1.default)('00000000-0000-0000-0000-000000000000'), Uint8Array.from(new Array(16).fill(0)));
|
---|
44 | });
|
---|
45 | (0, node_test_1.default)('UUID validation', () => {
|
---|
46 | assert.throws(() => (0, parse_js_1.default)());
|
---|
47 | assert.throws(() => (0, parse_js_1.default)('invalid uuid'));
|
---|
48 | assert.throws(() => (0, parse_js_1.default)('zyxwvuts-rqpo-nmlk-jihg-fedcba000000'));
|
---|
49 | });
|
---|
50 | });
|
---|