From 8363a89773d68ae0939de6634321db26e4f853e4 Mon Sep 17 00:00:00 2001 From: Sokwhan Huh Date: Wed, 3 Sep 2025 11:29:09 -0700 Subject: [PATCH] Internal Changes PiperOrigin-RevId: 802636865 --- .../common/ast/CelMutableExprConverter.java | 1 + .../ast/CelMutableExprConverterTest.java | 79 +++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/common/src/main/java/dev/cel/common/ast/CelMutableExprConverter.java b/common/src/main/java/dev/cel/common/ast/CelMutableExprConverter.java index 00f3e6229..3e9ebc9c3 100644 --- a/common/src/main/java/dev/cel/common/ast/CelMutableExprConverter.java +++ b/common/src/main/java/dev/cel/common/ast/CelMutableExprConverter.java @@ -173,6 +173,7 @@ public static CelExpr fromMutableExpr(CelMutableExpr mutableExpr) { return CelExpr.ofComprehension( id, mutableComprehension.iterVar(), + mutableComprehension.iterVar2(), fromMutableExpr(mutableComprehension.iterRange()), mutableComprehension.accuVar(), fromMutableExpr(mutableComprehension.accuInit()), diff --git a/common/src/test/java/dev/cel/common/ast/CelMutableExprConverterTest.java b/common/src/test/java/dev/cel/common/ast/CelMutableExprConverterTest.java index d58d336ae..76f9f2027 100644 --- a/common/src/test/java/dev/cel/common/ast/CelMutableExprConverterTest.java +++ b/common/src/test/java/dev/cel/common/ast/CelMutableExprConverterTest.java @@ -432,4 +432,83 @@ public void convertCelComprehension_toMutableComprehension() { CelMutableExpr.ofConstant(6L, CelConstant.ofValue(true)), CelMutableExpr.ofIdent(7L, "__result__")))); } + + @Test + public void convertMutableComprehension_withTwoIterVars_toCelComprehension() { + CelMutableExpr mutableExpr = + CelMutableExpr.ofComprehension( + 1L, + CelMutableComprehension.create( + "iterVar", + "iterVar2", + CelMutableExpr.ofList( + 2L, + CelMutableList.create( + CelMutableExpr.ofConstant(3L, CelConstant.ofValue(true)))), + "accuVar", + CelMutableExpr.ofConstant(4L, CelConstant.ofValue(true)), + CelMutableExpr.ofConstant(5L, CelConstant.ofValue(true)), + CelMutableExpr.ofConstant(6L, CelConstant.ofValue(true)), + CelMutableExpr.ofIdent(7L, "__result__"))); + + CelExpr celExpr = CelMutableExprConverter.fromMutableExpr(mutableExpr); + + assertThat(celExpr) + .isEqualTo( + CelExpr.ofComprehension( + 1L, + "iterVar", + "iterVar2", + CelExpr.newBuilder() + .setId(2L) + .setList( + CelList.newBuilder() + .addElements(CelExpr.ofConstant(3L, CelConstant.ofValue(true))) + .build()) + .build(), + "accuVar", + CelExpr.ofConstant(4L, CelConstant.ofValue(true)), + CelExpr.ofConstant(5L, CelConstant.ofValue(true)), + CelExpr.ofConstant(6L, CelConstant.ofValue(true)), + CelExpr.ofIdent(7L, "__result__"))); + } + + @Test + public void convertCelComprehension_withTwoIterVars_toMutableComprehension() { + CelExpr celExpr = + CelExpr.ofComprehension( + 1L, + "iterVar", + "iterVar2", + CelExpr.newBuilder() + .setId(2L) + .setList( + CelList.newBuilder() + .addElements(CelExpr.ofConstant(3L, CelConstant.ofValue(true))) + .build()) + .build(), + "accuVar", + CelExpr.ofConstant(4L, CelConstant.ofValue(true)), + CelExpr.ofConstant(5L, CelConstant.ofValue(true)), + CelExpr.ofConstant(6L, CelConstant.ofValue(true)), + CelExpr.ofIdent(7L, "__result__")); + + CelMutableExpr mutableExpr = CelMutableExprConverter.fromCelExpr(celExpr); + assertThat(mutableExpr) + .isEqualTo( + CelMutableExpr.ofComprehension( + 1L, + CelMutableComprehension.create( + "iterVar", + "iterVar2", + CelMutableExpr.ofList( + 2L, + CelMutableList.create( + CelMutableExpr.ofConstant(3L, CelConstant.ofValue(true)))), + "accuVar", + CelMutableExpr.ofConstant(4L, CelConstant.ofValue(true)), + CelMutableExpr.ofConstant(5L, CelConstant.ofValue(true)), + CelMutableExpr.ofConstant(6L, CelConstant.ofValue(true)), + CelMutableExpr.ofIdent(7L, "__result__")))); + } }