Skip to content

Commit 0ba5f75

Browse files
maskri17copybara-github
authored andcommitted
Checker and parser changes to support two variable comprehensions for remaining Macros
PiperOrigin-RevId: 797505479
1 parent 37828da commit 0ba5f75

4 files changed

Lines changed: 615 additions & 115 deletions

File tree

checker/src/test/java/dev/cel/checker/ExprCheckerTest.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,12 @@ public void twoVarComprehensions() throws Exception {
800800
"x.map_string_string.all(i, v, i < v) "
801801
+ "&& x.repeated_int64.all(i, v, i < v) "
802802
+ "&& [1, 2, 3, 4].all(i, v, i < 5 && v > 0) "
803-
+ "&& {'a': 1, 'b': 2}.all(k, v, k.startsWith('a') && v == 1)";
803+
+ "&& {'a': 1, 'b': 2}.all(k, v, k.startsWith('a') && v == 1) "
804+
+ "&& x.map_string_string.exists(i, v, i < v) "
805+
+ "&& [-1,2,3].exists_one(i,v,i>v) "
806+
+ "&& [1, 2, 3].transformList(i, v, i > 0 && v < 3, (i * v) + v) == [4] "
807+
+ "&& [1, 2, 3].transformList(i, v, i % 2 == 0, (i * v) + v) == [1,9] "
808+
+ "&& [1, 2, 3].transformList(i, v, (i * v) + v) == [1,4,9]";
804809
runTest();
805810
}
806811

@@ -812,6 +817,18 @@ public void twoVarComprehensionsErrors() throws Exception {
812817
runTest();
813818
}
814819

820+
@Test
821+
public void twoVarCompreIncorrectArgsErrors() throws Exception {
822+
CelType messageType = StructTypeReference.create("cel.expr.conformance.proto3.TestAllTypes");
823+
declareVariable("x", messageType);
824+
source =
825+
"x.repeated_int64.exists(i, i, i < v) "
826+
+ "&& [1, 2, 3, 4].exists(i, v, i < v, v) "
827+
+ "&& x.map_string_string.exists_one(i, i < v) "
828+
+ "&& [1, 2, 3].transformList(i, v, i > 0 && x < 3, (i * v) + v) == [4]";
829+
runTest();
830+
}
831+
815832
@Test
816833
public void quantifiersErrors() throws Exception {
817834
CelType messageType = StructTypeReference.create("cel.expr.conformance.proto3.TestAllTypes");
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Source: x.repeated_int64.exists(i, i, i < v) && [1, 2, 3, 4].exists(i, v, i < v, v) && x.map_string_string.exists_one(i, i < v) && [1, 2, 3].transformList(i, v, i > 0 && x < 3, (i * v) + v) == [4]
2+
declare x {
3+
value cel.expr.conformance.proto3.TestAllTypes
4+
}
5+
=====>
6+
ERROR: test_location:1:1: overlapping declaration name 'i' (type 'int' cannot be distinguished from 'int')
7+
| x.repeated_int64.exists(i, i, i < v) && [1, 2, 3, 4].exists(i, v, i < v, v) && x.map_string_string.exists_one(i, i < v) && [1, 2, 3].transformList(i, v, i > 0 && x < 3, (i * v) + v) == [4]
8+
| ^
9+
ERROR: test_location:1:35: undeclared reference to 'v' (in container '')
10+
| x.repeated_int64.exists(i, i, i < v) && [1, 2, 3, 4].exists(i, v, i < v, v) && x.map_string_string.exists_one(i, i < v) && [1, 2, 3].transformList(i, v, i > 0 && x < 3, (i * v) + v) == [4]
11+
| ..................................^
12+
ERROR: test_location:1:60: undeclared reference to 'exists' (in container '')
13+
| x.repeated_int64.exists(i, i, i < v) && [1, 2, 3, 4].exists(i, v, i < v, v) && x.map_string_string.exists_one(i, i < v) && [1, 2, 3].transformList(i, v, i > 0 && x < 3, (i * v) + v) == [4]
14+
| ...........................................................^
15+
ERROR: test_location:1:61: undeclared reference to 'i' (in container '')
16+
| x.repeated_int64.exists(i, i, i < v) && [1, 2, 3, 4].exists(i, v, i < v, v) && x.map_string_string.exists_one(i, i < v) && [1, 2, 3].transformList(i, v, i > 0 && x < 3, (i * v) + v) == [4]
17+
| ............................................................^
18+
ERROR: test_location:1:64: undeclared reference to 'v' (in container '')
19+
| x.repeated_int64.exists(i, i, i < v) && [1, 2, 3, 4].exists(i, v, i < v, v) && x.map_string_string.exists_one(i, i < v) && [1, 2, 3].transformList(i, v, i > 0 && x < 3, (i * v) + v) == [4]
20+
| ...............................................................^
21+
ERROR: test_location:1:67: undeclared reference to 'i' (in container '')
22+
| x.repeated_int64.exists(i, i, i < v) && [1, 2, 3, 4].exists(i, v, i < v, v) && x.map_string_string.exists_one(i, i < v) && [1, 2, 3].transformList(i, v, i > 0 && x < 3, (i * v) + v) == [4]
23+
| ..................................................................^
24+
ERROR: test_location:1:71: undeclared reference to 'v' (in container '')
25+
| x.repeated_int64.exists(i, i, i < v) && [1, 2, 3, 4].exists(i, v, i < v, v) && x.map_string_string.exists_one(i, i < v) && [1, 2, 3].transformList(i, v, i > 0 && x < 3, (i * v) + v) == [4]
26+
| ......................................................................^
27+
ERROR: test_location:1:74: undeclared reference to 'v' (in container '')
28+
| x.repeated_int64.exists(i, i, i < v) && [1, 2, 3, 4].exists(i, v, i < v, v) && x.map_string_string.exists_one(i, i < v) && [1, 2, 3].transformList(i, v, i > 0 && x < 3, (i * v) + v) == [4]
29+
| .........................................................................^
30+
ERROR: test_location:1:118: undeclared reference to 'v' (in container '')
31+
| x.repeated_int64.exists(i, i, i < v) && [1, 2, 3, 4].exists(i, v, i < v, v) && x.map_string_string.exists_one(i, i < v) && [1, 2, 3].transformList(i, v, i > 0 && x < 3, (i * v) + v) == [4]
32+
| .....................................................................................................................^
33+
ERROR: test_location:1:165: found no matching overload for '_<_' applied to '(cel.expr.conformance.proto3.TestAllTypes, int)' (candidates: (bool, bool),(int, int),(uint, uint),(double, double),(string, string),(bytes, bytes),(google.protobuf.Timestamp, google.protobuf.Timestamp),(google.protobuf.Duration, google.protobuf.Duration),(int, uint),(uint, int),(int, double),(double, int),(uint, double),(double, uint))
34+
| x.repeated_int64.exists(i, i, i < v) && [1, 2, 3, 4].exists(i, v, i < v, v) && x.map_string_string.exists_one(i, i < v) && [1, 2, 3].transformList(i, v, i > 0 && x < 3, (i * v) + v) == [4]
35+
| ....................................................................................................................................................................^

0 commit comments

Comments
 (0)