Search in sources :

Example 16 with TypeRegistry

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

the class ProviderTest method unsupportedConversion.

@Test
void unsupportedConversion() {
    TypeRegistry reg = newEmptyRegistry();
    Val val = reg.nativeToValue(new nonConvertible());
    assertThat(val).matches(Err::isError);
}
Also used : Val(org.projectnessie.cel.common.types.ref.Val) TypeRegistry(org.projectnessie.cel.common.types.ref.TypeRegistry) ProtoTypeRegistry(org.projectnessie.cel.common.types.pb.ProtoTypeRegistry) Test(org.junit.jupiter.api.Test)

Example 17 with TypeRegistry

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

the class ProviderTest method expectNativeToValue.

static void expectNativeToValue(Object in, Val out) {
    TypeRegistry reg = newRegistry(ParsedExpr.getDefaultInstance());
    Val val = reg.nativeToValue(in);
    assertThat(val).matches(v -> !Err.isError(v));
    assertThat(val.equal(out)).isSameAs(True);
}
Also used : Val(org.projectnessie.cel.common.types.ref.Val) TypeRegistry(org.projectnessie.cel.common.types.ref.TypeRegistry) ProtoTypeRegistry(org.projectnessie.cel.common.types.pb.ProtoTypeRegistry)

Example 18 with TypeRegistry

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

the class AttributesTest method attributesAbsoluteAttr.

@Test
void attributesAbsoluteAttr() {
    TypeRegistry reg = newRegistry();
    Container cont = newContainer(Container.name("acme.ns"));
    AttributeFactory attrs = newAttributeFactory(cont, reg, reg);
    Activation vars = newActivation(mapOf("acme.a", mapOf("b", mapOf(4L, mapOf(false, "success")))));
    // acme.a.b[4][false]
    NamespacedAttribute attr = attrs.absoluteAttribute(1, "acme.a");
    Qualifier qualB = attrs.newQualifier(null, 2, "b");
    Qualifier qual4 = attrs.newQualifier(null, 3, 4L);
    Qualifier qualFalse = attrs.newQualifier(null, 4, false);
    attr.addQualifier(qualB);
    attr.addQualifier(qual4);
    attr.addQualifier(qualFalse);
    Object out = attr.resolve(vars);
    assertThat(out).isEqualTo("success");
    assertThat(estimateCost(attr)).extracting("min", "max").containsExactly(1L, 1L);
}
Also used : Container.newContainer(org.projectnessie.cel.common.containers.Container.newContainer) Container(org.projectnessie.cel.common.containers.Container) NamespacedAttribute(org.projectnessie.cel.interpreter.AttributeFactory.NamespacedAttribute) AttributePattern.newPartialAttributeFactory(org.projectnessie.cel.interpreter.AttributePattern.newPartialAttributeFactory) AttributeFactory.newAttributeFactory(org.projectnessie.cel.interpreter.AttributeFactory.newAttributeFactory) Activation.emptyActivation(org.projectnessie.cel.interpreter.Activation.emptyActivation) Activation.newPartialActivation(org.projectnessie.cel.interpreter.Activation.newPartialActivation) Activation.newActivation(org.projectnessie.cel.interpreter.Activation.newActivation) Qualifier(org.projectnessie.cel.interpreter.AttributeFactory.Qualifier) TypeRegistry(org.projectnessie.cel.common.types.ref.TypeRegistry) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 19 with TypeRegistry

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

the class JacksonRegistryTest method copy.

@Test
void copy() {
    TypeRegistry reg = JacksonRegistry.newRegistry();
    assertThat(reg).extracting(TypeRegistry::copy).isSameAs(reg);
}
Also used : TypeRegistry(org.projectnessie.cel.common.types.ref.TypeRegistry) MetaTest(org.projectnessie.cel.types.jackson.types.MetaTest) Test(org.junit.jupiter.api.Test)

Example 20 with TypeRegistry

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

the class JacksonRegistryTest method registerType.

@Test
void registerType() {
    TypeRegistry reg = JacksonRegistry.newRegistry();
    assertThatThrownBy(() -> reg.registerType(IntT.IntType)).isInstanceOf(UnsupportedOperationException.class);
}
Also used : TypeRegistry(org.projectnessie.cel.common.types.ref.TypeRegistry) MetaTest(org.projectnessie.cel.types.jackson.types.MetaTest) 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