this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

cue/testdata/cycle: add regression test for issue 4244

The added test case shows that reordering the data fields causes
a schema with "let" fields suddenly change from succeeding to erroring.

For #4244

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: Ie6deecb41d514126d60ec66d7f75b254e5416cc5
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1230697
Reviewed-by: Marcel van Lohuizen <mpvl@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>

+120
+120
cue/testdata/cycle/issue4244.txtar
··· 1 + -- in.cue -- 2 + import "strings" 3 + 4 + #schema: { 5 + let splits = strings.Split(id, "_never_") 6 + let prefix = splits[0] 7 + 8 + #ID: =~"^\(prefix)$" 9 + #SubID: =~"^\(prefix):sub$" 10 + 11 + id: #ID 12 + subid: #SubID 13 + } 14 + 15 + case1: #schema & { 16 + id: "foo" 17 + subid: "foo:sub" 18 + } 19 + 20 + case2: #schema & { 21 + subid: "foo:sub" 22 + id: "foo" 23 + } 24 + -- out/evalalpha -- 25 + Errors: 26 + case2.subid: invalid value "foo:sub" (out of bound =~"^:sub$"): 27 + ./in.cue:8:10 28 + ./in.cue:11:9 29 + ./in.cue:20:9 30 + 31 + Result: 32 + (_|_){ 33 + // [eval] 34 + #schema: (#struct){ 35 + let splits#1 = (_|_){ 36 + // [cycle] #schema.#ID: invalid interpolation: cycle with field: prefix: 37 + // ./in.cue:7:12 38 + // ./in.cue:7:16 39 + } 40 + let prefix#2 = (_|_){ 41 + // [incomplete] #schema.prefix: index out of range [0] with length 1: 42 + // ./in.cue:5:22 43 + } 44 + #ID: (_|_){ 45 + // [cycle] #schema.#ID: invalid interpolation: cycle with field: prefix: 46 + // ./in.cue:7:12 47 + // ./in.cue:7:16 48 + } 49 + #SubID: (_|_){ 50 + // [cycle] #schema.#ID: invalid interpolation: cycle with field: prefix: 51 + // ./in.cue:8:12 52 + // ./in.cue:7:16 53 + } 54 + id: (_|_){ 55 + // [cycle] #schema.#ID: invalid interpolation: cycle with field: prefix: 56 + // ./in.cue:7:12 57 + // ./in.cue:7:16 58 + } 59 + subid: (_|_){ 60 + // [cycle] #schema.#ID: invalid interpolation: cycle with field: prefix: 61 + // ./in.cue:8:12 62 + // ./in.cue:7:16 63 + } 64 + } 65 + case1: (#struct){ 66 + id: (string){ "foo" } 67 + subid: (string){ "foo:sub" } 68 + let splits#1 = (#list){ 69 + 0: (string){ "foo" } 70 + } 71 + let prefix#2 = (string){ "foo" } 72 + #ID: (string){ =~"^foo$" } 73 + #SubID: (string){ =~"^foo:sub$" } 74 + } 75 + case2: (_|_){ 76 + // [eval] 77 + subid: (_|_){ 78 + // [eval] case2.subid: invalid value "foo:sub" (out of bound =~"^:sub$"): 79 + // ./in.cue:8:10 80 + // ./in.cue:11:9 81 + // ./in.cue:20:9 82 + } 83 + id: (_|_){ 84 + // [cycle] case2.id: invalid interpolation: cycle with field: prefix: 85 + // ./in.cue:7:12 86 + // ./in.cue:7:16 87 + } 88 + let splits#1 = (_|_){ 89 + // [cycle] case2.id: invalid interpolation: cycle with field: prefix: 90 + // ./in.cue:7:12 91 + // ./in.cue:7:16 92 + } 93 + let prefix#2 = (_|_){ 94 + // [cycle] case2.id: cycle with field: prefix: 95 + // ./in.cue:7:16 96 + } 97 + #ID: (string){ =~"^$" } 98 + #SubID: (string){ =~"^:sub$" } 99 + } 100 + } 101 + -- out/compile -- 102 + --- in.cue 103 + { 104 + #schema: { 105 + let splits#1 = 〈import;strings〉.Split(〈0;id〉, "_never_") 106 + let prefix#2 = 〈0;let splits#1〉[0] 107 + #ID: =~"^\(〈0;let prefix#2〉)$" 108 + #SubID: =~"^\(〈0;let prefix#2〉):sub$" 109 + id: 〈0;#ID〉 110 + subid: 〈0;#SubID〉 111 + } 112 + case1: (〈0;#schema〉 & { 113 + id: "foo" 114 + subid: "foo:sub" 115 + }) 116 + case2: (〈0;#schema〉 & { 117 + subid: "foo:sub" 118 + id: "foo" 119 + }) 120 + }