@@ -1005,6 +1005,48 @@ func TestContextEval(t *testing.T) {
10051005 }
10061006}
10071007
1008+ func TestContextEvalUnknowns (t * testing.T ) {
1009+ env , err := NewEnv (
1010+ Variable ("groups" , ListType (IntType )),
1011+ Variable ("id" , IntType ),
1012+ )
1013+ if err != nil {
1014+ t .Fatalf ("NewEnv() failed: %v" , err )
1015+ }
1016+
1017+ pvars , err := PartialVars (
1018+ map [string ]any {
1019+ "groups" : []int {1 , 2 , 3 },
1020+ },
1021+ AttributePattern ("id" ),
1022+ )
1023+ if err != nil {
1024+ t .Fatalf ("PartialVars() failed: %v" , err )
1025+ }
1026+
1027+ ast , iss := env .Compile (`groups.exists(t, t == id)` )
1028+ if iss .Err () != nil {
1029+ t .Fatalf ("env.Compile() failed: %v" , iss .Err ())
1030+ }
1031+
1032+ prg , err := env .Program (ast , EvalOptions (OptTrackState , OptPartialEval ), InterruptCheckFrequency (100 ))
1033+ if err != nil {
1034+ t .Fatalf ("env.Program() failed: %v" , err )
1035+ }
1036+
1037+ out , _ , err := prg .Eval (pvars )
1038+ if err != nil {
1039+ t .Fatalf ("prg.Eval() failed: %v" , err )
1040+ }
1041+ ctxOut , _ , err := prg .ContextEval (context .Background (), pvars )
1042+ if err != nil {
1043+ t .Fatalf ("prg.ContextEval() failed: %v" , err )
1044+ }
1045+ if ! reflect .DeepEqual (out , ctxOut ) {
1046+ t .Errorf ("got %v, wanted %v" , out , ctxOut )
1047+ }
1048+ }
1049+
10081050func BenchmarkContextEval (b * testing.B ) {
10091051 env := testEnv (b ,
10101052 Variable ("items" , ListType (IntType )),
0 commit comments