Skip to content

Commit

Permalink
No public description
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 567132204
  • Loading branch information
l46kok authored and copybara-github committed Sep 21, 2023
1 parent 8cb805a commit a7beb7a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 12 deletions.
9 changes: 5 additions & 4 deletions bundle/src/test/java/dev/cel/bundle/CelImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import dev.cel.common.CelAbstractSyntaxTree;
import dev.cel.common.CelIssue;
import dev.cel.common.CelOptions;
import dev.cel.common.CelProtoAbstractSyntaxTree;
import dev.cel.common.CelValidationException;
import dev.cel.common.CelValidationResult;
import dev.cel.common.CelVarDecl;
Expand Down Expand Up @@ -1053,7 +1054,7 @@ public void setOptions() throws Exception {
Cel cel = standardCelBuilderWithMacros().build();
CelValidationResult result = cel.parse("!!!true");
assertThat(result.hasError()).isFalse();
assertThat(result.getAst().toParsedExpr().getExpr())
assertThat(CelProtoAbstractSyntaxTree.fromCelAst(result.getAst()).toParsedExpr().getExpr())
.ignoringFieldDescriptors(Expr.getDescriptor().findFieldByName("id"))
.isEqualTo(NOT_EXPR);

Expand All @@ -1063,7 +1064,7 @@ public void setOptions() throws Exception {
.build();
result = cel.parse("!!!true");
assertThat(result.hasError()).isFalse();
assertThat(result.getAst().toParsedExpr().getExpr())
assertThat(CelProtoAbstractSyntaxTree.fromCelAst(result.getAst()).toParsedExpr().getExpr())
.ignoringFieldDescriptors(Expr.getDescriptor().findFieldByName("id"))
.isEqualTo(NOT_NOT_NOT_EXPR);
}
Expand All @@ -1078,7 +1079,7 @@ private void assertValidationResult(CelValidationResult result, ParsedExpr parse
throws Exception {
assertThat(result.hasError()).isFalse();
assertThat(result.getAllIssues()).isEmpty();
assertThat(result.getAst().toParsedExpr())
assertThat(CelProtoAbstractSyntaxTree.fromCelAst(result.getAst()).toParsedExpr())
.ignoringFieldDescriptors(
Expr.getDescriptor().findFieldByName("id"),
ParsedExpr.getDescriptor().findFieldByName("source_info"))
Expand All @@ -1089,7 +1090,7 @@ private void assertValidationResult(CelValidationResult result, ParsedExpr parse
private void assertValidationResult(CelValidationResult result, CheckedExpr checkedExpr)
throws Exception {
assertThat(result.hasError()).isFalse();
assertThat(result.getAst().toCheckedExpr())
assertThat(CelProtoAbstractSyntaxTree.fromCelAst(result.getAst()).toCheckedExpr())
.ignoringFieldDescriptors(
Expr.getDescriptor().findFieldByName("id"),
CheckedExpr.getDescriptor().findFieldByName("source_info"))
Expand Down
12 changes: 9 additions & 3 deletions checker/src/test/java/dev/cel/checker/ExprCheckerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.google.protobuf.DescriptorProtos.FileDescriptorSet;
// import com.google.testing.testsize.MediumTest;
import dev.cel.common.CelAbstractSyntaxTree;
import dev.cel.common.CelProtoAbstractSyntaxTree;
import dev.cel.common.internal.EnvVisitable;
import dev.cel.common.internal.Errors;
import dev.cel.common.types.CelTypes;
Expand Down Expand Up @@ -78,7 +79,9 @@ private void runTest() throws Exception {
testOutput()
.println(
CelDebug.toAdornedDebugString(
ast.getProtoExpr(), new CheckedExprAdorner(ast.toCheckedExpr())));
CelProtoAbstractSyntaxTree.fromCelAst(ast).getExpr(),
new CheckedExprAdorner(
CelProtoAbstractSyntaxTree.fromCelAst(ast).toCheckedExpr())));
}
testOutput().println();
}
Expand Down Expand Up @@ -699,7 +702,9 @@ public void globalStandaloneEnumValues() throws Exception {
testOutput()
.println(
CelDebug.toAdornedDebugString(
ast.getProtoExpr(), new CheckedExprAdorner(ast.toCheckedExpr())));
CelProtoAbstractSyntaxTree.fromCelAst(ast).getExpr(),
new CheckedExprAdorner(
CelProtoAbstractSyntaxTree.fromCelAst(ast).toCheckedExpr())));
}
}

