Skip to content
Merged
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
9 changes: 7 additions & 2 deletions bundle/src/test/java/dev/cel/bundle/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,18 @@ java_library(
"//bundle:environment_exporter",
"//bundle:environment_yaml_parser",
"//checker",
"//checker:checker_legacy_environment",
"//checker:proto_type_mask",
"//checker:standard_decl",
"//checker:type_provider_legacy",
"//common:cel_ast",
"//common:cel_descriptor_util",
"//common:cel_function_decl",
"//common:cel_issue",
"//common:cel_overload_decl",
"//common:cel_source",
"//common:compiler_common",
"//common:cel_validation_exception",
"//common:cel_validation_result",
"//common:cel_var_decl",
"//common:container",
"//common:error_codes",
"//common:options",
Expand Down
20 changes: 10 additions & 10 deletions bundle/src/test/java/dev/cel/bundle/CelEnvironmentExporterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@
@RunWith(TestParameterInjector.class)
public class CelEnvironmentExporterTest {

public static final CelOptions CEL_OPTIONS =
CelOptions.newBuilder().enableHeterogeneousNumericComparisons(true).build();
private static final CelOptions CEL_OPTIONS =
CelOptions.current().enableHeterogeneousNumericComparisons(true).build();

@Test
public void extensions_latest() {
Cel cel =
CelFactory.standardCelBuilder()
CelFactory.plannerCelBuilder()
.addCompilerLibraries(CelExtensions.math(CEL_OPTIONS, 2))
.build();

Expand All @@ -70,7 +70,7 @@ public void extensions_latest() {
@Test
public void extensions_earlierVersion() {
Cel cel =
CelFactory.standardCelBuilder()
CelFactory.plannerCelBuilder()
.addCompilerLibraries(CelExtensions.math(CEL_OPTIONS, 1))
.build();

Expand All @@ -88,7 +88,7 @@ public void standardLibrarySubset_favorExclusion() throws Exception {
CelEnvironment environment = CelEnvironmentYamlParser.newInstance().parse(yamlFileContent);

Cel standardCel =
CelFactory.standardCelBuilder()
CelFactory.plannerCelBuilder()
.addCompilerLibraries(CelExtensions.math(CEL_OPTIONS, 2))
.build();
Cel extendedCel = environment.extend(standardCel, CEL_OPTIONS);
Expand Down Expand Up @@ -123,7 +123,7 @@ public void standardLibrarySubset_favorInclusion() throws Exception {
CelEnvironment environment = CelEnvironmentYamlParser.newInstance().parse(yamlFileContent);

Cel standardCel =
CelFactory.standardCelBuilder()
CelFactory.plannerCelBuilder()
.addCompilerLibraries(CelExtensions.math(CEL_OPTIONS, 2))
.build();
Cel extendedCel = environment.extend(standardCel, CEL_OPTIONS);
Expand Down Expand Up @@ -171,7 +171,7 @@ public void standardLibrarySubset_favorInclusion() throws Exception {
@Test
public void customFunctions() {
Cel cel =
CelFactory.standardCelBuilder()
CelFactory.plannerCelBuilder()
.addCompilerLibraries(CelExtensions.math(CEL_OPTIONS, 1))
.addFunctionDeclarations(
CelFunctionDecl.newFunctionDeclaration(
Expand Down Expand Up @@ -296,7 +296,7 @@ public void customFunctions() {
@Test
public void customVariables() {
Cel cel =
CelFactory.standardCelBuilder()
CelFactory.plannerCelBuilder()
.addVarDeclarations(
CelVarDecl.newVarDeclaration("x", SimpleType.INT),
CelVarDecl.newVarDeclaration("y", OpaqueType.create("foo.Bar")))
Expand All @@ -321,7 +321,7 @@ public void customVariables() {
@Test
public void container() {
Cel cel =
CelFactory.standardCelBuilder()
CelFactory.plannerCelBuilder()
.setContainer(
CelContainer.newBuilder()
.setName("cntnr")
Expand All @@ -342,7 +342,7 @@ public void container() {
@Test
public void options() {
Cel cel =
CelFactory.standardCelBuilder()
CelFactory.plannerCelBuilder()
.setOptions(
CelOptions.current()
.maxExpressionCodePointSize(100)
Expand Down
29 changes: 16 additions & 13 deletions bundle/src/test/java/dev/cel/bundle/CelEnvironmentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
@RunWith(TestParameterInjector.class)
public class CelEnvironmentTest {

private static final CelOptions CEL_OPTIONS =
CelOptions.current().enableHeterogeneousNumericComparisons(true).build();

@Test
public void newBuilder_defaults() {
CelEnvironment environment = CelEnvironment.newBuilder().build();
Expand Down Expand Up @@ -90,7 +93,7 @@ public void extend_allExtensions() throws Exception {
CelEnvironment environment =
CelEnvironment.newBuilder().addExtensions(extensionConfigs).build();

Cel cel = environment.extend(CelFactory.standardCelBuilder().build(), CelOptions.DEFAULT);
Cel cel = environment.extend(CelFactory.plannerCelBuilder().build(), CEL_OPTIONS);
CelAbstractSyntaxTree ast =
cel.compile(
"cel.bind(x, 10, math.greatest([1,x])) < int(' 11 '.trim()) &&"
Expand All @@ -116,7 +119,7 @@ public void extend_allFeatureFlags() throws Exception {

Cel cel =
environment.extend(
CelFactory.standardCelBuilder()
CelFactory.plannerCelBuilder()
.setStandardMacros(CelStandardMacro.STANDARD_MACROS)
.build(),
CelOptions.DEFAULT);
Expand All @@ -140,10 +143,10 @@ public void extend_allLimits() throws Exception {

Cel cel =
environment.extend(
CelFactory.standardCelBuilder()
CelFactory.plannerCelBuilder()
.setStandardMacros(CelStandardMacro.STANDARD_MACROS)
.build(),
CelOptions.DEFAULT);
CEL_OPTIONS);
CelOptions checkerOptions = cel.toCheckerBuilder().options();
assertThat(checkerOptions.maxExpressionCodePointSize()).isEqualTo(20);
assertThat(checkerOptions.maxParseErrorRecoveryLimit()).isEqualTo(10);
Expand All @@ -169,10 +172,10 @@ public void extend_expressionNodeCountLimit() throws Exception {

Cel cel =
environment.extend(
CelFactory.legacyCelBuilder()
CelFactory.plannerCelBuilder()
.setStandardMacros(CelStandardMacro.STANDARD_MACROS)
.build(),
CelOptions.DEFAULT);
CEL_OPTIONS);
CelOptions checkerOptions = cel.toCheckerBuilder().options();
assertThat(checkerOptions.maxParseExpressionNodeCount()).isEqualTo(2);

Expand All @@ -193,10 +196,10 @@ public void extend_unsupportedFeatureFlag_throws() throws Exception {
IllegalArgumentException.class,
() ->
environment.extend(
CelFactory.standardCelBuilder()
CelFactory.plannerCelBuilder()
.setStandardMacros(CelStandardMacro.STANDARD_MACROS)
.build(),
CelOptions.DEFAULT));
CEL_OPTIONS));
assertThat(e).hasMessageThat().contains("Unknown feature flag: unknown.feature");
}

Expand All @@ -212,10 +215,10 @@ public void extend_unsupportedLimit_throws() throws Exception {
IllegalArgumentException.class,
() ->
environment.extend(
CelFactory.standardCelBuilder()
CelFactory.plannerCelBuilder()
.setStandardMacros(CelStandardMacro.STANDARD_MACROS)
.build(),
CelOptions.DEFAULT));
CEL_OPTIONS));
assertThat(e).hasMessageThat().contains("Unknown limit: unknown.limit");
}

Expand All @@ -224,7 +227,7 @@ public void extensionVersion_specific() throws Exception {
CelEnvironment environment =
CelEnvironment.newBuilder().addExtensions(ExtensionConfig.of("math", 1)).build();

Cel cel = environment.extend(CelFactory.standardCelBuilder().build(), CelOptions.DEFAULT);
Cel cel = environment.extend(CelFactory.plannerCelBuilder().build(), CEL_OPTIONS);
CelAbstractSyntaxTree ast1 = cel.compile("math.abs(-4)").getAst();
assertThat(cel.createProgram(ast1).eval()).isEqualTo(4);

Expand All @@ -244,7 +247,7 @@ public void extensionVersion_latest() throws Exception {
CelEnvironment environment =
CelEnvironment.newBuilder().addExtensions(ExtensionConfig.latest("math")).build();

Cel cel = environment.extend(CelFactory.standardCelBuilder().build(), CelOptions.DEFAULT);
Cel cel = environment.extend(CelFactory.plannerCelBuilder().build(), CEL_OPTIONS);
CelAbstractSyntaxTree ast = cel.compile("math.sqrt(4)").getAst();
double result = (double) cel.createProgram(ast).eval();
assertThat(result).isEqualTo(2.0);
Expand All @@ -259,7 +262,7 @@ public void extensionVersion_unsupportedVersion_throws() {
assertThrows(
CelEnvironmentException.class,
() -> {
environment.extend(CelFactory.standardCelBuilder().build(), CelOptions.DEFAULT);
environment.extend(CelFactory.plannerCelBuilder().build(), CEL_OPTIONS);
}))
.hasMessageThat()
.contains("Unsupported 'math' extension version -5");
Expand Down
Loading
Loading