Skip to content

Commit f147ac3

Browse files
CEL Dev Teamcopybara-github
authored andcommitted
Couldn't find CelMutableExpr in repo here - https://github.com/google/cel-spec. So, believe this is an internal change.
PiperOrigin-RevId: 806154757
1 parent 0bb2f72 commit f147ac3

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

common/src/main/java/dev/cel/common/ast/CelMutableExpr.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,10 @@ public static CelMutableExpr ofMap(long id, CelMutableMap mutableMap) {
10341034
return new CelMutableExpr(id, mutableMap);
10351035
}
10361036

1037+
public static CelMutableExpr ofComprehension(CelMutableComprehension mutableComprehension) {
1038+
return ofComprehension(0, mutableComprehension);
1039+
}
1040+
10371041
public static CelMutableExpr ofComprehension(
10381042
long id, CelMutableComprehension mutableComprehension) {
10391043
return new CelMutableExpr(id, mutableComprehension);

common/src/test/java/dev/cel/common/ast/CelMutableExprTest.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,35 @@ public void mutableMap_deepCopy() {
600600
.containsExactlyElementsIn(deepCopiedExpr.map().entries());
601601
}
602602

603+
@Test
604+
public void ofComprehension() {
605+
CelMutableExpr mutableExpr =
606+
CelMutableExpr.ofComprehension(
607+
CelMutableComprehension.create(
608+
"iterVar",
609+
CelMutableExpr.ofList(
610+
CelMutableList.create(CelMutableExpr.ofConstant(CelConstant.ofValue(true)))),
611+
"accuVar",
612+
CelMutableExpr.ofConstant(CelConstant.ofValue(true)),
613+
CelMutableExpr.ofConstant(CelConstant.ofValue(true)),
614+
CelMutableExpr.ofConstant(CelConstant.ofValue(true)),
615+
CelMutableExpr.ofIdent("__result__")));
616+
617+
assertThat(mutableExpr.id()).isEqualTo(0L);
618+
assertThat(mutableExpr.comprehension())
619+
.isEqualTo(
620+
CelMutableComprehension.create(
621+
"iterVar",
622+
"",
623+
CelMutableExpr.ofList(
624+
CelMutableList.create(CelMutableExpr.ofConstant(CelConstant.ofValue(true)))),
625+
"accuVar",
626+
CelMutableExpr.ofConstant(CelConstant.ofValue(true)),
627+
CelMutableExpr.ofConstant(CelConstant.ofValue(true)),
628+
CelMutableExpr.ofConstant(CelConstant.ofValue(true)),
629+
CelMutableExpr.ofIdent("__result__")));
630+
}
631+
603632
@Test
604633
public void ofComprehension_withId() {
605634
CelMutableExpr mutableExpr =

0 commit comments

Comments
 (0)