@@ -1276,6 +1276,50 @@ func TestCompile_exposed_error(t *testing.T) {
12761276 require .Equal (t , `{"Line":1,"Column":2,"Message":"invalid operation: == (mismatched types int and bool)","Snippet":"\n | 1 == true\n | ..^"}` , string (b ))
12771277}
12781278
1279+ func TestCompile_deref (t * testing.T ) {
1280+ i := 1
1281+ env := map [string ]interface {}{
1282+ "i" : & i ,
1283+ "map" : map [string ]interface {}{
1284+ "i" : & i ,
1285+ },
1286+ }
1287+ {
1288+ // With specified env, OpDeref added and == works as expected.
1289+ program , err := expr .Compile (`i == 1 && map.i == 1` , expr .Env (env ))
1290+ require .NoError (t , err )
1291+
1292+ env ["any" ] = & i
1293+ out , err := expr .Run (program , env )
1294+ require .NoError (t , err )
1295+ require .Equal (t , true , out )
1296+ }
1297+ {
1298+ // Compile without expr.Env() also works as expected,
1299+ // and should add OpDeref automatically.
1300+ program , err := expr .Compile (`i == 1 && map.i == 1` )
1301+ require .NoError (t , err )
1302+
1303+ out , err := expr .Run (program , env )
1304+ require .NoError (t , err )
1305+ require .Equal (t , true , out )
1306+ }
1307+ }
1308+
1309+ func TestEval_deref (t * testing.T ) {
1310+ i := 1
1311+ env := map [string ]interface {}{
1312+ "i" : & i ,
1313+ "map" : map [string ]interface {}{
1314+ "i" : & i ,
1315+ },
1316+ }
1317+
1318+ out , err := expr .Eval (`i == 1 && map.i == 1` , env )
1319+ require .NoError (t , err )
1320+ require .Equal (t , true , out )
1321+ }
1322+
12791323func TestAsBool_exposed_error (t * testing.T ) {
12801324 _ , err := expr .Compile (`42` , expr .AsBool ())
12811325 require .Error (t , err )
0 commit comments