|
21 | 21 | import static dev.cel.common.CelOverloadDecl.newMemberOverload; |
22 | 22 | import static org.junit.Assert.assertThrows; |
23 | 23 |
|
| 24 | +import com.google.common.primitives.UnsignedLong; |
| 25 | +import com.google.protobuf.UInt64Value; |
24 | 26 | import dev.cel.expr.CheckedExpr; |
25 | 27 | import dev.cel.expr.Constant; |
26 | 28 | import dev.cel.expr.Decl; |
@@ -2193,6 +2195,74 @@ public void toBuilder_isImmutable() { |
2193 | 2195 | assertThat(newRuntimeBuilder).isNotEqualTo(celImpl.toRuntimeBuilder()); |
2194 | 2196 | } |
2195 | 2197 |
|
| 2198 | + @Test |
| 2199 | + public void mapSelection_uintWrapper() throws Exception { |
| 2200 | + Cel cel = CelFactory.standardCelBuilder() |
| 2201 | + .addVar("args", MapType.create(SimpleType.DYN, SimpleType.DYN)) |
| 2202 | + .setContainer(CelContainer.ofName("cel.expr.conformance.proto3")) |
| 2203 | + .addMessageTypes(TestAllTypes.getDescriptor()) |
| 2204 | + .build(); |
| 2205 | + |
| 2206 | + CelAbstractSyntaxTree ast = cel.compile("args.i[1]").getAst(); |
| 2207 | + |
| 2208 | + Object result = cel.createProgram(ast).eval( |
| 2209 | + ImmutableMap.of("args", |
| 2210 | + ImmutableMap.of("i", ImmutableMap.of(1L, UInt64Value.of(123L))))); |
| 2211 | + |
| 2212 | + assertThat(result).isEqualTo(UnsignedLong.valueOf(123L)); |
| 2213 | + } |
| 2214 | + |
| 2215 | + @Test |
| 2216 | + public void messageCreation_listContainsUintWrapperCreation() throws Exception { |
| 2217 | + Cel cel = CelFactory.standardCelBuilder() |
| 2218 | + .addVar("args", MapType.create(SimpleType.DYN, SimpleType.DYN)) |
| 2219 | + .setContainer(CelContainer.ofName("cel.expr.conformance.proto3")) |
| 2220 | + .addMessageTypes(TestAllTypes.getDescriptor()) |
| 2221 | + .build(); |
| 2222 | + |
| 2223 | + CelAbstractSyntaxTree ast = cel.compile("TestAllTypes{repeated_uint64: [google.protobuf.UInt64Value{value: 123u}]}").getAst(); |
| 2224 | + |
| 2225 | + Object result = cel.createProgram(ast).eval( |
| 2226 | + ImmutableMap.of("args", |
| 2227 | + ImmutableMap.of("i", ImmutableList.of(UInt64Value.of(123L))))); |
| 2228 | + |
| 2229 | + assertThat(result).isEqualTo(TestAllTypes.newBuilder().addRepeatedUint64(123L).build()); |
| 2230 | + } |
| 2231 | + |
| 2232 | + @Test |
| 2233 | + public void messageCreation_listContainsUintWrapper() throws Exception { |
| 2234 | + Cel cel = CelFactory.standardCelBuilder() |
| 2235 | + .addVar("args", MapType.create(SimpleType.DYN, SimpleType.DYN)) |
| 2236 | + .setContainer(CelContainer.ofName("cel.expr.conformance.proto3")) |
| 2237 | + .addMessageTypes(TestAllTypes.getDescriptor()) |
| 2238 | + .build(); |
| 2239 | + |
| 2240 | + CelAbstractSyntaxTree ast = cel.compile("TestAllTypes{repeated_uint64: args.i}").getAst(); |
| 2241 | + |
| 2242 | + Object result = cel.createProgram(ast).eval( |
| 2243 | + ImmutableMap.of("args", |
| 2244 | + ImmutableMap.of("i", ImmutableList.of(UInt64Value.of(123L))))); |
| 2245 | + |
| 2246 | + assertThat(result).isEqualTo(TestAllTypes.newBuilder().addRepeatedUint64(123L).build()); |
| 2247 | + } |
| 2248 | + |
| 2249 | + @Test |
| 2250 | + public void messageCreation_mapContainsUintWrapper() throws Exception { |
| 2251 | + Cel cel = CelFactory.standardCelBuilder() |
| 2252 | + .addVar("args", MapType.create(SimpleType.DYN, SimpleType.DYN)) |
| 2253 | + .setContainer(CelContainer.ofName("cel.expr.conformance.proto3")) |
| 2254 | + .addMessageTypes(TestAllTypes.getDescriptor()) |
| 2255 | + .build(); |
| 2256 | + |
| 2257 | + CelAbstractSyntaxTree ast = cel.compile("TestAllTypes{map_int64_uint64 : args.i}").getAst(); |
| 2258 | + |
| 2259 | + Object result = cel.createProgram(ast).eval( |
| 2260 | + ImmutableMap.of("args", |
| 2261 | + ImmutableMap.of("i", ImmutableMap.of(1L, UInt64Value.of(123L))))); |
| 2262 | + |
| 2263 | + assertThat(result).isEqualTo(TestAllTypes.newBuilder().putMapInt64Uint64(1L, 123L).build()); |
| 2264 | + } |
| 2265 | + |
2196 | 2266 | private static TypeProvider aliasingProvider(ImmutableMap<String, Type> typeAliases) { |
2197 | 2267 | return new TypeProvider() { |
2198 | 2268 | @Override |
|
0 commit comments