Search in sources :

Example 16 with EvalResult

use of org.projectnessie.cel.Program.EvalResult in project cel-java by projectnessie.

the class CELTest method residualAst_Modified.

@Test
void residualAst_Modified() {
    Env e = newEnv(declarations(Decls.newVar("x", Decls.newMapType(Decls.String, Decls.Int)), Decls.newVar("y", Decls.Int)));
    AstIssuesTuple astIss = e.parse("x == y");
    Program prg = e.program(astIss.getAst(), evalOptions(OptTrackState, OptPartialEval));
    for (int x = 123; x < 456; x++) {
        PartialActivation vars = partialVars(mapOf("x", x), attributePattern("y"));
        EvalResult outDet = prg.eval(vars);
        assertThat(outDet.getVal()).matches(UnknownT::isUnknown);
        Ast residual = e.residualAst(astIss.getAst(), outDet.getEvalDetails());
        String orig = astToString(astIss.getAst());
        assertThat(orig).isEqualTo("x == y");
        String expr = astToString(residual);
        String want = String.format("%d == y", x);
        assertThat(expr).isEqualTo(want);
    }
}
Also used : UnknownT(org.projectnessie.cel.common.types.UnknownT) PartialActivation(org.projectnessie.cel.interpreter.Activation.PartialActivation) CEL.parsedExprToAst(org.projectnessie.cel.CEL.parsedExprToAst) CEL.checkedExprToAst(org.projectnessie.cel.CEL.checkedExprToAst) EvalResult(org.projectnessie.cel.Program.EvalResult) CEL.astToString(org.projectnessie.cel.CEL.astToString) Env.newEnv(org.projectnessie.cel.Env.newEnv) Env.newCustomEnv(org.projectnessie.cel.Env.newCustomEnv) AstIssuesTuple(org.projectnessie.cel.Env.AstIssuesTuple) Test(org.junit.jupiter.api.Test)

Aggregations

EvalResult (org.projectnessie.cel.Program.EvalResult)16 Env.newCustomEnv (org.projectnessie.cel.Env.newCustomEnv)15 Env.newEnv (org.projectnessie.cel.Env.newEnv)15 Test (org.junit.jupiter.api.Test)14 AstIssuesTuple (org.projectnessie.cel.Env.AstIssuesTuple)14 CEL.checkedExprToAst (org.projectnessie.cel.CEL.checkedExprToAst)7 CEL.parsedExprToAst (org.projectnessie.cel.CEL.parsedExprToAst)7 CEL.astToString (org.projectnessie.cel.CEL.astToString)6 Val (org.projectnessie.cel.common.types.ref.Val)5 CheckedExpr (com.google.api.expr.v1alpha1.CheckedExpr)4 Expr (com.google.api.expr.v1alpha1.Expr)4 ParsedExpr (com.google.api.expr.v1alpha1.ParsedExpr)4 CEL.astToCheckedExpr (org.projectnessie.cel.CEL.astToCheckedExpr)4 CEL.astToParsedExpr (org.projectnessie.cel.CEL.astToParsedExpr)4 UnknownT (org.projectnessie.cel.common.types.UnknownT)4 PartialActivation (org.projectnessie.cel.interpreter.Activation.PartialActivation)4 Type (com.google.api.expr.v1alpha1.Type)3 TypeRegistry (org.projectnessie.cel.common.types.ref.TypeRegistry)3 EvalState (org.projectnessie.cel.interpreter.EvalState)3 Macro (org.projectnessie.cel.parser.Macro)3