cuelang.org/go@v0.13.0/pkg/list/testdata/unique.txtar (about) 1 -- in.cue -- 2 import "list" 3 4 [string]: [string]: list.UniqueItems() 5 6 #a: {a: 1} 7 #ab: {a: 1, b?: int} 8 #abErr: #ab & {b?: string} // erroneous optional field b. 9 10 #b: {b: 1} 11 #c: {c: int} 12 13 ok: { 14 t1: [1, 2, 3] 15 t2: [int, string, bool] 16 t3: ["1", 1] 17 t4: ["1", "2"] 18 t5: [#a, #b] 19 } 20 21 // These have all equal elements, but 22 incomplete: { 23 top: [_, _] 24 25 // These two elements are considered equal, but the error is an "incomplete" 26 // errors, as the items may still differ once they become more specific. 27 withOptional1: [{a: int}, {a: int, b?: string}] 28 29 // Ditto. This is an incomplete error, even though the matching elements 30 // are "final": there is still an optional field. 31 withOptional2: [{a: 1}, {a: 1, b?: string}] 32 33 // Ditto. This time with actually closed fields. 34 withOptional3: [#a, #ab] 35 36 // Ditto. There are not optional fields, but the structs are open. 37 openSpecific: [{a: 1}, {a: 1}] 38 39 // Fully identical closed structs, but with non-concrete values. 40 structs: [#c, #c] 41 42 } 43 44 fail: { 45 ints: [1, 2, 1] 46 structs: [#a, #a] 47 48 // Hidden values do not play a role in the comparisson. 49 ignoreHidden: [1, {1, _foo: 3}] 50 51 // This can be a permanent error, as the optional field of the second 52 // element is erroneous an cannot match. 53 ignoreOptError: [#a, #abErr] 54 } 55 56 // Value could still become more specific, and thus different. 57 incomplete: ints: [int, int] 58 59 // Struct field order is irrelevant, but these structs 60 // are open and hence they might gain more fields later 61 // which would make the values unique. 62 incomplete: openStructs: [{ 63 b: 1 64 a: 0 65 }, { 66 a: 0 67 b: 1 68 }] 69 70 // Struct field order is irrelevant. We simulate finalising 71 // these values here via close(), which gives the same behaviour 72 // as 'cue vet -c' on otherwise open values. 73 fail: structOrderIrrelevant: [close({ 74 b: 1 75 a: 0 76 }), close({ 77 a: 0 78 b: 1 79 })] 80 -- out/list-v3 -- 81 Errors: 82 fail.ignoreHidden: invalid value [1,1] (does not satisfy list.UniqueItems): equal value (1) at position 0 and 1: 83 ./in.cue:3:21 84 ./in.cue:48:16 85 fail.ignoreOptError: invalid value [~(#a),~(#abErr)] (does not satisfy list.UniqueItems): equal values at position 0 and 1: 86 ./in.cue:3:21 87 ./in.cue:52:18 88 fail.ints: invalid value [1,2,1] (does not satisfy list.UniqueItems): equal value (1) at position 0 and 2: 89 ./in.cue:3:21 90 ./in.cue:44:8 91 fail.structOrderIrrelevant: invalid value [{b:1,a:0},{a:0,b:1}] (does not satisfy list.UniqueItems): equal values at position 0 and 1: 92 ./in.cue:3:21 93 ./in.cue:72:30 94 fail.structs: invalid value [~(#a),~(#a)] (does not satisfy list.UniqueItems): equal values at position 0 and 1: 95 ./in.cue:3:21 96 ./in.cue:45:11 97 98 Result: 99 import "list" 100 101 #a: { 102 a: 1 103 } 104 #ab: { 105 a: 1 106 b?: int 107 } 108 #abErr: { 109 a: 1 110 b?: int & string 111 } 112 #b: { 113 b: 1 114 } 115 #c: { 116 c: int 117 } 118 ok: { 119 t1: [1, 2, 3] 120 t2: [int, string, bool] 121 t3: ["1", 1] 122 t4: ["1", "2"] 123 t5: [{ 124 a: 1 125 }, { 126 b: 1 127 }] 128 } 129 130 // These have all equal elements, but 131 incomplete: { 132 top: list.UniqueItems() & [_, _] 133 134 // These two elements are considered equal, but the error is an "incomplete" 135 // errors, as the items may still differ once they become more specific. 136 withOptional1: list.UniqueItems() & [{ 137 a: int 138 }, { 139 a: int 140 b?: string 141 }] 142 143 // Ditto. This is an incomplete error, even though the matching elements 144 // are "final": there is still an optional field. 145 withOptional2: list.UniqueItems() & [{ 146 a: 1 147 }, { 148 a: 1 149 b?: string 150 }] 151 152 // Ditto. This time with actually closed fields. 153 withOptional3: list.UniqueItems() & [#a, #ab] 154 155 // Ditto. There are not optional fields, but the structs are open. 156 openSpecific: list.UniqueItems() & [{ 157 a: 1 158 }, { 159 a: 1 160 }] 161 162 // Fully identical closed structs, but with non-concrete values. 163 structs: list.UniqueItems() & [#c, #c] 164 165 // Value could still become more specific, and thus different. 166 ints: list.UniqueItems() & [int, int] 167 168 // Struct field order is irrelevant, but these structs 169 // are open and hence they might gain more fields later 170 // which would make the values unique. 171 openStructs: list.UniqueItems() & [{ 172 b: 1 173 a: 0 174 }, { 175 a: 0 176 b: 1 177 }] 178 } 179 fail: { 180 ints: _|_ // fail.ints: invalid value [1,2,1] (does not satisfy list.UniqueItems): equal value (1) at position 0 and 2 181 structs: _|_ // fail.structs: invalid value [~(#a),~(#a)] (does not satisfy list.UniqueItems): equal values at position 0 and 1 182 183 // Hidden values do not play a role in the comparisson. 184 ignoreHidden: _|_ // fail.ignoreHidden: invalid value [1,1] (does not satisfy list.UniqueItems): equal value (1) at position 0 and 1 185 186 // This can be a permanent error, as the optional field of the second 187 // element is erroneous an cannot match. 188 ignoreOptError: _|_ // fail.ignoreOptError: invalid value [~(#a),~(#abErr)] (does not satisfy list.UniqueItems): equal values at position 0 and 1 189 190 // Struct field order is irrelevant. We simulate finalising 191 // these values here via close(), which gives the same behaviour 192 // as 'cue vet -c' on otherwise open values. 193 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 194 } 195 -- diff/-out/list-v3<==>+out/list -- 196 diff old new 197 --- old 198 +++ new 199 @@ -2,6 +2,9 @@ 200 fail.ignoreHidden: invalid value [1,1] (does not satisfy list.UniqueItems): equal value (1) at position 0 and 1: 201 ./in.cue:3:21 202 ./in.cue:48:16 203 +fail.ignoreOptError: invalid value [~(#a),~(#abErr)] (does not satisfy list.UniqueItems): equal values at position 0 and 1: 204 + ./in.cue:3:21 205 + ./in.cue:52:18 206 fail.ints: invalid value [1,2,1] (does not satisfy list.UniqueItems): equal value (1) at position 0 and 2: 207 ./in.cue:3:21 208 ./in.cue:44:8 209 @@ -8,7 +11,7 @@ 210 fail.structOrderIrrelevant: invalid value [{b:1,a:0},{a:0,b:1}] (does not satisfy list.UniqueItems): equal values at position 0 and 1: 211 ./in.cue:3:21 212 ./in.cue:72:30 213 -fail.structs: invalid value [{a:1},{a:1}] (does not satisfy list.UniqueItems): equal values at position 0 and 1: 214 +fail.structs: invalid value [~(#a),~(#a)] (does not satisfy list.UniqueItems): equal values at position 0 and 1: 215 ./in.cue:3:21 216 ./in.cue:45:11 217 218 @@ -67,12 +70,7 @@ 219 }] 220 221 // Ditto. This time with actually closed fields. 222 - withOptional3: [{ 223 - a: 1 224 - }, { 225 - a: 1 226 - b?: int 227 - }] 228 + withOptional3: list.UniqueItems() & [#a, #ab] 229 230 // Ditto. There are not optional fields, but the structs are open. 231 openSpecific: list.UniqueItems() & [{ 232 @@ -100,7 +98,7 @@ 233 } 234 fail: { 235 ints: _|_ // fail.ints: invalid value [1,2,1] (does not satisfy list.UniqueItems): equal value (1) at position 0 and 2 236 - structs: _|_ // fail.structs: invalid value [{a:1},{a:1}] (does not satisfy list.UniqueItems): equal values at position 0 and 1 237 + structs: _|_ // fail.structs: invalid value [~(#a),~(#a)] (does not satisfy list.UniqueItems): equal values at position 0 and 1 238 239 // Hidden values do not play a role in the comparisson. 240 ignoreHidden: _|_ // fail.ignoreHidden: invalid value [1,1] (does not satisfy list.UniqueItems): equal value (1) at position 0 and 1 241 @@ -107,12 +105,7 @@ 242 243 // This can be a permanent error, as the optional field of the second 244 // element is erroneous an cannot match. 245 - ignoreOptError: [{ 246 - a: 1 247 - }, { 248 - a: 1 249 - b?: int & string 250 - }] 251 + ignoreOptError: _|_ // fail.ignoreOptError: invalid value [~(#a),~(#abErr)] (does not satisfy list.UniqueItems): equal values at position 0 and 1 252 253 // Struct field order is irrelevant. We simulate finalising 254 // these values here via close(), which gives the same behaviour 255 -- out/list -- 256 Errors: 257 fail.ignoreHidden: invalid value [1,1] (does not satisfy list.UniqueItems): equal value (1) at position 0 and 1: 258 ./in.cue:3:21 259 ./in.cue:48:16 260 fail.ints: invalid value [1,2,1] (does not satisfy list.UniqueItems): equal value (1) at position 0 and 2: 261 ./in.cue:3:21 262 ./in.cue:44:8 263 fail.structOrderIrrelevant: invalid value [{b:1,a:0},{a:0,b:1}] (does not satisfy list.UniqueItems): equal values at position 0 and 1: 264 ./in.cue:3:21 265 ./in.cue:72:30 266 fail.structs: invalid value [{a:1},{a:1}] (does not satisfy list.UniqueItems): equal values at position 0 and 1: 267 ./in.cue:3:21 268 ./in.cue:45:11 269 270 Result: 271 import "list" 272 273 #a: { 274 a: 1 275 } 276 #ab: { 277 a: 1 278 b?: int 279 } 280 #abErr: { 281 a: 1 282 b?: int & string 283 } 284 #b: { 285 b: 1 286 } 287 #c: { 288 c: int 289 } 290 ok: { 291 t1: [1, 2, 3] 292 t2: [int, string, bool] 293 t3: ["1", 1] 294 t4: ["1", "2"] 295 t5: [{ 296 a: 1 297 }, { 298 b: 1 299 }] 300 } 301 302 // These have all equal elements, but 303 incomplete: { 304 top: list.UniqueItems() & [_, _] 305 306 // These two elements are considered equal, but the error is an "incomplete" 307 // errors, as the items may still differ once they become more specific. 308 withOptional1: list.UniqueItems() & [{ 309 a: int 310 }, { 311 a: int 312 b?: string 313 }] 314 315 // Ditto. This is an incomplete error, even though the matching elements 316 // are "final": there is still an optional field. 317 withOptional2: list.UniqueItems() & [{ 318 a: 1 319 }, { 320 a: 1 321 b?: string 322 }] 323 324 // Ditto. This time with actually closed fields. 325 withOptional3: [{ 326 a: 1 327 }, { 328 a: 1 329 b?: int 330 }] 331 332 // Ditto. There are not optional fields, but the structs are open. 333 openSpecific: list.UniqueItems() & [{ 334 a: 1 335 }, { 336 a: 1 337 }] 338 339 // Fully identical closed structs, but with non-concrete values. 340 structs: list.UniqueItems() & [#c, #c] 341 342 // Value could still become more specific, and thus different. 343 ints: list.UniqueItems() & [int, int] 344 345 // Struct field order is irrelevant, but these structs 346 // are open and hence they might gain more fields later 347 // which would make the values unique. 348 openStructs: list.UniqueItems() & [{ 349 b: 1 350 a: 0 351 }, { 352 a: 0 353 b: 1 354 }] 355 } 356 fail: { 357 ints: _|_ // fail.ints: invalid value [1,2,1] (does not satisfy list.UniqueItems): equal value (1) at position 0 and 2 358 structs: _|_ // fail.structs: invalid value [{a:1},{a:1}] (does not satisfy list.UniqueItems): equal values at position 0 and 1 359 360 // Hidden values do not play a role in the comparisson. 361 ignoreHidden: _|_ // fail.ignoreHidden: invalid value [1,1] (does not satisfy list.UniqueItems): equal value (1) at position 0 and 1 362 363 // This can be a permanent error, as the optional field of the second 364 // element is erroneous an cannot match. 365 ignoreOptError: [{ 366 a: 1 367 }, { 368 a: 1 369 b?: int & string 370 }] 371 372 // Struct field order is irrelevant. We simulate finalising 373 // these values here via close(), which gives the same behaviour 374 // as 'cue vet -c' on otherwise open values. 375 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 376 }