#!/usr/bin/ruby

var block = { |x|
    return "hi" if x==1;
    return "hello" if x==2;
}

assert_eq(block.call(1), "hi")
assert_eq(block.call(2), "hello")
assert_eq(block.call(1), "hi")

assert_eq(block.run(1), "hi")
assert_eq(block.run(2), "hello")
assert_eq(block.run(1), "hi")

func foo(x) {

    var b = { |x|
        return "foo" if x==42;
        return nil;
    }

    b(x) if x>10;
    return "func";
}

assert_eq(foo(42), "foo");
assert_eq(foo(21), nil);
assert_eq(foo(1), "func");
assert_eq(foo(42), "foo");

assert_eq([{}(42)], [])
assert_eq([->{}()], [])
assert_eq([func(_n){}(42)], [])
assert_eq([{|_n| }(42)], [])

assert_eq([{_}(42)], [42])
assert_eq([->(n){n}(42)], [42])
assert_eq([func(_){_}(42)], [42])
assert_eq([{|n| n }(42)], [42])

assert_eq({}(), nil)
assert_eq({}(42), nil)

say "** Test passed!"
