Skip to content

Commit

Permalink
pkg/uuid: add more valid and invalid test cases
Browse files Browse the repository at this point in the history
And check their results with Valid and Parse, the two main APIs,
which currently disagree on what is a valid UUID string.
The following commit will address that.

Signed-off-by: Daniel Martí <[email protected]>
Change-Id: I2a47ccac5be606f641937def524152974413075a
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1199880
Reviewed-by: Matthew Sackman <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
Unity-Result: CUE porcuepine <[email protected]>
  • Loading branch information
mvdan committed Aug 23, 2024
1 parent 9aabfcb commit a19cab1
Showing 1 changed file with 163 additions and 33 deletions.
196 changes: 163 additions & 33 deletions pkg/uuid/testdata/uuid.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,37 @@ sha1: a: uuid.SHA1(uuid.ns.DNS, "cuelang.org")

md5: a: uuid.MD5(uuid.ns.URL, "https://cuelang.org")

valid: {
a: uuid.Valid
validTable: {
a: "052ef62d-7223-58b6-a551-c1deee46d401"
b: "052EF62D-7223-58B6-A551-C1DEEE46D401"
c: "urn:uuid:123e4567-e89b-12d3-a456-426655440000"
d: "{123e4567-e89b-12d3-a456-426655440000}"
e: "123e4567e89b12d3a456426655440000"
}

invalid: {
a: uuid.Valid
a: "052EF62D-7223-58B6-A551-C1DEEE46D401"
invalidTable: {
a: "052ef62d_7223_58b6_a551_c1deee46d401"
b: "052ef62d-7223-58b6-a551-c1deee"
c: "{123e4567-e89b-12d3-a456-426655440000"
}

b: uuid.Valid
b: "052ef62d_7223_58b6_a551_c1deee46d401"
valid: {
for k, v in validTable {
ok: (k): v & uuid.Valid
}
for k, v in invalidTable {
err: (k): v & uuid.Valid
}
}

parse: a: uuid.Parse("052ef62d722358b6a551c1deee46d401")
parse: {
for k, v in validTable {
ok: (k): uuid.Parse(v)
}
for k, v in invalidTable {
err: (k): uuid.Parse(v)
}
}

fromInt: a: uuid.FromInt(0x052ef62d_7223_58b6_a551_c1deee46d401)

Expand All @@ -28,10 +45,26 @@ urn: a: uuid.URN(sha1.a)
toInt: a: uuid.ToInt(sha1.a)
-- out/uuid-v3 --
Errors:
invalid.a: invalid value "052EF62D-7223-58B6-A551-C1DEEE46D401" (does not satisfy uuid.Valid): invalid UUID "052EF62D-7223-58B6-A551-C1DEEE46D401":
./in.cue:14:5
invalid.b: invalid value "052ef62d_7223_58b6_a551_c1deee46d401" (does not satisfy uuid.Valid): invalid UUID "052ef62d_7223_58b6_a551_c1deee46d401":
valid.err.a: invalid value "052ef62d_7223_58b6_a551_c1deee46d401" (does not satisfy uuid.Valid): invalid UUID "052ef62d_7223_58b6_a551_c1deee46d401":
./in.cue:16:5
valid.err.b: invalid value "052ef62d-7223-58b6-a551-c1deee" (does not satisfy uuid.Valid): invalid UUID "052ef62d-7223-58b6-a551-c1deee":
./in.cue:17:5
valid.err.c: invalid value "{123e4567-e89b-12d3-a456-426655440000" (does not satisfy uuid.Valid): invalid UUID "{123e4567-e89b-12d3-a456-426655440000":
./in.cue:18:5
valid.ok.b: invalid value "052EF62D-7223-58B6-A551-C1DEEE46D401" (does not satisfy uuid.Valid): invalid UUID "052EF62D-7223-58B6-A551-C1DEEE46D401":
./in.cue:9:5
valid.ok.c: invalid value "urn:uuid:123e4567-e89b-12d3-a456-426655440000" (does not satisfy uuid.Valid): invalid UUID "urn:uuid:123e4567-e89b-12d3-a456-426655440000":
./in.cue:10:5
valid.ok.d: invalid value "{123e4567-e89b-12d3-a456-426655440000}" (does not satisfy uuid.Valid): invalid UUID "{123e4567-e89b-12d3-a456-426655440000}":
./in.cue:11:5
valid.ok.e: invalid value "123e4567e89b12d3a456426655440000" (does not satisfy uuid.Valid): invalid UUID "123e4567e89b12d3a456426655440000":
./in.cue:12:5
parse.err.a: error in call to uuid.Parse: invalid UUID format:
./in.cue:35:13
parse.err.b: error in call to uuid.Parse: invalid UUID length: 30:
./in.cue:35:13
parse.err.c: error in call to uuid.Parse: invalid UUID length: 37:
./in.cue:35:13

Result:
sha1: {
Expand All @@ -40,15 +73,45 @@ sha1: {
md5: {
a: "d891d69e-ae5c-39e0-9ead-164abd207f1f"
}
valid: {
validTable: {
a: "052ef62d-7223-58b6-a551-c1deee46d401"
b: "052EF62D-7223-58B6-A551-C1DEEE46D401"
c: "urn:uuid:123e4567-e89b-12d3-a456-426655440000"
d: "{123e4567-e89b-12d3-a456-426655440000}"
e: "123e4567e89b12d3a456426655440000"
}
invalid: {
a: _|_ // invalid.a: invalid value "052EF62D-7223-58B6-A551-C1DEEE46D401" (does not satisfy uuid.Valid): invalid.a: invalid UUID "052EF62D-7223-58B6-A551-C1DEEE46D401"
b: _|_ // invalid.b: invalid value "052ef62d_7223_58b6_a551_c1deee46d401" (does not satisfy uuid.Valid): invalid.b: invalid UUID "052ef62d_7223_58b6_a551_c1deee46d401"
invalidTable: {
a: "052ef62d_7223_58b6_a551_c1deee46d401"
b: "052ef62d-7223-58b6-a551-c1deee"
c: "{123e4567-e89b-12d3-a456-426655440000"
}
valid: {
ok: {
a: "052ef62d-7223-58b6-a551-c1deee46d401"
b: _|_ // valid.ok.b: invalid value "052EF62D-7223-58B6-A551-C1DEEE46D401" (does not satisfy uuid.Valid): valid.ok.b: invalid UUID "052EF62D-7223-58B6-A551-C1DEEE46D401"
c: _|_ // valid.ok.c: invalid value "urn:uuid:123e4567-e89b-12d3-a456-426655440000" (does not satisfy uuid.Valid): valid.ok.c: invalid UUID "urn:uuid:123e4567-e89b-12d3-a456-426655440000"
d: _|_ // valid.ok.d: invalid value "{123e4567-e89b-12d3-a456-426655440000}" (does not satisfy uuid.Valid): valid.ok.d: invalid UUID "{123e4567-e89b-12d3-a456-426655440000}"
e: _|_ // valid.ok.e: invalid value "123e4567e89b12d3a456426655440000" (does not satisfy uuid.Valid): valid.ok.e: invalid UUID "123e4567e89b12d3a456426655440000"
}
err: {
a: _|_ // valid.err.a: invalid value "052ef62d_7223_58b6_a551_c1deee46d401" (does not satisfy uuid.Valid): valid.err.a: invalid UUID "052ef62d_7223_58b6_a551_c1deee46d401"
b: _|_ // valid.err.b: invalid value "052ef62d-7223-58b6-a551-c1deee" (does not satisfy uuid.Valid): valid.err.b: invalid UUID "052ef62d-7223-58b6-a551-c1deee"
c: _|_ // valid.err.c: invalid value "{123e4567-e89b-12d3-a456-426655440000" (does not satisfy uuid.Valid): valid.err.c: invalid UUID "{123e4567-e89b-12d3-a456-426655440000"
}
}
parse: {
a: "052ef62d-7223-58b6-a551-c1deee46d401"
ok: {
a: "052ef62d-7223-58b6-a551-c1deee46d401"
b: "052ef62d-7223-58b6-a551-c1deee46d401"
c: "123e4567-e89b-12d3-a456-426655440000"
d: "123e4567-e89b-12d3-a456-426655440000"
e: "123e4567-e89b-12d3-a456-426655440000"
}
err: {
a: _|_ // parse.err.a: error in call to uuid.Parse: invalid UUID format
b: _|_ // parse.err.b: error in call to uuid.Parse: invalid UUID length: 30
c: _|_ // parse.err.c: error in call to uuid.Parse: invalid UUID length: 37
}
}
fromInt: {
a: "052ef62d-7223-58b6-a551-c1deee46d401"
Expand All @@ -69,26 +132,63 @@ toInt: {
diff old new
--- old
+++ new
@@ -1,9 +1,7 @@
@@ -1,25 +1,18 @@
Errors:
invalid.a: invalid value "052EF62D-7223-58B6-A551-C1DEEE46D401" (does not satisfy uuid.Valid): invalid UUID "052EF62D-7223-58B6-A551-C1DEEE46D401":
- ./in.cue:13:5
./in.cue:14:5
invalid.b: invalid value "052ef62d_7223_58b6_a551_c1deee46d401" (does not satisfy uuid.Valid): invalid UUID "052ef62d_7223_58b6_a551_c1deee46d401":
- ./in.cue:16:5
valid.err.a: invalid value "052ef62d_7223_58b6_a551_c1deee46d401" (does not satisfy uuid.Valid): invalid UUID "052ef62d_7223_58b6_a551_c1deee46d401":
./in.cue:16:5
- ./in.cue:26:13
valid.err.b: invalid value "052ef62d-7223-58b6-a551-c1deee" (does not satisfy uuid.Valid): invalid UUID "052ef62d-7223-58b6-a551-c1deee":
./in.cue:17:5

Result:
- ./in.cue:26:13
valid.err.c: invalid value "{123e4567-e89b-12d3-a456-426655440000" (does not satisfy uuid.Valid): invalid UUID "{123e4567-e89b-12d3-a456-426655440000":
./in.cue:18:5
- ./in.cue:26:13
valid.ok.b: invalid value "052EF62D-7223-58B6-A551-C1DEEE46D401" (does not satisfy uuid.Valid): invalid UUID "052EF62D-7223-58B6-A551-C1DEEE46D401":
./in.cue:9:5
- ./in.cue:23:12
valid.ok.c: invalid value "urn:uuid:123e4567-e89b-12d3-a456-426655440000" (does not satisfy uuid.Valid): invalid UUID "urn:uuid:123e4567-e89b-12d3-a456-426655440000":
./in.cue:10:5
- ./in.cue:23:12
valid.ok.d: invalid value "{123e4567-e89b-12d3-a456-426655440000}" (does not satisfy uuid.Valid): invalid UUID "{123e4567-e89b-12d3-a456-426655440000}":
./in.cue:11:5
- ./in.cue:23:12
valid.ok.e: invalid value "123e4567e89b12d3a456426655440000" (does not satisfy uuid.Valid): invalid UUID "123e4567e89b12d3a456426655440000":
./in.cue:12:5
- ./in.cue:23:12
parse.err.a: error in call to uuid.Parse: invalid UUID format:
./in.cue:35:13
parse.err.b: error in call to uuid.Parse: invalid UUID length: 30:
-- diff/todo/p2 --
Missing error positions.
-- out/uuid --
Errors:
invalid.a: invalid value "052EF62D-7223-58B6-A551-C1DEEE46D401" (does not satisfy uuid.Valid): invalid UUID "052EF62D-7223-58B6-A551-C1DEEE46D401":
./in.cue:13:5
./in.cue:14:5
invalid.b: invalid value "052ef62d_7223_58b6_a551_c1deee46d401" (does not satisfy uuid.Valid): invalid UUID "052ef62d_7223_58b6_a551_c1deee46d401":
valid.err.a: invalid value "052ef62d_7223_58b6_a551_c1deee46d401" (does not satisfy uuid.Valid): invalid UUID "052ef62d_7223_58b6_a551_c1deee46d401":
./in.cue:16:5
./in.cue:26:13
valid.err.b: invalid value "052ef62d-7223-58b6-a551-c1deee" (does not satisfy uuid.Valid): invalid UUID "052ef62d-7223-58b6-a551-c1deee":
./in.cue:17:5
./in.cue:26:13
valid.err.c: invalid value "{123e4567-e89b-12d3-a456-426655440000" (does not satisfy uuid.Valid): invalid UUID "{123e4567-e89b-12d3-a456-426655440000":
./in.cue:18:5
./in.cue:26:13
valid.ok.b: invalid value "052EF62D-7223-58B6-A551-C1DEEE46D401" (does not satisfy uuid.Valid): invalid UUID "052EF62D-7223-58B6-A551-C1DEEE46D401":
./in.cue:9:5
./in.cue:23:12
valid.ok.c: invalid value "urn:uuid:123e4567-e89b-12d3-a456-426655440000" (does not satisfy uuid.Valid): invalid UUID "urn:uuid:123e4567-e89b-12d3-a456-426655440000":
./in.cue:10:5
./in.cue:23:12
valid.ok.d: invalid value "{123e4567-e89b-12d3-a456-426655440000}" (does not satisfy uuid.Valid): invalid UUID "{123e4567-e89b-12d3-a456-426655440000}":
./in.cue:11:5
./in.cue:23:12
valid.ok.e: invalid value "123e4567e89b12d3a456426655440000" (does not satisfy uuid.Valid): invalid UUID "123e4567e89b12d3a456426655440000":
./in.cue:12:5
./in.cue:23:12
parse.err.a: error in call to uuid.Parse: invalid UUID format:
./in.cue:35:13
parse.err.b: error in call to uuid.Parse: invalid UUID length: 30:
./in.cue:35:13
parse.err.c: error in call to uuid.Parse: invalid UUID length: 37:
./in.cue:35:13

Result:
sha1: {
Expand All @@ -97,15 +197,45 @@ sha1: {
md5: {
a: "d891d69e-ae5c-39e0-9ead-164abd207f1f"
}
valid: {
validTable: {
a: "052ef62d-7223-58b6-a551-c1deee46d401"
b: "052EF62D-7223-58B6-A551-C1DEEE46D401"
c: "urn:uuid:123e4567-e89b-12d3-a456-426655440000"
d: "{123e4567-e89b-12d3-a456-426655440000}"
e: "123e4567e89b12d3a456426655440000"
}
invalid: {
a: _|_ // invalid.a: invalid value "052EF62D-7223-58B6-A551-C1DEEE46D401" (does not satisfy uuid.Valid): invalid.a: invalid UUID "052EF62D-7223-58B6-A551-C1DEEE46D401"
b: _|_ // invalid.b: invalid value "052ef62d_7223_58b6_a551_c1deee46d401" (does not satisfy uuid.Valid): invalid.b: invalid UUID "052ef62d_7223_58b6_a551_c1deee46d401"
invalidTable: {
a: "052ef62d_7223_58b6_a551_c1deee46d401"
b: "052ef62d-7223-58b6-a551-c1deee"
c: "{123e4567-e89b-12d3-a456-426655440000"
}
valid: {
ok: {
a: "052ef62d-7223-58b6-a551-c1deee46d401"
b: _|_ // valid.ok.b: invalid value "052EF62D-7223-58B6-A551-C1DEEE46D401" (does not satisfy uuid.Valid): valid.ok.b: invalid UUID "052EF62D-7223-58B6-A551-C1DEEE46D401"
c: _|_ // valid.ok.c: invalid value "urn:uuid:123e4567-e89b-12d3-a456-426655440000" (does not satisfy uuid.Valid): valid.ok.c: invalid UUID "urn:uuid:123e4567-e89b-12d3-a456-426655440000"
d: _|_ // valid.ok.d: invalid value "{123e4567-e89b-12d3-a456-426655440000}" (does not satisfy uuid.Valid): valid.ok.d: invalid UUID "{123e4567-e89b-12d3-a456-426655440000}"
e: _|_ // valid.ok.e: invalid value "123e4567e89b12d3a456426655440000" (does not satisfy uuid.Valid): valid.ok.e: invalid UUID "123e4567e89b12d3a456426655440000"
}
err: {
a: _|_ // valid.err.a: invalid value "052ef62d_7223_58b6_a551_c1deee46d401" (does not satisfy uuid.Valid): valid.err.a: invalid UUID "052ef62d_7223_58b6_a551_c1deee46d401"
b: _|_ // valid.err.b: invalid value "052ef62d-7223-58b6-a551-c1deee" (does not satisfy uuid.Valid): valid.err.b: invalid UUID "052ef62d-7223-58b6-a551-c1deee"
c: _|_ // valid.err.c: invalid value "{123e4567-e89b-12d3-a456-426655440000" (does not satisfy uuid.Valid): valid.err.c: invalid UUID "{123e4567-e89b-12d3-a456-426655440000"
}
}
parse: {
a: "052ef62d-7223-58b6-a551-c1deee46d401"
ok: {
a: "052ef62d-7223-58b6-a551-c1deee46d401"
b: "052ef62d-7223-58b6-a551-c1deee46d401"
c: "123e4567-e89b-12d3-a456-426655440000"
d: "123e4567-e89b-12d3-a456-426655440000"
e: "123e4567-e89b-12d3-a456-426655440000"
}
err: {
a: _|_ // parse.err.a: error in call to uuid.Parse: invalid UUID format
b: _|_ // parse.err.b: error in call to uuid.Parse: invalid UUID length: 30
c: _|_ // parse.err.c: error in call to uuid.Parse: invalid UUID length: 37
}
}
fromInt: {
a: "052ef62d-7223-58b6-a551-c1deee46d401"
Expand Down

0 comments on commit a19cab1

Please sign in to comment.