Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 57 additions & 2 deletions 59 checker/src/test/java/dev/cel/checker/ExprCheckerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ public void quantifiers() throws Exception {
}

@Test
public void twoVarComprehensions() throws Exception {
public void twoVarComprehensions_allMacro() throws Exception {
CelType messageType = StructTypeReference.create("cel.expr.conformance.proto3.TestAllTypes");
declareVariable("x", messageType);
source =
Expand All @@ -805,13 +805,68 @@ public void twoVarComprehensions() throws Exception {
}

@Test
public void twoVarComprehensionsErrors() throws Exception {
public void twoVarComprehensions_existsMacro() throws Exception {
CelType messageType = StructTypeReference.create("cel.expr.conformance.proto3.TestAllTypes");
declareVariable("x", messageType);
source =
"x.map_string_string.exists(i, v, i < v) "
+ "&& x.repeated_int64.exists(i, v, i < v) "
+ "&& [1, 2, 3, 4].exists(i, v, i < 5 && v > 0) "
+ "&& {'a': 1, 'b': 2}.exists(k, v, k.startsWith('a') && v == 1)";
runTest();
}

@Test
public void twoVarComprehensions_existsOneMacro() throws Exception {
CelType messageType = StructTypeReference.create("cel.expr.conformance.proto3.TestAllTypes");
declareVariable("x", messageType);
source =
"x.map_string_string.exists_one(i, v, i < v) "
+ "&& x.repeated_int64.exists_one(i, v, i < v) "
+ "&& [1, 2, 3, 4].exists_one(i, v, i < 5 && v > 0) "
+ "&& {'a': 1, 'b': 2}.exists_one(k, v, k.startsWith('a') && v == 1)";
runTest();
}

@Test
public void twoVarComprehensions_transformListMacro() throws Exception {
CelType messageType = StructTypeReference.create("cel.expr.conformance.proto3.TestAllTypes");
declareVariable("x", messageType);
source =
"[1, 2, 3].transformList(i, v, i > 0 && v < 3, (i * v) + v) == [4] "
+ "&& [1, 2, 3].transformList(i, v, i % 2 == 0, (i * v) + v) == [1,9] "
+ "&& [1, 2, 3].transformList(i, v, (i * v) + v) == [1,4,9]";
runTest();
}

@Test
public void twoVarComprehensions_incorrectIterVars() throws Exception {
CelType messageType = StructTypeReference.create("cel.expr.conformance.proto3.TestAllTypes");
declareVariable("x", messageType);
source = "x.map_string_string.all(i + 1, v, i < v) && x.repeated_int64.all(i, v + 1, i < v)";
runTest();
}

@Test
public void twoVarComprehensions_duplicateIterVars() throws Exception {
CelType messageType = StructTypeReference.create("cel.expr.conformance.proto3.TestAllTypes");
declareVariable("x", messageType);
source =
"x.repeated_int64.exists(i, i, i < v)";
runTest();
}

@Test
public void twoVarComprehensions_incorrectNumberOfArgs() throws Exception {
CelType messageType = StructTypeReference.create("cel.expr.conformance.proto3.TestAllTypes");
declareVariable("x", messageType);
source =
"[1, 2, 3, 4].exists_one(i, v, i < v, v)"
+ "&& x.map_string_string.transformList(i, i < v) "
+ "&& [1, 2, 3].transformList(i, v, i > 0 && x < 3, (i * v) + v) == [4]";
runTest();
}

@Test
public void quantifiersErrors() throws Exception {
CelType messageType = StructTypeReference.create("cel.expr.conformance.proto3.TestAllTypes");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Source: x.repeated_int64.exists(i, i, i < v)
declare x {
value cel.expr.conformance.proto3.TestAllTypes
}
=====>
ERROR: test_location:1:1: overlapping declaration name 'i' (type 'int' cannot be distinguished from 'int')
| x.repeated_int64.exists(i, i, i < v)
| ^
ERROR: test_location:1:35: undeclared reference to 'v' (in container '')
| x.repeated_int64.exists(i, i, i < v)
| ..................................^
134 changes: 134 additions & 0 deletions 134 checker/src/test/resources/twoVarComprehensions_existsMacro.baseline
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
Source: x.map_string_string.exists(i, v, i < v) && x.repeated_int64.exists(i, v, i < v) && [1, 2, 3, 4].exists(i, v, i < 5 && v > 0) && {'a': 1, 'b': 2}.exists(k, v, k.startsWith('a') && v == 1)
declare x {
value cel.expr.conformance.proto3.TestAllTypes
}
=====>
_&&_(
_&&_(
__comprehension__(
// Variable
i,
v,
// Target
x~cel.expr.conformance.proto3.TestAllTypes^x.map_string_string~map(string, string),
// Accumulator
@result,
// Init
false~bool,
// LoopCondition
@not_strictly_false(
!_(
@result~bool^@result
)~bool^logical_not
)~bool^not_strictly_false,
// LoopStep
_||_(
@result~bool^@result,
_<_(
i~string^i,
v~string^v
)~bool^less_string
)~bool^logical_or,
// Result
@result~bool^@result)~bool,
__comprehension__(
// Variable
i,
v,
// Target
x~cel.expr.conformance.proto3.TestAllTypes^x.repeated_int64~list(int),
// Accumulator
@result,
// Init
false~bool,
// LoopCondition
@not_strictly_false(
!_(
@result~bool^@result
)~bool^logical_not
)~bool^not_strictly_false,
// LoopStep
_||_(
@result~bool^@result,
_<_(
i~int^i,
v~int^v
)~bool^less_int64
)~bool^logical_or,
// Result
@result~bool^@result)~bool
)~bool^logical_and,
_&&_(
__comprehension__(
// Variable
i,
v,
// Target
[
1~int,
2~int,
3~int,
4~int
]~list(int),
// Accumulator
@result,
// Init
false~bool,
// LoopCondition
@not_strictly_false(
!_(
@result~bool^@result
)~bool^logical_not
)~bool^not_strictly_false,
// LoopStep
_||_(
@result~bool^@result,
_&&_(
_<_(
i~int^i,
5~int
)~bool^less_int64,
_>_(
v~int^v,
0~int
)~bool^greater_int64
)~bool^logical_and
)~bool^logical_or,
// Result
@result~bool^@result)~bool,
__comprehension__(
// Variable
k,
v,
// Target
{
"a"~string:1~int,
"b"~string:2~int
}~map(string, int),
// Accumulator
@result,
// Init
false~bool,
// LoopCondition
@not_strictly_false(
!_(
@result~bool^@result
)~bool^logical_not
)~bool^not_strictly_false,
// LoopStep
_||_(
@result~bool^@result,
_&&_(
k~string^k.startsWith(
"a"~string
)~bool^starts_with_string,
_==_(
v~int^v,
1~int
)~bool^equals
)~bool^logical_and
)~bool^logical_or,
// Result
@result~bool^@result)~bool
)~bool^logical_and
)~bool^logical_and
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
Source: x.map_string_string.exists_one(i, v, i < v) && x.repeated_int64.exists_one(i, v, i < v) && [1, 2, 3, 4].exists_one(i, v, i < 5 && v > 0) && {'a': 1, 'b': 2}.exists_one(k, v, k.startsWith('a') && v == 1)
declare x {
value cel.expr.conformance.proto3.TestAllTypes
}
=====>
_&&_(
_&&_(
__comprehension__(
// Variable
i,
v,
// Target
x~cel.expr.conformance.proto3.TestAllTypes^x.map_string_string~map(string, string),
// Accumulator
@result,
// Init
0~int,
// LoopCondition
true~bool,
// LoopStep
_?_:_(
_<_(
i~string^i,
v~string^v
)~bool^less_string,
_+_(
@result~int^@result,
1~int
)~int^add_int64,
@result~int^@result
)~int^conditional,
// Result
_==_(
@result~int^@result,
1~int
)~bool^equals)~bool,
__comprehension__(
// Variable
i,
v,
// Target
x~cel.expr.conformance.proto3.TestAllTypes^x.repeated_int64~list(int),
// Accumulator
@result,
// Init
0~int,
// LoopCondition
true~bool,
// LoopStep
_?_:_(
_<_(
i~int^i,
v~int^v
)~bool^less_int64,
_+_(
@result~int^@result,
1~int
)~int^add_int64,
@result~int^@result
)~int^conditional,
// Result
_==_(
@result~int^@result,
1~int
)~bool^equals)~bool
)~bool^logical_and,
_&&_(
__comprehension__(
// Variable
i,
v,
// Target
[
1~int,
2~int,
3~int,
4~int
]~list(int),
// Accumulator
@result,
// Init
0~int,
// LoopCondition
true~bool,
// LoopStep
_?_:_(
_&&_(
_<_(
i~int^i,
5~int
)~bool^less_int64,
_>_(
v~int^v,
0~int
)~bool^greater_int64
)~bool^logical_and,
_+_(
@result~int^@result,
1~int
)~int^add_int64,
@result~int^@result
)~int^conditional,
// Result
_==_(
@result~int^@result,
1~int
)~bool^equals)~bool,
__comprehension__(
// Variable
k,
v,
// Target
{
"a"~string:1~int,
"b"~string:2~int
}~map(string, int),
// Accumulator
@result,
// Init
0~int,
// LoopCondition
true~bool,
// LoopStep
_?_:_(
_&&_(
k~string^k.startsWith(
"a"~string
)~bool^starts_with_string,
_==_(
v~int^v,
1~int
)~bool^equals
)~bool^logical_and,
_+_(
@result~int^@result,
1~int
)~int^add_int64,
@result~int^@result
)~int^conditional,
// Result
_==_(
@result~int^@result,
1~int
)~bool^equals)~bool
)~bool^logical_and
)~bool^logical_and
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.