Builtin UUID module (#68)

* Implement builtin `uuid.parse` method
* Implement builtin `uuid.rfc4122` method
* Parse timestamps for v2 UUIDs
This commit is contained in:
Burak
2023-12-23 17:35:20 +00:00
committed by GitHub
parent 1fb144b145
commit ad3282caf4
5 changed files with 326 additions and 2 deletions

View File

@@ -0,0 +1,45 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
cases:
- note: generate-v4
data: {}
modules:
- |
package test
len := count(uuid.rfc4122("1"))
parsed := uuid.parse(uuid.rfc4122("1"))
query: data.test
want_result:
len: 36
parsed:
variant: "RFC4122"
version: 4
- note: consistent-output
data: {}
modules:
- |
package test
s1 := true { uuid.rfc4122("1") != uuid.rfc4122("2") }
s2 := true { uuid.rfc4122("1") == uuid.rfc4122("1") }
s3 := true { uuid.rfc4122("2") == uuid.rfc4122("2") }
s4 := true { uuid.rfc4122("2") != uuid.rfc4122("3") }
query: data.test
want_result:
s1: true
s2: true
s3: true
s4: true
- note: invalid-type
data: {}
modules:
- |
package test
id := uuid.rfc4122(42)
query: data.test
error: '`uuid.rfc4122` expects string argument. Got `42` instead'

View File

@@ -0,0 +1,128 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
cases:
- note: v1
data: {}
modules:
- |
package test
a := uuid.parse("b01d0062-a116-11ee-822b-7ab0b9e5e0c0")
b := uuid.parse("bdf46d2e-a116-11ee-8c90-0242ac120002")
c := uuid.parse("b3dd08c8-a116-11ee-822b-7ab0b9e5e0c0")
d := uuid.parse("b700c334-a128-11ee-bfff-7ab0b9e5e0c0")
query: data.test
want_result:
a:
clocksequence: 555
macvariables: "local:unicast"
nodeid: "7a-b0-b9-e5-e0-c0"
time: 1703282931110717000
variant: "RFC4122"
version: 1
b:
clocksequence: 3216
macvariables: "local:unicast"
nodeid: "02-42-ac-12-00-02"
time: 1703282954332907000
variant: "RFC4122"
version: 1
c:
clocksequence: 555
macvariables: "local:unicast"
nodeid: "7a-b0-b9-e5-e0-c0"
time: 1703282937402388000
variant: "RFC4122"
version: 1
d:
clocksequence: 16383
macvariables: "local:unicast"
nodeid: "7a-b0-b9-e5-e0-c0"
time: 1703290673610834000
variant: "RFC4122"
version: 1
- note: v2
data: {}
modules:
- |
package test
a := uuid.parse("000003e8-a129-21ee-ae00-325096b39f47")
b := uuid.parse("000003e8-a129-21ee-ab00-325096b39f47")
query: data.test
want_result:
a:
clocksequence: 11776
domain: "Person"
id: 1000
macvariables: "local:unicast"
nodeid: "32-50-96-b3-9f-47"
time: 1703290796079613600
variant: "RFC4122"
version: 2
b:
clocksequence: 11008
domain: "Person"
id: 1000
macvariables: "local:unicast"
nodeid: "32-50-96-b3-9f-47"
time: 1703290796079613600
variant: "RFC4122"
version: 2
- note: others
data: {}
modules:
- |
package test
v3 := uuid.parse("c6db027c-615c-3b4d-959e-1a917747ca5a")
v4 := uuid.parse("a6342df8-7801-469c-b3f3-c5317a0ebdaa")
v5 := uuid.parse("c66bbb60-d62e-5f17-a399-3a0bd237c503")
v6 := uuid.parse("1EC9414C-232A-6B00-B3C8-9E6BDECED846")
v7 := uuid.parse("017F22E2-79B0-7CC3-98C4-DC0C0C07398F")
v8 := uuid.parse("320C3D4D-CC00-875B-8EC9-32D5F69181C0")
query: data.test
want_result:
v3:
variant: "RFC4122"
version: 3
v4:
variant: "RFC4122"
version: 4
v5:
variant: "RFC4122"
version: 5
v6:
variant: "RFC4122"
version: 6
time: 1645557742000000000
v7:
variant: "RFC4122"
version: 7
time: 1645557742000000000
v8:
variant: "RFC4122"
version: 8
- note: invalid-uuid
data: {}
modules:
- |
package test
id := uuid.parse("not-valid")
query: data.test
want_result: {}
- note: invalid-type
data: {}
modules:
- |
package test
id := uuid.parse(42)
query: data.test
error: '`uuid.parse` expects string argument. Got `42` instead'