Skip to content

Commit

Permalink
pkg/list: add more test cases for list.UniqueItems
Browse files Browse the repository at this point in the history
Specifically, explicitly cover the cases raised in
https://cuelang.org/issue/2192 that cover incomplete types that are
otherwise identical, and open/closed struct values that are otherwise
identical.

Signed-off-by: Paul Jolly <paul@myitcv.io>
Change-Id: I0b91bb79aa0599c8ce4c42014e3444ebc7afa0ca
Dispatch-Trailer: {"type":"trybot","CL":1206606,"patchset":2,"ref":"refs/changes/06/1206606/2","targetBranch":"master"}
  • Loading branch information
myitcv authored and cueckoo committed Jan 3, 2025
1 parent e44b17d commit adb9508
Showing 1 changed file with 77 additions and 4 deletions.
81 changes: 77 additions & 4 deletions pkg/list/testdata/unique.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,31 @@ fail: {
// element is erroneous an cannot match.
ignoreOptError: [#a, #abErr]
}

// Value could still become more specific, and thus different.
incomplete: ints: [int, int]

// Struct field order is irrelevant, but these structs
// are open and hence they might gain more fields later
// which would make the values unique.
incomplete: openStructs: [{
b: 1
a: 0
}, {
a: 0
b: 1
}]

// Struct field order is irrelevant. We simulate finalising
// these values here via close(), which gives the same behaviour
// as 'cue vet -c' on otherwise open values.
fail: structOrderIrrelevant: [close({
b: 1
a: 0
}), close({
a: 0
b: 1
})]
-- out/list-v3 --
Errors:
fail.ignoreHidden: invalid value [1,1] (does not satisfy list.UniqueItems): equal value (1) at position 0 and 1:
Expand All @@ -63,6 +88,9 @@ fail.ignoreOptError: invalid value [~(#a),~(#abErr)] (does not satisfy list.Uniq
fail.ints: invalid value [1,2,1] (does not satisfy list.UniqueItems): equal value (1) at position 0 and 2:
./in.cue:3:21
./in.cue:44:8
fail.structOrderIrrelevant: invalid value [{b:1,a:0},{a:0,b:1}] (does not satisfy list.UniqueItems): equal values at position 0 and 1:
./in.cue:3:21
./in.cue:72:30
fail.structs: invalid value [~(#a),~(#a)] (does not satisfy list.UniqueItems): equal values at position 0 and 1:
./in.cue:3:21
./in.cue:45:11
Expand Down Expand Up @@ -131,6 +159,20 @@ incomplete: {
a: 1
}]

// Value could still become more specific, and thus different.
ints: list.UniqueItems() & [int, int]

// Struct field order is irrelevant, but these structs
// are open and hence they might gain more fields later
// which would make the values unique.
openStructs: list.UniqueItems() & [{
b: 1
a: 0
}, {
a: 0
b: 1
}]

// Fully identical closed structs, but with non-concrete values.
structs: list.UniqueItems() & [#c, #c]
}
Expand All @@ -141,6 +183,11 @@ fail: {
// Hidden values do not play a role in the comparisson.
ignoreHidden: _|_ // fail.ignoreHidden: invalid value [1,1] (does not satisfy list.UniqueItems): equal value (1) at position 0 and 1

// Struct field order is irrelevant. We simulate finalising
// these values here via close(), which gives the same behaviour
// as 'cue vet -c' on otherwise open values.
structOrderIrrelevant: _|_ // fail.structOrderIrrelevant: invalid value [{b:1,a:0},{a:0,b:1}] (does not satisfy list.UniqueItems): equal values at position 0 and 1

// This can be a permanent error, as the optional field of the second
// element is erroneous an cannot match.
ignoreOptError: _|_ // fail.ignoreOptError: invalid value [~(#a),~(#abErr)] (does not satisfy list.UniqueItems): equal values at position 0 and 1
Expand All @@ -149,7 +196,7 @@ fail: {
diff old new
--- old
+++ new
@@ -2,10 +2,13 @@
@@ -2,6 +2,9 @@
fail.ignoreHidden: invalid value [1,1] (does not satisfy list.UniqueItems): equal value (1) at position 0 and 1:
./in.cue:3:21
./in.cue:48:16
Expand All @@ -159,12 +206,16 @@ diff old new
fail.ints: invalid value [1,2,1] (does not satisfy list.UniqueItems): equal value (1) at position 0 and 2:
./in.cue:3:21
./in.cue:44:8
@@ -8,7 +11,7 @@
fail.structOrderIrrelevant: invalid value [{b:1,a:0},{a:0,b:1}] (does not satisfy list.UniqueItems): equal values at position 0 and 1:
./in.cue:3:21
./in.cue:72:30
-fail.structs: invalid value [{a:1},{a:1}] (does not satisfy list.UniqueItems): equal values at position 0 and 1:
+fail.structs: invalid value [~(#a),~(#a)] (does not satisfy list.UniqueItems): equal values at position 0 and 1:
./in.cue:3:21
./in.cue:45:11

@@ -64,12 +67,7 @@
@@ -67,12 +70,7 @@
}]

// Ditto. This time with actually closed fields.
Expand All @@ -178,7 +229,7 @@ diff old new

// Ditto. There are not optional fields, but the structs are open.
openSpecific: list.UniqueItems() & [{
@@ -83,7 +81,7 @@
@@ -100,7 +98,7 @@
}
fail: {
ints: _|_ // fail.ints: invalid value [1,2,1] (does not satisfy list.UniqueItems): equal value (1) at position 0 and 2
Expand All @@ -187,7 +238,7 @@ diff old new

// Hidden values do not play a role in the comparisson.
ignoreHidden: _|_ // fail.ignoreHidden: invalid value [1,1] (does not satisfy list.UniqueItems): equal value (1) at position 0 and 1
@@ -90,10 +88,5 @@
@@ -112,10 +110,5 @@

// This can be a permanent error, as the optional field of the second
// element is erroneous an cannot match.
Expand All @@ -207,6 +258,9 @@ fail.ignoreHidden: invalid value [1,1] (does not satisfy list.UniqueItems): equa
fail.ints: invalid value [1,2,1] (does not satisfy list.UniqueItems): equal value (1) at position 0 and 2:
./in.cue:3:21
./in.cue:44:8
fail.structOrderIrrelevant: invalid value [{b:1,a:0},{a:0,b:1}] (does not satisfy list.UniqueItems): equal values at position 0 and 1:
./in.cue:3:21
./in.cue:72:30
fail.structs: invalid value [{a:1},{a:1}] (does not satisfy list.UniqueItems): equal values at position 0 and 1:
./in.cue:3:21
./in.cue:45:11
Expand Down Expand Up @@ -280,6 +334,20 @@ incomplete: {
a: 1
}]

// Value could still become more specific, and thus different.
ints: list.UniqueItems() & [int, int]

// Struct field order is irrelevant, but these structs
// are open and hence they might gain more fields later
// which would make the values unique.
openStructs: list.UniqueItems() & [{
b: 1
a: 0
}, {
a: 0
b: 1
}]

// Fully identical closed structs, but with non-concrete values.
structs: list.UniqueItems() & [#c, #c]
}
Expand All @@ -290,6 +358,11 @@ fail: {
// Hidden values do not play a role in the comparisson.
ignoreHidden: _|_ // fail.ignoreHidden: invalid value [1,1] (does not satisfy list.UniqueItems): equal value (1) at position 0 and 1

// Struct field order is irrelevant. We simulate finalising
// these values here via close(), which gives the same behaviour
// as 'cue vet -c' on otherwise open values.
structOrderIrrelevant: _|_ // fail.structOrderIrrelevant: invalid value [{b:1,a:0},{a:0,b:1}] (does not satisfy list.UniqueItems): equal values at position 0 and 1

// This can be a permanent error, as the optional field of the second
// element is erroneous an cannot match.
ignoreOptError: [{
Expand Down

0 comments on commit adb9508

Please sign in to comment.