github.com/solo-io/cue@v0.4.7/cue/testdata/scalars/embed.txtar (about) 1 // Issue ##739 2 3 -- in.cue -- 4 import "strings" 5 6 intEmbed: { 7 a1: { 8 2 9 } 10 a2: { 11 v: { 12 3 13 #foo: a2.v + 1 14 } 15 w: v 16 x: v.#foo 17 } 18 a3: a1 + a2.v 19 } 20 21 listEmbed: { 22 a1: { 23 2 24 } 25 b3: { 26 [1, 2] 27 #foo: 1 28 } 29 b4: b3 + b3 30 b5: b3[1] 31 b6: b3[5] 32 b7: b4[a1] // 1 33 } 34 35 stringEmbed: { 36 s1: { 37 "foo" 38 #bar: "bar" 39 } 40 s2: [ s1, { s1.#bar, #baz: 4 } ] 41 s3: strings.Join(s2, "--") 42 } 43 44 45 outPattern: { 46 sum: { 47 out: #a + #b 48 #a: int 49 #b: int 50 } 51 used: sum&{#a: 1, #b: 3} 52 } 53 54 arithmetic: { 55 sum: { 56 #a + #b 57 #a: int 58 #b: int 59 } 60 a1: (sum&{_, #a: 1, #b: 3}) + 2 61 a2: 2 + (sum&{_, #a: 1, #b: 3}) 62 a3: 2 + (2 + (sum&{_, #a: 1, #b: 3})) 63 } 64 65 defCheck: { 66 a: { 67 #def: 1 68 } 69 b: a.#def 70 } 71 72 optionalExists: { 73 string | { 74 value?: string 75 76 if value != _|_ { 77 other: int 78 } 79 } 80 } 81 82 optionalCheck: { 83 thing: string | { 84 value?: string 85 86 if value != _|_ { 87 other: int 88 } 89 } 90 91 thing: { 92 value: "some string" 93 other: 3 94 } 95 } 96 97 hidden: { 98 issue794: { 99 _foo: "foo" 100 [_foo] 101 } 102 } 103 -- out/eval -- 104 Errors: 105 listEmbed.b6: invalid list index 5 (out of bounds): 106 ./in.cue:28:12 107 108 Result: 109 (_|_){ 110 // [eval] 111 intEmbed: (struct){ 112 a1: (int){ 2 } 113 a2: (struct){ 114 v: (int){ 115 3 116 #foo: (int){ 4 } 117 } 118 w: (int){ 119 3 120 #foo: (int){ 4 } 121 } 122 x: (int){ 4 } 123 } 124 a3: (int){ 5 } 125 } 126 listEmbed: (_|_){ 127 // [eval] 128 a1: (int){ 2 } 129 b3: (#list){ 130 #foo: (int){ 1 } 131 0: (int){ 1 } 132 1: (int){ 2 } 133 } 134 b4: (#list){ 135 0: (int){ 1 } 136 1: (int){ 2 } 137 2: (int){ 1 } 138 3: (int){ 2 } 139 } 140 b5: (int){ 2 } 141 b6: (_|_){ 142 // [eval] listEmbed.b6: invalid list index 5 (out of bounds): 143 // ./in.cue:28:12 144 } 145 b7: (int){ 1 } 146 } 147 stringEmbed: (struct){ 148 s1: (string){ 149 "foo" 150 #bar: (string){ "bar" } 151 } 152 s2: (#list){ 153 0: (string){ 154 "foo" 155 #bar: (string){ "bar" } 156 } 157 1: (string){ 158 "bar" 159 #baz: (int){ 4 } 160 } 161 } 162 s3: (string){ "foo--bar" } 163 } 164 outPattern: (struct){ 165 sum: (struct){ 166 out: (_|_){ 167 // [incomplete] outPattern.sum.out: non-concrete value int in operand to +: 168 // ./in.cue:44:14 169 // ./in.cue:45:9 170 } 171 #a: (int){ int } 172 #b: (int){ int } 173 } 174 used: (struct){ 175 out: (int){ 4 } 176 #a: (int){ 1 } 177 #b: (int){ 3 } 178 } 179 } 180 arithmetic: (struct){ 181 sum: (_|_){ 182 // [incomplete] arithmetic.sum: non-concrete value int in operand to +: 183 // ./in.cue:53:9 184 // ./in.cue:54:9 185 #a: (int){ int } 186 #b: (int){ int } 187 } 188 a1: (int){ 6 } 189 a2: (int){ 6 } 190 a3: (int){ 8 } 191 } 192 defCheck: (struct){ 193 a: (struct){ 194 #def: (int){ 1 } 195 } 196 b: (int){ 1 } 197 } 198 optionalExists: ((string|struct)){ |((string){ string }, (struct){ 199 }) } 200 optionalCheck: (struct){ 201 thing: (struct){ 202 value: (string){ "some string" } 203 other: (int){ 3 } 204 } 205 } 206 hidden: (struct){ 207 issue794: (#list){ 208 _foo: (string){ "foo" } 209 0: (string){ "foo" } 210 } 211 } 212 } 213 -- out/compile -- 214 --- in.cue 215 { 216 intEmbed: { 217 a1: { 218 2 219 } 220 a2: { 221 v: { 222 3 223 #foo: (〈2;a2〉.v + 1) 224 } 225 w: 〈0;v〉 226 x: 〈0;v〉.#foo 227 } 228 a3: (〈0;a1〉 + 〈0;a2〉.v) 229 } 230 listEmbed: { 231 a1: { 232 2 233 } 234 b3: { 235 [ 236 1, 237 2, 238 ] 239 #foo: 1 240 } 241 b4: (〈0;b3〉 + 〈0;b3〉) 242 b5: 〈0;b3〉[1] 243 b6: 〈0;b3〉[5] 244 b7: 〈0;b4〉[〈0;a1〉] 245 } 246 stringEmbed: { 247 s1: { 248 "foo" 249 #bar: "bar" 250 } 251 s2: [ 252 〈0;s1〉, 253 { 254 〈1;s1〉.#bar 255 #baz: 4 256 }, 257 ] 258 s3: 〈import;strings〉.Join(〈0;s2〉, "--") 259 } 260 outPattern: { 261 sum: { 262 out: (〈0;#a〉 + 〈0;#b〉) 263 #a: int 264 #b: int 265 } 266 used: (〈0;sum〉 & { 267 #a: 1 268 #b: 3 269 }) 270 } 271 arithmetic: { 272 sum: { 273 (〈0;#a〉 + 〈0;#b〉) 274 #a: int 275 #b: int 276 } 277 a1: ((〈0;sum〉 & { 278 _ 279 #a: 1 280 #b: 3 281 }) + 2) 282 a2: (2 + (〈0;sum〉 & { 283 _ 284 #a: 1 285 #b: 3 286 })) 287 a3: (2 + (2 + (〈0;sum〉 & { 288 _ 289 #a: 1 290 #b: 3 291 }))) 292 } 293 defCheck: { 294 a: { 295 #def: 1 296 } 297 b: 〈0;a〉.#def 298 } 299 optionalExists: { 300 (string|{ 301 value?: string 302 if (〈0;value〉 != _|_(explicit error (_|_ literal) in source)) { 303 other: int 304 } 305 }) 306 } 307 optionalCheck: { 308 thing: (string|{ 309 value?: string 310 if (〈0;value〉 != _|_(explicit error (_|_ literal) in source)) { 311 other: int 312 } 313 }) 314 thing: { 315 value: "some string" 316 other: 3 317 } 318 } 319 hidden: { 320 issue794: { 321 _foo: "foo" 322 [ 323 〈0;_foo〉, 324 ] 325 } 326 } 327 }