|
49 | 49 | import dev.cel.expr.conformance.proto3.TestAllTypes.NestedMessage; |
50 | 50 | import dev.cel.parser.CelMacro; |
51 | 51 | import dev.cel.parser.CelStandardMacro; |
| 52 | +import dev.cel.runtime.CelAttributePattern; |
52 | 53 | import dev.cel.runtime.CelEvaluationException; |
53 | 54 | import dev.cel.runtime.CelFunctionBinding; |
54 | 55 | import dev.cel.runtime.CelRuntime; |
55 | 56 | import dev.cel.runtime.InterpreterUtil; |
| 57 | +import dev.cel.runtime.PartialVars; |
56 | 58 | import java.time.Duration; |
57 | 59 | import java.time.Instant; |
58 | 60 | import java.util.List; |
@@ -897,14 +899,14 @@ public void optionalIndex_onMap_returnsOptionalValue() throws Exception { |
897 | 899 | @TestParameters("{source: '{?x: x}'}") |
898 | 900 | public void optionalIndex_onMapWithUnknownInput_returnsUnknownResult(String source) |
899 | 901 | throws Exception { |
900 | | - if (testMode.equals(TestMode.PLANNER_CHECKED) || testMode.equals(TestMode.PLANNER_PARSE_ONLY)) { |
901 | | - // TODO: Uncomment once unknowns is implemented |
902 | | - return; |
903 | | - } |
904 | 902 | Cel cel = newCelBuilder().addVar("x", OptionalType.create(SimpleType.INT)).build(); |
905 | 903 | CelAbstractSyntaxTree ast = compile(cel, source); |
906 | 904 |
|
907 | | - Object result = cel.createProgram(ast).eval(); |
| 905 | + Object result = |
| 906 | + cel.createProgram(ast) |
| 907 | + .eval( |
| 908 | + PartialVars.of( |
| 909 | + ImmutableMap.of(), CelAttributePattern.fromQualifiedIdentifier("x"))); |
908 | 910 |
|
909 | 911 | assertThat(InterpreterUtil.isUnknown(result)).isTrue(); |
910 | 912 | } |
@@ -987,18 +989,18 @@ public void optionalIndex_onOptionalList_returnsOptionalValue() throws Exception |
987 | 989 |
|
988 | 990 | @Test |
989 | 991 | public void optionalIndex_onListWithUnknownInput_returnsUnknownResult() throws Exception { |
990 | | - if (testMode.equals(TestMode.PLANNER_CHECKED) || testMode.equals(TestMode.PLANNER_PARSE_ONLY)) { |
991 | | - // TODO: Uncomment once unknowns is implemented |
992 | | - return; |
993 | | - } |
994 | 992 | Cel cel = |
995 | 993 | newCelBuilder() |
996 | 994 | .addVar("x", OptionalType.create(SimpleType.INT)) |
997 | 995 | .setResultType(ListType.create(SimpleType.INT)) |
998 | 996 | .build(); |
999 | 997 | CelAbstractSyntaxTree ast = compile(cel, "[?x]"); |
1000 | 998 |
|
1001 | | - Object result = cel.createProgram(ast).eval(); |
| 999 | + Object result = |
| 1000 | + cel.createProgram(ast) |
| 1001 | + .eval( |
| 1002 | + PartialVars.of( |
| 1003 | + ImmutableMap.of(), CelAttributePattern.fromQualifiedIdentifier("x"))); |
1002 | 1004 |
|
1003 | 1005 | assertThat(InterpreterUtil.isUnknown(result)).isTrue(); |
1004 | 1006 | } |
@@ -1026,18 +1028,18 @@ public void traditionalIndex_onOptionalList_returnsOptionalEmpty() throws Except |
1026 | 1028 | @TestParameters("{expression: 'optional.none().orValue(optx)'}") |
1027 | 1029 | public void optionalChainedFunctions_lhsIsUnknown_returnsUnknown(String expression) |
1028 | 1030 | throws Exception { |
1029 | | - if (testMode.equals(TestMode.PLANNER_CHECKED) || testMode.equals(TestMode.PLANNER_PARSE_ONLY)) { |
1030 | | - // TODO: Uncomment once unknowns is implemented |
1031 | | - return; |
1032 | | - } |
1033 | 1031 | Cel cel = |
1034 | 1032 | newCelBuilder() |
1035 | 1033 | .addVar("optx", OptionalType.create(SimpleType.INT)) |
1036 | 1034 | .addVar("x", SimpleType.INT) |
1037 | 1035 | .build(); |
1038 | 1036 | CelAbstractSyntaxTree ast = compile(cel, expression); |
1039 | 1037 |
|
1040 | | - Object result = cel.createProgram(ast).eval(); |
| 1038 | + Object result = |
| 1039 | + cel.createProgram(ast) |
| 1040 | + .eval( |
| 1041 | + PartialVars.of( |
| 1042 | + ImmutableMap.of(), CelAttributePattern.fromQualifiedIdentifier("optx"))); |
1041 | 1043 |
|
1042 | 1044 | assertThat(InterpreterUtil.isUnknown(result)).isTrue(); |
1043 | 1045 | } |
|
0 commit comments