use of org.projectnessie.cel.interpreter.Activation.PartialActivation in project cel-java by projectnessie.
the class AttributePatternsTest method crossReference.
@Test
void crossReference() {
TypeRegistry reg = newRegistry();
AttributeFactory fac = newPartialAttributeFactory(Container.defaultContainer, reg, reg);
NamespacedAttribute a = fac.absoluteAttribute(1, "a");
NamespacedAttribute b = fac.absoluteAttribute(2, "b");
a.addQualifier(b);
// Ensure that var a[b], the dynamic index into var 'a' is the unknown value
// returned from attribute resolution.
PartialActivation partVars = newPartialActivation(mapOf("a", new long[] { 1L, 2L }), newAttributePattern("b"));
Object val = a.resolve(partVars);
assertThat(val).isEqualTo(unknownOf(2));
// Ensure that a[b], the dynamic index into var 'a' is the unknown value
// returned from attribute resolution. Note, both 'a' and 'b' have unknown attribute
// patterns specified. This changes the evaluation behavior slightly, but the end
// result is the same.
partVars = newPartialActivation(mapOf("a", new long[] { 1L, 2L }), newAttributePattern("a").qualInt(0), newAttributePattern("b"));
val = a.resolve(partVars);
assertThat(val).isEqualTo(unknownOf(2));
// Note, that only 'a[0].c' will result in an unknown result since both 'a' and 'b'
// have values. However, since the attribute being pattern matched is just 'a.b',
// the outcome will indicate that 'a[b]' is unknown.
partVars = newPartialActivation(mapOf("a", new long[] { 1, 2 }, "b", 0), newAttributePattern("a").qualInt(0).qualString("c"));
val = a.resolve(partVars);
assertThat(val).isEqualTo(unknownOf(2));
// Test a positive case that returns a valid value even though the attribugte factory
// is the partial attribute factory.
partVars = newPartialActivation(mapOf("a", new long[] { 1, 2 }, "b", 0));
val = a.resolve(partVars);
assertThat(val).isEqualTo(1L);
// Ensure the unknown attribute id moves when the attribute becomes more specific.
partVars = newPartialActivation(mapOf("a", new long[] { 1, 2 }, "b", 0), newAttributePattern("a").qualInt(0).qualString("c"));
// Qualify a[b] with 'c', a[b].c
Qualifier c = fac.newQualifier(null, 3, "c");
a.addQualifier(c);
// The resolve step should return unknown
val = a.resolve(partVars);
assertThat(val).isEqualTo(unknownOf(3));
}
Aggregations