|
114 | 114 | import dev.cel.runtime.CelUnknownSet; |
115 | 115 | import dev.cel.runtime.CelVariableResolver; |
116 | 116 | import dev.cel.runtime.UnknownContext; |
| 117 | +import dev.cel.testing.CelRuntimeFlavor; |
117 | 118 | import dev.cel.testing.testdata.SingleFile; |
118 | 119 | import dev.cel.testing.testdata.SingleFileExtensionsProto; |
119 | 120 | import dev.cel.testing.testdata.proto3.StandaloneGlobalEnum; |
@@ -2144,8 +2145,9 @@ public void toBuilder_isImmutable() { |
2144 | 2145 | } |
2145 | 2146 |
|
2146 | 2147 | @Test |
2147 | | - public void eval_withJsonFieldName(@TestParameter RuntimeEnv runtimeEnv) throws Exception { |
2148 | | - Cel cel = runtimeEnv.cel; |
| 2148 | + public void eval_withJsonFieldName(@TestParameter CelRuntimeFlavor runtimeFlavor) |
| 2149 | + throws Exception { |
| 2150 | + Cel cel = setupEnv(runtimeFlavor.builder()); |
2149 | 2151 | CelAbstractSyntaxTree ast = |
2150 | 2152 | cel.compile( |
2151 | 2153 | "file.int32_snake_case_json_name == 1 && " |
@@ -2176,8 +2178,9 @@ public void eval_withJsonFieldName(@TestParameter RuntimeEnv runtimeEnv) throws |
2176 | 2178 | } |
2177 | 2179 |
|
2178 | 2180 | @Test |
2179 | | - public void eval_withJsonFieldName_fieldsFallBack(@TestParameter RuntimeEnv runtimeEnv) throws Exception { |
2180 | | - Cel cel = runtimeEnv.cel; |
| 2181 | + public void eval_withJsonFieldName_fieldsFallBack(@TestParameter CelRuntimeFlavor runtimeFlavor) |
| 2182 | + throws Exception { |
| 2183 | + Cel cel = setupEnv(runtimeFlavor.builder()); |
2181 | 2184 | CelAbstractSyntaxTree ast = |
2182 | 2185 | cel.compile( |
2183 | 2186 | "dyn(file).int32_snake_case_json_name == 1 && " |
@@ -2206,8 +2209,9 @@ public void eval_withJsonFieldName_fieldsFallBack(@TestParameter RuntimeEnv runt |
2206 | 2209 | } |
2207 | 2210 |
|
2208 | 2211 | @Test |
2209 | | - public void eval_withJsonFieldName_extensionFields(@TestParameter RuntimeEnv runtimeEnv) throws Exception { |
2210 | | - Cel cel = runtimeEnv.cel; |
| 2212 | + public void eval_withJsonFieldName_extensionFields(@TestParameter CelRuntimeFlavor runtimeFlavor) |
| 2213 | + throws Exception { |
| 2214 | + Cel cel = setupEnv(runtimeFlavor.builder()); |
2211 | 2215 | CelAbstractSyntaxTree ast = |
2212 | 2216 | cel.compile( |
2213 | 2217 | "proto.getExt(file, dev.cel.testing.testdata.int64CamelCaseJsonName) == 5 &&" |
@@ -2317,33 +2321,21 @@ private static TypeProvider aliasingProvider(ImmutableMap<String, Type> typeAlia |
2317 | 2321 | }; |
2318 | 2322 | } |
2319 | 2323 |
|
2320 | | - private enum RuntimeEnv { |
2321 | | - LEGACY(setupEnv(CelFactory.standardCelBuilder())), |
2322 | | - PLANNER(setupEnv(CelExperimentalFactory.plannerCelBuilder())) |
2323 | | - ; |
2324 | | - |
2325 | | - private final Cel cel; |
2326 | | - |
2327 | | - private static Cel setupEnv(CelBuilder celBuilder) { |
2328 | | - ExtensionRegistry extensionRegistry = ExtensionRegistry.newInstance(); |
2329 | | - SingleFileExtensionsProto.registerAllExtensions(extensionRegistry); |
2330 | | - return celBuilder |
2331 | | - .addVar("file", StructTypeReference.create(SingleFile.getDescriptor().getFullName())) |
2332 | | - .addMessageTypes(SingleFile.getDescriptor()) |
2333 | | - .addFileTypes(SingleFileExtensionsProto.getDescriptor()) |
2334 | | - .addCompilerLibraries(CelExtensions.protos()) |
2335 | | - .setExtensionRegistry(extensionRegistry) |
2336 | | - .setOptions( |
2337 | | - CelOptions.current() |
2338 | | - .enableJsonFieldNames(true) |
2339 | | - .enableHeterogeneousNumericComparisons(true) |
2340 | | - .enableQuotedIdentifierSyntax(true) |
2341 | | - .build()) |
2342 | | - .build(); |
2343 | | - } |
2344 | | - |
2345 | | - RuntimeEnv(Cel cel) { |
2346 | | - this.cel = cel; |
2347 | | - } |
| 2324 | + private static Cel setupEnv(CelBuilder celBuilder) { |
| 2325 | + ExtensionRegistry extensionRegistry = ExtensionRegistry.newInstance(); |
| 2326 | + SingleFileExtensionsProto.registerAllExtensions(extensionRegistry); |
| 2327 | + return celBuilder |
| 2328 | + .addVar("file", StructTypeReference.create(SingleFile.getDescriptor().getFullName())) |
| 2329 | + .addMessageTypes(SingleFile.getDescriptor()) |
| 2330 | + .addFileTypes(SingleFileExtensionsProto.getDescriptor()) |
| 2331 | + .addCompilerLibraries(CelExtensions.protos()) |
| 2332 | + .setExtensionRegistry(extensionRegistry) |
| 2333 | + .setOptions( |
| 2334 | + CelOptions.current() |
| 2335 | + .enableJsonFieldNames(true) |
| 2336 | + .enableHeterogeneousNumericComparisons(true) |
| 2337 | + .enableQuotedIdentifierSyntax(true) |
| 2338 | + .build()) |
| 2339 | + .build(); |
2348 | 2340 | } |
2349 | 2341 | } |
0 commit comments