source: imaps-frontend/node_modules/uuid/dist/cjs-browser/test/v6.test.js@ 79a0317

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

F4 Finalna Verzija

  • Property mode set to 100644
File size: 2.4 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const assert = require("assert");
4const node_test_1 = require("node:test");
5const v1ToV6_js_1 = require("../v1ToV6.js");
6const v6_js_1 = require("../v6.js");
7const v6ToV1_js_1 = require("../v6ToV1.js");
8(0, node_test_1.describe)('v6', () => {
9 const V1_ID = 'f1207660-21d2-11ef-8c4f-419efbd44d48';
10 const V6_ID = '1ef21d2f-1207-6660-8c4f-419efbd44d48';
11 const fullOptions = {
12 msecs: 0x133b891f705,
13 nsecs: 0x1538,
14 clockseq: 0x385c,
15 node: Uint8Array.of(0x61, 0xcd, 0x3c, 0xbb, 0x32, 0x10),
16 };
17 const EXPECTED_BYTES = Uint8Array.of(0x1e, 0x11, 0x22, 0xbd, 0x94, 0x28, 0x68, 0x88, 0xb8, 0x5c, 0x61, 0xcd, 0x3c, 0xbb, 0x32, 0x10);
18 (0, node_test_1.default)('default behavior', () => {
19 const id = (0, v6_js_1.default)();
20 assert.ok(/[0-9a-f]{8}-[0-9a-f]{4}-6[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/.test(id), 'id is valid v6 UUID');
21 });
22 (0, node_test_1.default)('default behavior (binary type)', () => {
23 const buffer = new Uint8Array(16);
24 const result = (0, v6_js_1.default)(fullOptions, buffer);
25 assert.deepEqual(buffer, EXPECTED_BYTES);
26 assert.strictEqual(buffer, result);
27 });
28 (0, node_test_1.default)('all options', () => {
29 const id = (0, v6_js_1.default)(fullOptions);
30 assert.equal(id, '1e1122bd-9428-6888-b85c-61cd3cbb3210');
31 });
32 (0, node_test_1.default)('sort by creation time', () => {
33 const ids = [];
34 for (let i = 0; i < 5; i++) {
35 ids.push((0, v6_js_1.default)({ msecs: i * 1000 }));
36 }
37 assert.deepEqual(ids, ids.slice().sort());
38 });
39 (0, node_test_1.default)('creating at array offset', () => {
40 const buffer = new Uint8Array(32);
41 (0, v6_js_1.default)(fullOptions, buffer, 0);
42 (0, v6_js_1.default)(fullOptions, buffer, 16);
43 const expectedBuf = new Uint8Array(32);
44 expectedBuf.set(EXPECTED_BYTES, 0);
45 expectedBuf.set(EXPECTED_BYTES, 16);
46 assert.deepEqual(buffer, expectedBuf);
47 });
48 (0, node_test_1.default)('v1 -> v6 conversion', () => {
49 const id = (0, v1ToV6_js_1.default)(V1_ID);
50 assert.equal(id, V6_ID);
51 });
52 (0, node_test_1.default)('v6 -> v1 conversion', () => {
53 const id = (0, v6ToV1_js_1.default)(V6_ID);
54 assert.equal(id, V1_ID);
55 });
56});
Note: See TracBrowser for help on using the repository browser.