Repository navigation
Expand file tree
/
Copy pathmacros.feature
More file actions
313 lines (181 loc) · 8.13 KB
/
Copy pathmacros.feature
File metadata and controls
313 lines (181 loc) · 8.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
Feature: macros
Tests for CEL macros.
# exists -- Tests for the .exists() macro, which is equivalent to joining the evaluated elements with logical-OR.
Scenario: list_elem_all_true
When CEL expression "[1, 2, 3].exists(e, e > 0)" is evaluated
# bool_value:true
Then value is BoolType(source=True)
Scenario: list_elem_some_true
When CEL expression "[1, 2, 3].exists(e, e == 2)" is evaluated
# bool_value:true
Then value is BoolType(source=True)
Scenario: list_elem_none_true
When CEL expression "[1, 2, 3].exists(e, e > 3)" is evaluated
# bool_value:false
Then value is BoolType(source=False)
Scenario: list_elem_type_shortcircuit
Exists filter is true for the last element, thus short-circuits after 'err || true'
When CEL expression "[1, 'foo', 3].exists(e, e != '1')" is evaluated
# bool_value:true
Then value is BoolType(source=True)
Scenario: list_elem_type_exhaustive
Exists filter is never true, thus reduces to 'err || false || err' which is an error
When CEL expression "[1, 'foo', 3].exists(e, e == '10')" is evaluated
# errors:{message:"no such overload"}
Then eval_error is 'no such overload'
Scenario: list_elem_all_error
When CEL expression "[1, 2, 3].exists(e, e / 0 == 17)" is evaluated
# errors:{message:"divide by zero"}
Then eval_error is 'divide by zero'
Scenario: list_empty
When CEL expression "[].exists(e, e == 2)" is evaluated
# bool_value:false
Then value is BoolType(source=False)
Scenario: map_key
When CEL expression "{'key1':1, 'key2':2}.exists(k, k == 'key2')" is evaluated
# bool_value:true
Then value is BoolType(source=True)
Scenario: not_map_key
When CEL expression "!{'key1':1, 'key2':2}.exists(k, k == 'key3')" is evaluated
# bool_value:true
Then value is BoolType(source=True)
Scenario: map_key_type_shortcircuit
Exists filter is true for the second key, thus reduces to 'err || true' which is true
When CEL expression "{'key':1, 1:21}.exists(k, k != 2)" is evaluated
# bool_value:true
Then value is BoolType(source=True)
Scenario: map_key_type_exhaustive
Exists filter is never true, thus reduces to 'err || false' which is an error
When CEL expression "!{'key':1, 1:42}.exists(k, k == 2)" is evaluated
# errors:{message:"no such overload"}
Then eval_error is 'no such overload'
# all -- Tests for the .all() macro, which is equivalent to joining the evaluated elements with logical-AND.
Scenario: list_elem_all_true
When CEL expression "[1, 2, 3].all(e, e > 0)" is evaluated
# bool_value:true
Then value is BoolType(source=True)
Scenario: list_elem_some_true
When CEL expression "[1, 2, 3].all(e, e == 2)" is evaluated
# bool_value:false
Then value is BoolType(source=False)
Scenario: list_elem_none_true
When CEL expression "[1, 2, 3].all(e, e == 17)" is evaluated
# bool_value:false
Then value is BoolType(source=False)
Scenario: list_elem_type_shortcircuit
When CEL expression "[1, 'foo', 3].all(e, e == 1)" is evaluated
# bool_value:false
Then value is BoolType(source=False)
Scenario: list_elem_type_exhaustive
When CEL expression "[1, 'foo', 3].all(e, e % 2 == 1)" is evaluated
# errors:{message:"no_such_overload"}
Then eval_error is 'no_such_overload'
Scenario: list_elem_error_shortcircuit
When CEL expression "[1, 2, 3].all(e, 6 / (2 - e) == 6)" is evaluated
# bool_value:false
Then value is BoolType(source=False)
Scenario: list_elem_error_exhaustive
When CEL expression "[1, 2, 3].all(e, e / 0 != 17)" is evaluated
# errors:{message:"divide by zero"}
Then eval_error is 'divide by zero'
Scenario: list_empty
When CEL expression "[].all(e, e > 0)" is evaluated
# bool_value:true
Then value is BoolType(source=True)
Scenario: map_key
When CEL expression "{'key1':1, 'key2':2}.all(k, k == 'key2')" is evaluated
# bool_value:false
Then value is BoolType(source=False)
# exists_one -- Tests for exists_one() macro. An expression 'L.exists_one(I, E)' is equivalent to 'size(L.filter(I, E)) == 1'.
Scenario: list_empty
When CEL expression "[].exists_one(a, a == 7)" is evaluated
# bool_value:false
Then value is BoolType(source=False)
Scenario: list_one_true
When CEL expression "[7].exists_one(a, a == 7)" is evaluated
# bool_value:true
Then value is BoolType(source=True)
Scenario: list_one_false
When CEL expression "[8].exists_one(a, a == 7)" is evaluated
# bool_value:false
Then value is BoolType(source=False)
Scenario: list_none
When CEL expression "[1, 2, 3].exists_one(x, x > 20)" is evaluated
# bool_value:false
Then value is BoolType(source=False)
Scenario: list_one
When CEL expression "[6, 7, 8].exists_one(foo, foo % 5 == 2)" is evaluated
# bool_value:true
Then value is BoolType(source=True)
Scenario: list_many
When CEL expression "[0, 1, 2, 3, 4].exists_one(n, n % 2 == 1)" is evaluated
# bool_value:false
Then value is BoolType(source=False)
Scenario: list_all
When CEL expression "['foal', 'foo', 'four'].exists_one(n, n.startsWith('fo'))" is evaluated
# bool_value:false
Then value is BoolType(source=False)
Scenario: list_no_shortcircuit
Errors invalidate everything, even if already false.
When CEL expression "[3, 2, 1, 0].exists_one(n, 12 / n > 1)" is evaluated
# errors:{message:"divide by zero"}
Then eval_error is 'divide by zero'
Scenario: map_one
When CEL expression "{6: 'six', 7: 'seven', 8: 'eight'}.exists_one(foo, foo % 5 == 2)" is evaluated
# bool_value:true
Then value is BoolType(source=True)
# map -- Tests for map() macro.
Scenario: list_empty
When CEL expression "[].map(n, n / 2)" is evaluated
# list_value:{}
Then value is []
Scenario: list_one
When CEL expression "[3].map(n, n * n)" is evaluated
# list_value:{values:{int64_value:9}}
Then value is [IntType(source=9)]
Scenario: list_many
When CEL expression "[2, 4, 6].map(n, n / 2)" is evaluated
# list_value:{values:{int64_value:1} values:{int64_value:2} values:{int64_value:3}}
Then value is [IntType(source=1), IntType(source=2), IntType(source=3)]
Scenario: list_error
When CEL expression "[2, 1, 0].map(n, 4 / n)" is evaluated
# errors:{message:"divide by zero"}
Then eval_error is 'divide by zero'
# filter -- Tests for filter() macro.
Scenario: list_empty
When CEL expression "[].filter(n, n % 2 == 0)" is evaluated
# list_value:{}
Then value is []
Scenario: list_one_true
When CEL expression "[2].filter(n, n == 2)" is evaluated
# list_value:{values:{int64_value:2}}
Then value is [IntType(source=2)]
Scenario: list_one_false
When CEL expression "[1].filter(n, n > 3)" is evaluated
# list_value:{}
Then value is []
Scenario: list_none
When CEL expression "[1, 2, 3].filter(e, e > 3)" is evaluated
# list_value:{}
Then value is []
Scenario: list_some
When CEL expression "[0, 1, 2, 3, 4].filter(x, x % 2 == 1)" is evaluated
# list_value:{values:{int64_value:1} values:{int64_value:3}}
Then value is [IntType(source=1), IntType(source=3)]
Scenario: list_all
When CEL expression "[1, 2, 3].filter(n, n > 0)" is evaluated
# list_value:{values:{int64_value:1} values:{int64_value:2} values:{int64_value:3}}
Then value is [IntType(source=1), IntType(source=2), IntType(source=3)]
Scenario: list_no_shortcircuit
When CEL expression "[3, 2, 1, 0].filter(n, 12 / n > 4)" is evaluated
# errors:{message:"divide by zero"}
Then eval_error is 'divide by zero'
# nested -- Tests with nested macros.
Scenario: filter_all
When CEL expression "['signer'].filter(signer, ['artifact'].all(artifact, true))" is evaluated
# list_value:{values:{string_value:"signer"}}
Then value is [StringType(source='signer')]
Scenario: all_all
When CEL expression "['signer'].all(signer, ['artifact'].all(artifact, true))" is evaluated
# bool_value:true
Then value is BoolType(source=True)