github.com/solo-io/cue@v0.4.7/cue/testdata/resolve/016_index.txtar (about) 1 # DO NOT EDIT; generated by go run testdata/gen.go 2 # 3 #name: index 4 #evalPartial 5 -- in.cue -- 6 a: [2][0] 7 b: {foo: "bar"}["foo"] 8 c: (*l | {"3": 3})["3"] 9 d: (*[] | [1])[0] 10 l: [] 11 e1: [2][""] 12 e2: 2[2] 13 e3: [][true] 14 e4: [1, 2, 3][3] 15 e5: [1, 2, 3][-1] 16 e6: (*[] | {})[1] 17 e7: [1, 2, 3][3] 18 e8: [1, 2, 3][-1] 19 e9: (*[] | {})[1] 20 21 def: { 22 a: 1 23 #b: 3 24 } 25 e7: def["b"] 26 -- out/def -- 27 a: 2 28 b: "bar" 29 c: _|_ // invalid list index "3" (type string) 30 l: [] 31 d: _|_ // index 0 out of bounds 32 e1: _|_ // invalid list index "" (type string) 33 e2: _|_ // invalid operation: 2[2] (type int does not support indexing) 34 e3: _|_ // invalid list index true (type bool) 35 e4: _|_ // index 3 out of bounds 36 e5: _|_ // invalid list index -1 (index must be non-negative) 37 e6: _|_ // index 1 out of bounds 38 def: { 39 a: 1 40 #b: 3 41 } 42 e7: def["b"] 43 -- out/legacy-debug -- 44 <0>{a: 2, b: "bar", c: _|_("3":invalid list index "3" (type string)), l: [], d: _|_([]:index 0 out of bounds), e1: _|_("":invalid list index "" (type string)), e2: _|_(2:invalid operation: 2[2] (type int does not support indexing)), e3: _|_(true:invalid list index true (type bool)), e4: _|_([1,2,3]:index 3 out of bounds), e5: _|_(-1:invalid list index -1 (index must be non-negative)), e6: _|_([]:index 1 out of bounds), def: <1>{a: 1, #b: 3}, e7: <2>.def["b"]} 45 -- out/compile -- 46 --- in.cue 47 { 48 a: [ 49 2, 50 ][0] 51 b: { 52 foo: "bar" 53 }["foo"] 54 c: (*〈0;l〉|{ 55 "3": 3 56 })["3"] 57 d: (*[]|[ 58 1, 59 ])[0] 60 l: [] 61 e1: [ 62 2, 63 ][""] 64 e2: 2[2] 65 e3: [][true] 66 e4: [ 67 1, 68 2, 69 3, 70 ][3] 71 e5: [ 72 1, 73 2, 74 3, 75 ][-1] 76 e6: (*[]|{})[1] 77 e7: [ 78 1, 79 2, 80 3, 81 ][3] 82 e8: [ 83 1, 84 2, 85 3, 86 ][-1] 87 e9: (*[]|{})[1] 88 def: { 89 a: 1 90 #b: 3 91 } 92 e7: 〈0;def〉["b"] 93 } 94 -- out/eval -- 95 Errors: 96 c: invalid list index "3" (type string): 97 ./in.cue:3:20 98 d: index out of range [0] with length 0: 99 ./in.cue:4:16 100 e1: invalid list index "" (type string): 101 ./in.cue:6:9 102 e2: invalid operand 2 (found int, want list or struct): 103 ./in.cue:7:5 104 e3: invalid index true (invalid type bool): 105 ./in.cue:8:5 106 ./in.cue:8:8 107 e4: index out of range [3] with length 3: 108 ./in.cue:9:15 109 e5: invalid index -1 (index must be non-negative): 110 ./in.cue:10:5 111 ./in.cue:10:15 112 e6: invalid list index 1 (out of bounds): 113 ./in.cue:11:16 114 e7: index out of range [3] with length 3: 115 ./in.cue:12:15 116 e8: invalid index -1 (index must be non-negative): 117 ./in.cue:13:5 118 ./in.cue:13:15 119 e9: invalid list index 1 (out of bounds): 120 ./in.cue:14:16 121 122 Result: 123 (_|_){ 124 // [eval] 125 a: (int){ 2 } 126 b: (string){ "bar" } 127 c: (_|_){ 128 // [eval] c: invalid list index "3" (type string): 129 // ./in.cue:3:20 130 } 131 d: (_|_){ 132 // [eval] d: index out of range [0] with length 0: 133 // ./in.cue:4:16 134 } 135 l: (#list){ 136 } 137 e1: (_|_){ 138 // [eval] e1: invalid list index "" (type string): 139 // ./in.cue:6:9 140 } 141 e2: (_|_){ 142 // [eval] e2: invalid operand 2 (found int, want list or struct): 143 // ./in.cue:7:5 144 } 145 e3: (_|_){ 146 // [eval] e3: invalid index true (invalid type bool): 147 // ./in.cue:8:5 148 // ./in.cue:8:8 149 } 150 e4: (_|_){ 151 // [eval] e4: index out of range [3] with length 3: 152 // ./in.cue:9:15 153 } 154 e5: (_|_){ 155 // [eval] e5: invalid index -1 (index must be non-negative): 156 // ./in.cue:10:5 157 // ./in.cue:10:15 158 } 159 e6: (_|_){ 160 // [eval] e6: invalid list index 1 (out of bounds): 161 // ./in.cue:11:16 162 } 163 e7: (_|_){ 164 // [eval] e7: index out of range [3] with length 3: 165 // ./in.cue:12:15 166 } 167 e8: (_|_){ 168 // [eval] e8: invalid index -1 (index must be non-negative): 169 // ./in.cue:13:5 170 // ./in.cue:13:15 171 } 172 e9: (_|_){ 173 // [eval] e9: invalid list index 1 (out of bounds): 174 // ./in.cue:14:16 175 } 176 def: (struct){ 177 a: (int){ 1 } 178 #b: (int){ 3 } 179 } 180 }