use of com.google.api.expr.test.v1.proto3.TestAllTypesProto.TestAllTypes in project cel-java by projectnessie.
the class AttributesTest method benchmarkResolverFieldQualifier.
@Test
void benchmarkResolverFieldQualifier() {
TestAllTypes msg = TestAllTypes.newBuilder().setSingleNestedMessage(NestedMessage.newBuilder().setBb(123)).build();
TypeRegistry reg = newRegistry(msg);
AttributeFactory attrs = newAttributeFactory(Container.defaultContainer, reg, reg);
Activation vars = newActivation(mapOf("msg", msg));
NamespacedAttribute attr = attrs.absoluteAttribute(1, "msg");
Type opType = reg.findType("google.api.expr.test.v1.proto3.TestAllTypes");
assertThat(opType).isNotNull();
Type fieldType = reg.findType("google.api.expr.test.v1.proto3.TestAllTypes.NestedMessage");
assertThat(fieldType).isNotNull();
attr.addQualifier(makeQualifier(attrs, opType.getType(), 2, "single_nested_message"));
attr.addQualifier(makeQualifier(attrs, fieldType.getType(), 3, "bb"));
// Note: migrated to JMH
}
use of com.google.api.expr.test.v1.proto3.TestAllTypesProto.TestAllTypes in project cel-java by projectnessie.
the class InterpreterTest method setProto2PrimitiveFields.
@Test
void setProto2PrimitiveFields() {
// Test the use of proto2 primitives within object construction.
Source src = newTextSource("input == TestAllTypes{\n" + " single_int32: 1,\n" + " single_int64: 2,\n" + " single_uint32: 3u,\n" + " single_uint64: 4u,\n" + " single_float: -3.3,\n" + " single_double: -2.2,\n" + " single_string: \"hello world\",\n" + " single_bool: true\n" + "}");
ParseResult parsed = Parser.parseAllMacros(src);
assertThat(parsed.hasErrors()).withFailMessage(parsed.getErrors()::toDisplayString).isFalse();
Container cont = testContainer("google.api.expr.test.v1.proto2");
TypeRegistry reg = newRegistry(com.google.api.expr.test.v1.proto2.TestAllTypesProto.TestAllTypes.getDefaultInstance());
CheckerEnv env = newStandardCheckerEnv(cont, reg);
env.add(singletonList(Decls.newVar("input", Decls.newObjectType("google.api.expr.test.v1.proto2.TestAllTypes"))));
CheckResult checkResult = Checker.Check(parsed, src, env);
if (parsed.hasErrors()) {
throw new IllegalArgumentException(parsed.getErrors().toDisplayString());
}
AttributeFactory attrs = newAttributeFactory(cont, reg, reg);
Interpreter i = newStandardInterpreter(cont, reg, reg, attrs);
Interpretable eval = i.newInterpretable(checkResult.getCheckedExpr());
int one = 1;
long two = 2L;
int three = 3;
long four = 4L;
float five = -3.3f;
double six = -2.2d;
String str = "hello world";
boolean truth = true;
com.google.api.expr.test.v1.proto2.TestAllTypesProto.TestAllTypes input = com.google.api.expr.test.v1.proto2.TestAllTypesProto.TestAllTypes.newBuilder().setSingleInt32(one).setSingleInt64(two).setSingleUint32(three).setSingleUint64(four).setSingleFloat(five).setSingleDouble(six).setSingleString(str).setSingleBool(truth).build();
Activation vars = newActivation(mapOf("input", reg.nativeToValue(input)));
Val result = eval.eval(vars);
assertThat(result.value()).isInstanceOf(Boolean.class);
boolean got = (Boolean) result.value();
assertThat(got).isTrue();
}
use of com.google.api.expr.test.v1.proto3.TestAllTypesProto.TestAllTypes in project cel-java by projectnessie.
the class FieldDescriptionTest method isSet.
@ParameterizedTest
@MethodSource("isSetTestCases")
void isSet(TestCase tc) {
Db pbdb = newDb();
TestAllTypes msg = TestAllTypes.getDefaultInstance();
String msgName = msg.getDescriptorForType().getFullName();
pbdb.registerMessage(msg);
PbTypeDescription td = pbdb.describeType(msgName);
assertThat(td).isNotNull();
FieldDescription f = td.fieldByName(tc.field);
assertThat(f).isNotNull();
assertThat(f.isSet(tc.msg)).isEqualTo(tc.isSet);
}
use of com.google.api.expr.test.v1.proto3.TestAllTypesProto.TestAllTypes in project cel-java by projectnessie.
the class FieldDescriptionTest method fieldDescription.
@Test
void fieldDescription() {
Db pbdb = newDb();
NestedTestAllTypes msg = NestedTestAllTypes.getDefaultInstance();
String msgName = msg.getDescriptorForType().getFullName();
pbdb.registerMessage(msg);
PbTypeDescription td = pbdb.describeType(msgName);
assertThat(td).isNotNull();
FieldDescription fd = td.fieldByName("payload");
assertThat(fd).isNotNull();
assertThat(fd).extracting(FieldDescription::name).isEqualTo("payload");
assertThat(fd).extracting(FieldDescription::isOneof).isEqualTo(false);
assertThat(fd).extracting(FieldDescription::isMap).isEqualTo(false);
assertThat(fd).extracting(FieldDescription::isMessage).isEqualTo(true);
assertThat(fd).extracting(FieldDescription::isEnum).isEqualTo(false);
assertThat(fd).extracting(FieldDescription::isList).isEqualTo(false);
// Access the field by its Go struct name and check to see that it's index
// matches the one determined by the TypeDescription utils.
Type got = fd.checkedType();
Type wanted = Type.newBuilder().setMessageType("google.api.expr.test.v1.proto3.TestAllTypes").build();
assertThat(got).isEqualTo(wanted);
}
use of com.google.api.expr.test.v1.proto3.TestAllTypesProto.TestAllTypes in project cel-java by projectnessie.
the class PbTypeDescriptionTest method checkedType.
@Test
void checkedType() {
Db pbdb = newDb();
TestAllTypes msg = TestAllTypes.getDefaultInstance();
String msgName = msg.getDescriptorForType().getFullName();
pbdb.registerMessage(msg);
PbTypeDescription td = pbdb.describeType(msgName);
assertThat(td).isNotNull();
FieldDescription field = td.fieldByName("map_string_string");
assertThat(field).isNotNull();
Type mapType = Decls.newMapType(Decls.String, Decls.String);
assertThat(field.checkedType()).isEqualTo(mapType);
field = td.fieldByName("repeated_nested_message");
assertThat(field).isNotNull();
Type listType = Decls.newListType(Decls.newObjectType("google.api.expr.test.v1.proto3.TestAllTypes.NestedMessage"));
assertThat(field.checkedType()).isEqualTo(listType);
}
Aggregations