| 1 | import { assert, describe, it } from "@effect/vitest" |
| 2 | import * as Uuid from "effect/internal/uuid" |
| 3 | |
| 4 | const bytes = () => Uint8Array.from({ length: 16 }, (_, i) => i) |
| 5 | |
| 6 | describe("Uuid", () => { |
| 7 | it("stringifies UUID bytes", () => { |
| 8 | assert.strictEqual(Uuid.stringify(bytes()), "00010203-0405-0607-0809-0a0b0c0d0e0f") |
| 9 | }) |
| 10 | |
| 11 | it("generates UUID v4 bytes and strings", () => { |
| 12 | assert.deepStrictEqual( |
| 13 | Uuid.v4Bytes(bytes()), |
| 14 | Uint8Array.of(0, 1, 2, 3, 4, 5, 0x46, 7, 0x88, 9, 10, 11, 12, 13, 14, 15) |
| 15 | ) |
| 16 | assert.strictEqual(Uuid.v4String(bytes()), "00010203-0405-4607-8809-0a0b0c0d0e0f") |
| 17 | }) |
| 18 | |
| 19 | it("generates UUID v7 bytes and strings", () => { |
| 20 | assert.deepStrictEqual( |
| 21 | Uuid.v7Bytes(0x0123456789ab, bytes()), |
| 22 | Uint8Array.of(1, 0x23, 0x45, 0x67, 0x89, 0xab, 0x76, 7, 0x88, 9, 10, 11, 12, 13, 14, 15) |
| 23 | ) |
| 24 | assert.strictEqual(Uuid.v7String(0x0123456789ab, bytes()), "01234567-89ab-7607-8809-0a0b0c0d0e0f") |
| 25 | }) |
| 26 | }) |