Debian Codegraph @

tests/snippets/rego/test_lookup.txt

raw
1 ---input---
2 package example
3
4 # Rego Policy References: https://www.openpolicyagent.org/docs/latest/policy-reference/
5
6 ### Arrays
7
8 # lookup value at index 0
9 val := arr[0]
10
11 # check if value at index 0 is "foo"
12 "foo" == arr[0]
13
14 # find all indices i that have value "foo"
15 "foo" == arr[i]
16
17 # lookup last value
18 val := arr[count(arr)-1]
19
20 # with `import rego.v1` or `import future.keywords.in`
21 some 0, val in arr # lookup value at index 0
22 0, "foo" in arr # check if value at index 0 is "foo"
23 some i, "foo" in arr # find all indices i that have value "foo"
24
25 ### Objects
26
27 # lookup value for key "foo"
28 val := obj["foo"]
29
30 # check if value for key "foo" is "bar"
31 "bar" == obj["foo"]
32
33 # OR
34
35 "bar" == obj.foo
36
37 # check if key "foo" exists and is not false
38 obj.foo
39
40 # check if key assigned to variable k exists
41 k := "foo"
42 obj[k]
43
44 # check if path foo.bar.baz exists and is not false
45 obj.foo.bar.baz
46
47 # check if path foo.bar.baz, foo.bar, or foo does not exist or is false
48 not obj.foo.bar.baz
49
50 # with `import rego.v1` or `import future.keywords.in`
51 o := {"foo": false}
52 # check if value exists: the expression will be true
53 false in o
54 # check if value for key "foo" is false
55 "foo", false in o
56
57 ### Sets
58
59 # check if "foo" belongs to the set
60 a_set["foo"]
61
62 # check if "foo" DOES NOT belong to the set
63 not a_set["foo"]
64
65 # check if the array ["a", "b", "c"] belongs to the set
66 a_set[["a", "b", "c"]]
67
68 # find all arrays of the form [x, "b", z] in the set
69 a_set[[x, "b", z]]
70
71 # with `import rego.v1` or `import future.keywords.in`
72 "foo" in a_set
73 not "foo" in a_set
74 some ["a", "b", "c"] in a_set
75 some [x, "b", z] in a_set
76
77 ---tokens---
78 'package' Keyword
79 ' ' Text.Whitespace
80 'example' Name
81 '\n' Text.Whitespace
82
83 '\n' Text.Whitespace
84
85 '# Rego Policy References: https://www.openpolicyagent.org/docs/latest/policy-reference/' Comment.Single
86 '\n' Text.Whitespace
87
88 '\n' Text.Whitespace
89
90 '### Arrays' Comment.Single
91 '\n' Text.Whitespace
92
93 '\n' Text.Whitespace
94
95 '# lookup value at index 0' Comment.Single
96 '\n' Text.Whitespace
97
98 'val' Name
99 ' ' Text.Whitespace
100 ':=' Operator
101 ' ' Text.Whitespace
102 'arr' Name
103 '[' Punctuation
104 '0' Literal.Number
105 ']' Punctuation
106 '\n' Text.Whitespace
107
108 '\n' Text.Whitespace
109
110 ' ' Text.Whitespace
111 '# check if value at index 0 is "foo"' Comment.Single
112 '\n' Text.Whitespace
113
114 '"foo"' Literal.String.Double
115 ' ' Text.Whitespace
116 '==' Operator
117 ' ' Text.Whitespace
118 'arr' Name
119 '[' Punctuation
120 '0' Literal.Number
121 ']' Punctuation
122 '\n' Text.Whitespace
123
124 '\n' Text.Whitespace
125
126 '# find all indices i that have value "foo"' Comment.Single
127 '\n' Text.Whitespace
128
129 '"foo"' Literal.String.Double
130 ' ' Text.Whitespace
131 '==' Operator
132 ' ' Text.Whitespace
133 'arr' Name
134 '[' Punctuation
135 'i' Name
136 ']' Punctuation
137 '\n' Text.Whitespace
138
139 '\n' Text.Whitespace
140
141 '# lookup last value' Comment.Single
142 '\n' Text.Whitespace
143
144 'val' Name
145 ' ' Text.Whitespace
146 ':=' Operator
147 ' ' Text.Whitespace
148 'arr' Name
149 '[' Punctuation
150 'count' Name
151 '(' Punctuation
152 'arr' Name
153 ')' Punctuation
154 '-1' Literal.Number
155 ']' Punctuation
156 '\n' Text.Whitespace
157
158 '\n' Text.Whitespace
159
160 '# with `import rego.v1` or `import future.keywords.in`' Comment.Single
161 '\n' Text.Whitespace
162
163 'some' Keyword
164 ' ' Text.Whitespace
165 '0' Literal.Number
166 ',' Punctuation
167 ' ' Text.Whitespace
168 'val' Name
169 ' ' Text.Whitespace
170 'in' Keyword
171 ' ' Text.Whitespace
172 'arr' Name
173 ' ' Text.Whitespace
174 '# lookup value at index 0' Comment.Single
175 '\n' Text.Whitespace
176
177 '0' Literal.Number
178 ',' Punctuation
179 ' ' Text.Whitespace
180 '"foo"' Literal.String.Double
181 ' ' Text.Whitespace
182 'in' Keyword
183 ' ' Text.Whitespace
184 'arr' Name
185 ' ' Text.Whitespace
186 '# check if value at index 0 is "foo"' Comment.Single
187 '\n' Text.Whitespace
188
189 'some' Keyword
190 ' ' Text.Whitespace
191 'i' Name
192 ',' Punctuation
193 ' ' Text.Whitespace
194 '"foo"' Literal.String.Double
195 ' ' Text.Whitespace
196 'in' Keyword
197 ' ' Text.Whitespace
198 'arr' Name
199 ' ' Text.Whitespace
200 '# find all indices i that have value "foo"' Comment.Single
201 '\n' Text.Whitespace
202
203 '\n' Text.Whitespace
204
205 '### Objects' Comment.Single
206 '\n' Text.Whitespace
207
208 '\n' Text.Whitespace
209
210 '# lookup value for key "foo"' Comment.Single
211 '\n' Text.Whitespace
212
213 'val' Name
214 ' ' Text.Whitespace
215 ':=' Operator
216 ' ' Text.Whitespace
217 'obj' Name
218 '[' Punctuation
219 '"foo"' Literal.String.Double
220 ']' Punctuation
221 '\n' Text.Whitespace
222
223 '\n' Text.Whitespace
224
225 '# check if value for key "foo" is "bar"' Comment.Single
226 '\n' Text.Whitespace
227
228 '"bar"' Literal.String.Double
229 ' ' Text.Whitespace
230 '==' Operator
231 ' ' Text.Whitespace
232 'obj' Name
233 '[' Punctuation
234 '"foo"' Literal.String.Double
235 ']' Punctuation
236 '\n' Text.Whitespace
237
238 '\n' Text.Whitespace
239
240 '# OR' Comment.Single
241 '\n' Text.Whitespace
242
243 '\n' Text.Whitespace
244
245 '"bar"' Literal.String.Double
246 ' ' Text.Whitespace
247 '==' Operator
248 ' ' Text.Whitespace
249 'obj' Name
250 '.' Punctuation
251 'foo' Name
252 '\n' Text.Whitespace
253
254 '\n' Text.Whitespace
255
256 '# check if key "foo" exists and is not false' Comment.Single
257 '\n' Text.Whitespace
258
259 'obj' Name
260 '.' Punctuation
261 'foo' Name
262 '\n' Text.Whitespace
263
264 '\n' Text.Whitespace
265
266 '# check if key assigned to variable k exists' Comment.Single
267 '\n' Text.Whitespace
268
269 'k' Name
270 ' ' Text.Whitespace
271 ':=' Operator
272 ' ' Text.Whitespace
273 '"foo"' Literal.String.Double
274 '\n' Text.Whitespace
275
276 'obj' Name
277 '[' Punctuation
278 'k' Name
279 ']' Punctuation
280 '\n' Text.Whitespace
281
282 '\n' Text.Whitespace
283
284 '# check if path foo.bar.baz exists and is not false' Comment.Single
285 '\n' Text.Whitespace
286
287 'obj' Name
288 '.' Punctuation
289 'foo' Name
290 '.' Punctuation
291 'bar' Name
292 '.' Punctuation
293 'baz' Name
294 '\n' Text.Whitespace
295
296 '\n' Text.Whitespace
297
298 '# check if path foo.bar.baz, foo.bar, or foo does not exist or is false' Comment.Single
299 '\n' Text.Whitespace
300
301 'not' Keyword
302 ' ' Text.Whitespace
303 'obj' Name
304 '.' Punctuation
305 'foo' Name
306 '.' Punctuation
307 'bar' Name
308 '.' Punctuation
309 'baz' Name
310 '\n' Text.Whitespace
311
312 '\n' Text.Whitespace
313
314 '# with `import rego.v1` or `import future.keywords.in`' Comment.Single
315 '\n' Text.Whitespace
316
317 'o' Name
318 ' ' Text.Whitespace
319 ':=' Operator
320 ' ' Text.Whitespace
321 '{' Punctuation
322 '"foo"' Literal.String.Double
323 ':' Punctuation
324 ' ' Text.Whitespace
325 'false' Keyword
326 '}' Punctuation
327 '\n' Text.Whitespace
328
329 '# check if value exists: the expression will be true' Comment.Single
330 '\n' Text.Whitespace
331
332 'false' Keyword
333 ' ' Text.Whitespace
334 'in' Keyword
335 ' ' Text.Whitespace
336 'o' Name
337 '\n' Text.Whitespace
338
339 '# check if value for key "foo" is false' Comment.Single
340 '\n' Text.Whitespace
341
342 '"foo"' Literal.String.Double
343 ',' Punctuation
344 ' ' Text.Whitespace
345 'false' Keyword
346 ' ' Text.Whitespace
347 'in' Keyword
348 ' ' Text.Whitespace
349 'o' Name
350 '\n' Text.Whitespace
351
352 '\n' Text.Whitespace
353
354 '### Sets' Comment.Single
355 '\n' Text.Whitespace
356
357 '\n' Text.Whitespace
358
359 '# check if "foo" belongs to the set' Comment.Single
360 '\n' Text.Whitespace
361
362 'a_set' Name
363 '[' Punctuation
364 '"foo"' Literal.String.Double
365 ']' Punctuation
366 '\n' Text.Whitespace
367
368 '\n' Text.Whitespace
369
370 '# check if "foo" DOES NOT belong to the set' Comment.Single
371 '\n' Text.Whitespace
372
373 'not' Keyword
374 ' ' Text.Whitespace
375 'a_set' Name
376 '[' Punctuation
377 '"foo"' Literal.String.Double
378 ']' Punctuation
379 '\n' Text.Whitespace
380
381 '\n' Text.Whitespace
382
383 '# check if the array ["a", "b", "c"] belongs to the set' Comment.Single
384 '\n' Text.Whitespace
385
386 'a_set' Name
387 '[' Punctuation
388 '[' Punctuation
389 '"a"' Literal.String.Double
390 ',' Punctuation
391 ' ' Text.Whitespace
392 '"b"' Literal.String.Double
393 ',' Punctuation
394 ' ' Text.Whitespace
395 '"c"' Literal.String.Double
396 ']' Punctuation
397 ']' Punctuation
398 '\n' Text.Whitespace
399
400 '\n' Text.Whitespace
401
402 '# find all arrays of the form [x, "b", z] in the set' Comment.Single
403 '\n' Text.Whitespace
404
405 'a_set' Name
406 '[' Punctuation
407 '[' Punctuation
408 'x' Name
409 ',' Punctuation
410 ' ' Text.Whitespace
411 '"b"' Literal.String.Double
412 ',' Punctuation
413 ' ' Text.Whitespace
414 'z' Name
415 ']' Punctuation
416 ']' Punctuation
417 '\n' Text.Whitespace
418
419 '\n' Text.Whitespace
420
421 '# with `import rego.v1` or `import future.keywords.in`' Comment.Single
422 '\n' Text.Whitespace
423
424 '"foo"' Literal.String.Double
425 ' ' Text.Whitespace
426 'in' Keyword
427 ' ' Text.Whitespace
428 'a_set' Name
429 '\n' Text.Whitespace
430
431 'not' Keyword
432 ' ' Text.Whitespace
433 '"foo"' Literal.String.Double
434 ' ' Text.Whitespace
435 'in' Keyword
436 ' ' Text.Whitespace
437 'a_set' Name
438 '\n' Text.Whitespace
439
440 'some' Keyword
441 ' ' Text.Whitespace
442 '[' Punctuation
443 '"a"' Literal.String.Double
444 ',' Punctuation
445 ' ' Text.Whitespace
446 '"b"' Literal.String.Double
447 ',' Punctuation
448 ' ' Text.Whitespace
449 '"c"' Literal.String.Double
450 ']' Punctuation
451 ' ' Text.Whitespace
452 'in' Keyword
453 ' ' Text.Whitespace
454 'a_set' Name
455 '\n' Text.Whitespace
456
457 'some' Keyword
458 ' ' Text.Whitespace
459 '[' Punctuation
460 'x' Name
461 ',' Punctuation
462 ' ' Text.Whitespace
463 '"b"' Literal.String.Double
464 ',' Punctuation
465 ' ' Text.Whitespace
466 'z' Name
467 ']' Punctuation
468 ' ' Text.Whitespace
469 'in' Keyword
470 ' ' Text.Whitespace
471 'a_set' Name
472 '\n' Text.Whitespace