|
23 | 23 | import com.google.common.primitives.UnsignedLong;
|
24 | 24 | import com.google.protobuf.ByteString;
|
25 | 25 | import com.google.protobuf.ExtensionRegistryLite;
|
| 26 | +import com.google.testing.junit.testparameterinjector.TestParameter; |
26 | 27 | import com.google.testing.junit.testparameterinjector.TestParameterInjector;
|
27 | 28 | import dev.cel.common.CelAbstractSyntaxTree;
|
| 29 | +import dev.cel.common.CelOptions; |
28 | 30 | import dev.cel.common.CelProtoAbstractSyntaxTree;
|
29 | 31 | import dev.cel.common.CelSource;
|
30 | 32 | import dev.cel.common.ast.CelConstant;
|
@@ -63,6 +65,14 @@ public void programConstruction() throws Exception {
|
63 | 65 | assertThat(program).isNotNull();
|
64 | 66 | }
|
65 | 67 |
|
| 68 | + @Test |
| 69 | + public void setCelOptions_unallowedOptionsSet_throws(@TestParameter CelOptionsTestCase testCase) { |
| 70 | + assertThrows( |
| 71 | + IllegalArgumentException.class, |
| 72 | + () -> |
| 73 | + CelLiteRuntimeFactory.newLiteRuntimeBuilder().setOptions(testCase.celOptions).build()); |
| 74 | + } |
| 75 | + |
66 | 76 | @Test
|
67 | 77 | public void standardEnvironment_disabledByDefault() throws Exception {
|
68 | 78 | CelLiteRuntime runtime = CelLiteRuntimeFactory.newLiteRuntimeBuilder().build();
|
@@ -187,4 +197,24 @@ private static CelAbstractSyntaxTree readCheckedExpr(String compiledCelTarget) t
|
187 | 197 | CheckedExpr.parseFrom(checkedExprBytes, ExtensionRegistryLite.getEmptyRegistry());
|
188 | 198 | return CelProtoAbstractSyntaxTree.fromCheckedExpr(checkedExpr).getAst();
|
189 | 199 | }
|
| 200 | + |
| 201 | + private enum CelOptionsTestCase { |
| 202 | + CEL_VALUE_DISABLED(newBaseTestOptions().enableCelValue(false).build()), |
| 203 | + UNSIGNED_LONG_DISABLED(newBaseTestOptions().enableUnsignedLongs(false).build()), |
| 204 | + UNWRAP_WKT_DISABLED(newBaseTestOptions().unwrapWellKnownTypesOnFunctionDispatch(false).build()), |
| 205 | + STRING_CONCAT_DISABLED(newBaseTestOptions().enableStringConcatenation(false).build()), |
| 206 | + STRING_CONVERSION_DISABLED(newBaseTestOptions().enableStringConversion(false).build()), |
| 207 | + LIST_CONCATENATION_DISABLED(newBaseTestOptions().enableListConcatenation(false).build()), |
| 208 | + ; |
| 209 | + |
| 210 | + private final CelOptions celOptions; |
| 211 | + |
| 212 | + private static CelOptions.Builder newBaseTestOptions() { |
| 213 | + return CelOptions.current().enableCelValue(true); |
| 214 | + } |
| 215 | + |
| 216 | + CelOptionsTestCase(CelOptions celOptions) { |
| 217 | + this.celOptions = celOptions; |
| 218 | + } |
| 219 | + } |
190 | 220 | }
|
0 commit comments