Skip to content
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
4 changes: 4 additions & 0 deletions common/src/main/java/dev/cel/common/ast/CelMutableExpr.java
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,10 @@ public static CelMutableExpr ofMap(long id, CelMutableMap mutableMap) {
return new CelMutableExpr(id, mutableMap);
}

public static CelMutableExpr ofComprehension(CelMutableComprehension mutableComprehension) {
return ofComprehension(0, mutableComprehension);
}

public static CelMutableExpr ofComprehension(
long id, CelMutableComprehension mutableComprehension) {
return new CelMutableExpr(id, mutableComprehension);
Expand Down
29 changes: 29 additions & 0 deletions common/src/test/java/dev/cel/common/ast/CelMutableExprTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,35 @@ public void mutableMap_deepCopy() {
.containsExactlyElementsIn(deepCopiedExpr.map().entries());
}

@Test
public void ofComprehension() {
CelMutableExpr mutableExpr =
CelMutableExpr.ofComprehension(
CelMutableComprehension.create(
"iterVar",
CelMutableExpr.ofList(
CelMutableList.create(CelMutableExpr.ofConstant(CelConstant.ofValue(true)))),
"accuVar",
CelMutableExpr.ofConstant(CelConstant.ofValue(true)),
CelMutableExpr.ofConstant(CelConstant.ofValue(true)),
CelMutableExpr.ofConstant(CelConstant.ofValue(true)),
CelMutableExpr.ofIdent("__result__")));

assertThat(mutableExpr.id()).isEqualTo(0L);
assertThat(mutableExpr.comprehension())
.isEqualTo(
CelMutableComprehension.create(
"iterVar",
"",
CelMutableExpr.ofList(
CelMutableList.create(CelMutableExpr.ofConstant(CelConstant.ofValue(true)))),
"accuVar",
CelMutableExpr.ofConstant(CelConstant.ofValue(true)),
CelMutableExpr.ofConstant(CelConstant.ofValue(true)),
CelMutableExpr.ofConstant(CelConstant.ofValue(true)),
CelMutableExpr.ofIdent("__result__")));
}

@Test
public void ofComprehension_withId() {
CelMutableExpr mutableExpr =
Expand Down
Loading