Skip to content

Commit

Permalink
test: add api surface test v4()
Browse files Browse the repository at this point in the history
  • Loading branch information
ctavan committed Jan 23, 2020
1 parent a91a699 commit d6c7378
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions test/unit/unit.test.js
Expand Up @@ -7,6 +7,7 @@ import sha1 from '../../src/sha1.js';
import sha1Browser from '../../src/sha1-browser.js';
import v1 from '../../src/v1.js';
import v3 from '../../src/v3.js';
import v4 from '../../src/v4.js';
import v5 from '../../src/v5.js';

describe('rng', () => {
Expand Down Expand Up @@ -136,6 +137,78 @@ describe('v1', () => {
});
});

describe('v4', () => {
const randomBytesFixture = [
0x10,
0x91,
0x56,
0xbe,
0xc4,
0xfb,
0xc1,
0xea,
0x71,
0xb4,
0xef,
0xe1,
0x67,
0x1c,
0x58,
0x36,
];
const expectedBytes = [16, 145, 86, 190, 196, 251, 65, 234, 177, 180, 239, 225, 103, 28, 88, 54];

test('subsequent UUIDs are different', () => {
const id1 = v4();
const id2 = v4();
assert(id1 !== id2);
});

test('explicit options.random produces expected result', () => {
const id = v4({
random: randomBytesFixture,
});
assert.strictEqual(id, '109156be-c4fb-41ea-b1b4-efe1671c5836');
});

test('explicit options.rng produces expected result', () => {
const id = v4({
rng: () => randomBytesFixture,
});
assert.strictEqual(id, '109156be-c4fb-41ea-b1b4-efe1671c5836');
});

test('fills one UUID into a buffer as expected', () => {
const buffer = new Array();
v4(
{
random: randomBytesFixture,
},
buffer,
);
assert.deepEqual(buffer, expectedBytes);
});

test('fills two UUIDs into a buffer as expected', () => {
const buffer = new Array();
v4(
{
random: randomBytesFixture,
},
buffer,
0,
);
v4(
{
random: randomBytesFixture,
},
buffer,
16,
);
assert.deepEqual(buffer, expectedBytes.concat(expectedBytes));
});
});

describe('v5', () => {
const HASH_SAMPLES = [
{
Expand Down

0 comments on commit d6c7378

Please sign in to comment.