source: imaps-frontend/node_modules/uuid/dist/cjs-browser/test/parse.test.js

main
Last change on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 2.1 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const assert = require("assert");
4const node_test_1 = require("node:test");
5const parse_js_1 = require("../parse.js");
6const stringify_js_1 = require("../stringify.js");
7const v4_js_1 = require("../v4.js");
8function 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}
19const rand = splitmix32(0x12345678);
20function 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});
Note: See TracBrowser for help on using the repository browser.