@planet-matrix/mobius-model 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,37 @@
1
+ import { expect, test } from "vitest"
2
+
3
+ import { assertUuid, generateUuid, getUuidVersion, isUuid } from "#Source/random/index.ts"
4
+
5
+ test("isUuid validates UUID input", () => {
6
+ expect(isUuid("550e8400-e29b-41d4-a716-446655440000")).toBe(true)
7
+ expect(isUuid("550E8400-E29B-41D4-A716-446655440000")).toBe(true)
8
+ expect(isUuid("123e4567-e89b-12d3-a456-426614174000")).toBe(true)
9
+
10
+ expect(isUuid("not-a-uuid")).toBe(false)
11
+ expect(isUuid("550e8400e29b41d4a716446655440000")).toBe(false)
12
+ expect(isUuid("550e8400-e29b-91d4-a716-446655440000")).toBe(false)
13
+ expect(isUuid("550e8400-e29b-41d4-c716-446655440000")).toBe(false)
14
+ })
15
+
16
+ test("assertUuid throws on malformed input", () => {
17
+ expect(() => assertUuid("550e8400-e29b-41d4-a716-446655440000")).not.toThrow()
18
+ expect(() => assertUuid("not-a-uuid")).toThrow(TypeError)
19
+ expect(() => assertUuid("550e8400e29b41d4a716446655440000")).toThrow(TypeError)
20
+ })
21
+
22
+ test("getUuidVersion returns UUID version and throws on malformed input", () => {
23
+ expect(getUuidVersion("550e8400-e29b-41d4-a716-446655440000")).toBe(4)
24
+ expect(getUuidVersion("123e4567-e89b-12d3-a456-426614174000")).toBe(1)
25
+
26
+ expect(() => getUuidVersion("not-a-uuid")).toThrow(TypeError)
27
+ })
28
+
29
+ test("generateUuid returns RFC 4122 version-4 UUID format", () => {
30
+ const UUID_V4_REGEXP = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i
31
+ const value1 = generateUuid()
32
+ const value2 = generateUuid()
33
+
34
+ expect(value1).toMatch(UUID_V4_REGEXP)
35
+ expect(value2).toMatch(UUID_V4_REGEXP)
36
+ expect(value1).not.toBe(value2)
37
+ })