Search in sources :

Example 51 with TypeRegistry

use of org.projectnessie.cel.common.types.ref.TypeRegistry in project cel-java by projectnessie.

the class PbObjectTest method protoObjectGet.

@Test
void protoObjectGet() {
    TypeRegistry reg = newRegistry(Expr.getDefaultInstance());
    ParsedExpr msg = ParsedExpr.newBuilder().setSourceInfo(SourceInfo.newBuilder().addAllLineOffsets(Arrays.asList(1, 2, 3)).build()).build();
    Val obj = reg.nativeToValue(msg);
    assertThat(obj).isInstanceOf(ObjectT.class);
    ObjectT objVal = (ObjectT) obj;
    assertThat(objVal.get(stringOf("source_info")).equal(reg.nativeToValue(msg.getSourceInfo()))).isSameAs(True);
    assertThat(objVal.get(stringOf("expr")).equal(reg.nativeToValue(Expr.getDefaultInstance()))).isSameAs(True);
    assertThat(objVal.get(stringOf("bad_field"))).matches(Err::isError);
    assertThat(objVal.get(IntZero)).matches(Err::isError);
}
Also used : Val(org.projectnessie.cel.common.types.ref.Val) Err(org.projectnessie.cel.common.types.Err) ParsedExpr(com.google.api.expr.v1alpha1.ParsedExpr) ObjectT(org.projectnessie.cel.common.types.ObjectT) TypeRegistry(org.projectnessie.cel.common.types.ref.TypeRegistry) Test(org.junit.jupiter.api.Test)

Aggregations

TypeRegistry (org.projectnessie.cel.common.types.ref.TypeRegistry)51 Test (org.junit.jupiter.api.Test)40 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)26 AttributePattern.newPartialAttributeFactory (org.projectnessie.cel.interpreter.AttributePattern.newPartialAttributeFactory)26 AttributeFactory.newAttributeFactory (org.projectnessie.cel.interpreter.AttributeFactory.newAttributeFactory)25 Activation.newActivation (org.projectnessie.cel.interpreter.Activation.newActivation)21 Activation.newPartialActivation (org.projectnessie.cel.interpreter.Activation.newPartialActivation)21 Val (org.projectnessie.cel.common.types.ref.Val)20 NamespacedAttribute (org.projectnessie.cel.interpreter.AttributeFactory.NamespacedAttribute)20 Activation.emptyActivation (org.projectnessie.cel.interpreter.Activation.emptyActivation)19 Qualifier (org.projectnessie.cel.interpreter.AttributeFactory.Qualifier)16 Container (org.projectnessie.cel.common.containers.Container)14 Container.newContainer (org.projectnessie.cel.common.containers.Container.newContainer)12 Attribute (org.projectnessie.cel.interpreter.AttributeFactory.Attribute)12 MethodSource (org.junit.jupiter.params.provider.MethodSource)11 ProtoTypeRegistry (org.projectnessie.cel.common.types.pb.ProtoTypeRegistry)10 ParseResult (org.projectnessie.cel.parser.Parser.ParseResult)10 Source (org.projectnessie.cel.common.Source)9 Interpreter.newStandardInterpreter (org.projectnessie.cel.interpreter.Interpreter.newStandardInterpreter)9 Source.newTextSource (org.projectnessie.cel.common.Source.newTextSource)8