Skip to content
Open
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
82 changes: 77 additions & 5 deletions bundle/src/test/java/dev/cel/bundle/CelImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1228,13 +1228,19 @@ private CelVariableResolver fromMap(ImmutableMap<String, ?> m) {
}

@Test
public void programAdvanceEvaluation_unknownsBasic() throws Exception {
public void programAdvanceEvaluation_unknownsBasic(@TestParameter CelRuntimeFlavor runtimeFlavor)
throws Exception {
Cel cel =
standardCelBuilderWithMacros()
.setOptions(CelOptions.current().enableUnknownTracking(true).build())
runtimeFlavor
.builder()
.setStandardMacros(CelStandardMacro.STANDARD_MACROS)
.setOptions(
CelOptions.current()
.enableUnknownTracking(true)
.enableHeterogeneousNumericComparisons(true)
.build())
.addVar("a", SimpleType.BOOL)
.addVar("b", SimpleType.BOOL)
.addFunctionBindings()
.setResultType(SimpleType.BOOL)
.build();
CelRuntime.Program program = cel.createProgram(cel.compile("a || b").getAst());
Expand Down Expand Up @@ -1439,7 +1445,7 @@ public void programAdvanceEvaluation_argumentMergeErrorPriority() throws Excepti
CelRuntime.Program program =
cel.createProgram(cel.compile("acceptThreeBoolArgs(false, unk, [false][1])").getAst());

Assert.assertThrows(
assertThrows(
CelEvaluationException.class,
() ->
program.advanceEvaluation(
Expand Down Expand Up @@ -1634,6 +1640,72 @@ public void programAdvanceEvaluation_unsupportedIndexIgnored() throws Exception
.isEqualTo(false);
}

@Test
public void programAdvanceEvaluation_sizeList() throws Exception {
Cel cel =
CelRuntimeFlavor.PLANNER
.builder()
.setStandardMacros(CelStandardMacro.STANDARD_MACROS)
.setOptions(
CelOptions.current()
.enableUnknownTracking(true)
.enableHeterogeneousNumericComparisons(true)
.build())
.addVar("testList", ListType.create(SimpleType.BOOL))
.setContainer(CelContainer.ofName(""))
.addFunctionBindings()
.setResultType(SimpleType.INT)
.build();
CelRuntime.Program program = cel.createProgram(cel.compile("size(testList)").getAst());
Object result =
program.advanceEvaluation(
UnknownContext.create(
fromMap(ImmutableMap.of("testList", ImmutableList.of(true, true, false))),
ImmutableList.of(
CelAttributePattern.create("testList").qualify(Qualifier.ofInt(2)))));
assertThat(result).isEqualTo(3L);
}

@Test
public void programAdvanceEvaluation_listIndexUnknownElement() throws Exception {
Cel cel =
CelRuntimeFlavor.PLANNER
.builder()
.setStandardMacros(CelStandardMacro.STANDARD_MACROS)
.setOptions(
CelOptions.current()
.enableUnknownTracking(true)
.enableHeterogeneousNumericComparisons(true)
.build())
.addVar("testList", ListType.create(SimpleType.BOOL))
.setContainer(CelContainer.ofName(""))
.addFunctionBindings()
.setResultType(SimpleType.BOOL)
.build();

CelRuntime.Program program = cel.createProgram(cel.compile("testList[2] == true").getAst());

assertThat(
program.advanceEvaluation(
UnknownContext.create(
fromMap(ImmutableMap.of("testList", ImmutableList.of(true, true, false))),
ImmutableList.of(
CelAttributePattern.create("testList").qualify(Qualifier.ofInt(2))))))
.isEqualTo(
CelUnknownSet.create(
ImmutableSet.of(CelAttribute.create("testList").qualify(Qualifier.ofInt(2)))));

CelRuntime.Program programIndex1 =
cel.createProgram(cel.compile("testList[1] == true").getAst());
assertThat(
programIndex1.advanceEvaluation(
UnknownContext.create(
fromMap(ImmutableMap.of("testList", ImmutableList.of(true, true, false))),
ImmutableList.of(
CelAttributePattern.create("testList").qualify(Qualifier.ofInt(2))))))
.isEqualTo(true);
}

@Test
public void programAdvanceEvaluation_listIndexMacroTracking() throws Exception {
Cel cel =
Expand Down
Loading
Loading