|
1 | 1 | import * as assert from 'assert'; |
2 | 2 | import test, { describe } from 'node:test'; |
3 | | -import { Version7Options } from '../types.js'; |
4 | 3 | import parse from '../parse.js'; |
5 | 4 | import stringify from '../stringify.js'; |
| 5 | +import { Version7Options } from '../types.js'; |
6 | 6 | import v7, { updateV7State } from '../v7.js'; |
7 | 7 |
|
8 | 8 | // Fixture values for testing with the rfc v7 UUID example: |
@@ -267,4 +267,28 @@ describe('v7', () => { |
267 | 267 | assert.notStrictEqual(stringify(buf), id); |
268 | 268 | } |
269 | 269 | }); |
| 270 | + |
| 271 | + test('throws when option.random is too short', () => { |
| 272 | + const random = Uint8Array.of(16); |
| 273 | + const buffer = new Uint8Array(16).fill(0); |
| 274 | + assert.throws(() => { |
| 275 | + v7({ random }, buffer); |
| 276 | + }); |
| 277 | + }); |
| 278 | + |
| 279 | + test('throws when options.rng() is too short', () => { |
| 280 | + const buffer = new Uint8Array(16); |
| 281 | + const rng = () => Uint8Array.of(0); // length = 1 |
| 282 | + assert.throws(() => { |
| 283 | + v7({ rng }, buffer); |
| 284 | + }); |
| 285 | + }); |
| 286 | + |
| 287 | + test('throws RangeError for out-of-range indexes', () => { |
| 288 | + const buf15 = new Uint8Array(15); |
| 289 | + const buf30 = new Uint8Array(30); |
| 290 | + assert.throws(() => v7({}, buf15)); |
| 291 | + assert.throws(() => v7({}, buf30, -1)); |
| 292 | + assert.throws(() => v7({}, buf30, 15)); |
| 293 | + }); |
270 | 294 | }); |
0 commit comments