#!/usr/bin/ruby
#
## Eval in an environment
#
func eval_with_x(code, x, y) {
var f = eval(code);
x = y;
eval(code) - f;
}
assert_eq(24, eval_with_x('2 ** x', 3, 5));
#
## Eval with function parameter
#
func test(z) {
z; # use z once to avoid the warning
eval("z+2");
}
assert_eq(42, test(40));
#
## Simple with variables
#
var (a, b) = (-5, 7);
assert_eq(abs(a * b), eval('abs(a * b)'));
assert_eq(eval '(a * b).abs', 35);
#
## Nested eval
#
assert_eq(eval '42 + eval("1 + eval(%q/1 + 1/)")', 45);
#
## All done
#
say "** Test passed!";