function testLambdaContext() { $m = $this->m; $res = $m->render("{{foo}}", array("a" => 42, "foo" => function () { $ctx = Proust\Context::GetContext(); return $ctx['a']; })); $this->assertEqual($res, 42); $res = $m->render("{{#foo}}{{a}}{{/foo}}", array("a" => 42, "foo" => function ($text) { return $text; })); $this->assertEqual($res, 42); $res = $m->render("{{#foo}}{{a}}{{/foo}}", array("a" => 42, "foo" => function ($text) { return $text . $text; })); $this->assertEqual($res, 4242); $res = $m->render("{{#foo}}{{a}}{{/foo}}", array("b" => 42, "a" => 100, "c" => "{{b}}", "foo" => function ($text) { $ctx = Proust\Context::GetContext(); $c = $ctx['c']; return $text . $c . $text; })); $this->assertEqual($res, 10042100); }
function testLambda() { $ctx = $this->ctx; $func = function () { return 4; }; $ctx->push(array("a" => $func)); $res = $ctx->fetch("a", false, null); $this->assertEqual($res, $func); // immediate evaluation $res = $ctx->fetch("a", true, null); $this->assertEqual($res, 4); // access context $ctx->push(array("d" => 17, "b" => function () { $ctx = Proust\Context::GetContext(); return $ctx["d"] + 5; })); $res = $ctx->fetch("b", true, null); $this->assertEqual($res, 22); }