import { expect, test } from "vitest" import { assertId, generateId, idToString, isEqualId, isId, isSameId, } from "#Source/identifier/index.ts" test("generateId is seed-stable and no-seed calls are uncached", () => { const first = generateId("user:42") const second = generateId("user:42") const third = generateId("user:43") const withoutSeed1 = generateId() const withoutSeed2 = generateId() const undefinedSeed1 = generateId(undefined) const undefinedSeed2 = generateId(undefined) expect(first).toBe(second) expect(first).not.toBe(third) expect(withoutSeed1).not.toBe(withoutSeed2) expect(undefinedSeed1).not.toBe(undefinedSeed2) expect(withoutSeed1).not.toBe(undefinedSeed1) }) test("isId validates generated Id values", () => { const id = generateId(1) expect(isId(id)).toBe(true) expect(isId(null)).toBe(false) expect(isId(undefined)).toBe(false) expect(isId("plain-string")).toBe(false) expect(isId({})).toBe(false) }) test("assertId throws for non-Id inputs", () => { const id = generateId(Symbol("seed")) expect(() => assertId(id)).not.toThrow() expect(() => assertId("plain-string")).toThrow(TypeError) expect(() => assertId(1)).toThrow(TypeError) }) test("isSameId compares by instance identity", () => { const id = generateId("same") const sameReference = id const another = generateId("another") expect(isSameId(id, sameReference)).toBe(true) expect(isSameId(id, another)).toBe(false) }) test("isEqualId compares internal ID value", () => { const first = generateId("equal-seed") const second = generateId("equal-seed") const third = generateId("different-seed") expect(isEqualId(first, second)).toBe(true) expect(isEqualId(first, third)).toBe(false) }) test("idToString serializes Id to readable label", () => { const id = generateId("to-string") const asString = idToString(id) expect(asString.startsWith("Symbol-ID-")).toBe(true) // oxlint-disable-next-line typescript/no-base-to-string expect(asString).toBe(String(id)) })