Expand Down Expand Up @@ -949,7 +954,8 @@ public void optionalErrors() throws Exception {
source = "a.?b";
declareVariable("a", createMap(CelTypes.STRING, CelTypes.STRING));
prepareCompiler(new ProtoMessageTypeProvider());
ParsedExpr parsedExpr = celCompiler.parse(source).getAst().toParsedExpr();
ParsedExpr parsedExpr =
CelProtoAbstractSyntaxTree.fromCelAst(celCompiler.parse(source).getAst()).toParsedExpr();
ParsedExpr.Builder parsedExprBuilder = parsedExpr.toBuilder();
parsedExprBuilder
.getExprBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.google.common.collect.ImmutableList;
import com.google.common.primitives.UnsignedLong;
import dev.cel.common.CelAbstractSyntaxTree;
import dev.cel.common.CelProtoAbstractSyntaxTree;
import dev.cel.common.CelValidationException;
import dev.cel.common.CelValidationResult;
import dev.cel.parser.CelParser;
Expand Down Expand Up @@ -110,7 +111,8 @@ public static CelAttributePattern parsePattern(String attribute) {
try {
CelAbstractSyntaxTree ast = result.getAst();
ArrayDeque<CelAttribute.Qualifier> qualifiers = new ArrayDeque<>();
Expr node = ast.getProtoExpr();
// TODO: Traverse using CelExpr
Expr node = CelProtoAbstractSyntaxTree.fromCelAst(ast).getExpr();
while (node != null) {
switch (node.getExprKindCase()) {
case IDENT_EXPR:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private Object runTest(Activation activation) throws Exception {
testOutput().println("bindings: " + activation);
Object result = null;
try {
result = eval.eval(ast.toCheckedExpr(), activation);
result = eval.eval(CelProtoAbstractSyntaxTree.fromCelAst(ast).toCheckedExpr(), activation);
if (result instanceof ByteString) {
// Note: this call may fail for printing byte sequences that are not valid UTF-8, but works
// pretty well for test purposes.
Expand All @@ -113,7 +113,7 @@ private Object runTest(Activation activation) throws Exception {
* native CelAbstractSyntaxTree
*/
private void assertAstRoundTrip(CelAbstractSyntaxTree ast) {
CheckedExpr checkedExpr = ast.toCheckedExpr();
CheckedExpr checkedExpr = CelProtoAbstractSyntaxTree.fromCelAst(ast).toCheckedExpr();
CelProtoAbstractSyntaxTree protoAst = CelProtoAbstractSyntaxTree.fromCelAst(ast);
assertThat(checkedExpr).isEqualTo(protoAst.toCheckedExpr());
}
Expand Down
11 changes: 9 additions & 2 deletions testing/src/test/java/dev/cel/testing/EvalSyncTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.google.type.Expr;
import dev.cel.common.CelAbstractSyntaxTree;
import dev.cel.common.CelOptions;
import dev.cel.common.CelProtoAbstractSyntaxTree;
import dev.cel.common.types.CelType;
import dev.cel.common.types.SimpleType;
import dev.cel.compiler.CelCompiler;
Expand Down Expand Up @@ -140,7 +141,10 @@ public EvalWithoutActivationTests(String expr, Object evaluatedResult) {
@Test
public void evaluateExpr_returnsExpectedResult() throws Exception {
CelAbstractSyntaxTree ast = COMPILER.compile(expr).getAst();
assertThat(EVAL.eval(ast.toCheckedExpr(), Activation.EMPTY)).isEqualTo(evaluatedResult);
assertThat(
EVAL.eval(
CelProtoAbstractSyntaxTree.fromCelAst(ast).toCheckedExpr(), Activation.EMPTY))
.isEqualTo(evaluatedResult);
}
}

Expand Down Expand Up @@ -178,7 +182,10 @@ public EvalWithActivationTests(
@Test
public void expr_returnsExpectedResult() throws Exception {
CelAbstractSyntaxTree ast = compiler.compile(expr).getAst();
assertThat(EVAL.eval(ast.toCheckedExpr(), Activation.of("x", paramValue)))
assertThat(
EVAL.eval(
CelProtoAbstractSyntaxTree.fromCelAst(ast).toCheckedExpr(),
Activation.of("x", paramValue)))
.isEqualTo(evaluatedResult);
}
}
Expand Down

0 comments on commit a7beb7a

Please sign in to comment.