mirror of
https://github.com/fenom-template/fenom.git
synced 2023-08-10 21:13:07 +03:00
Add recursive macros support (#28)
This commit is contained in:
@@ -42,6 +42,25 @@ class MacrosTest extends TestCase {
|
||||
|
||||
a: {macro.plus x=5 y=3}.
|
||||
');
|
||||
|
||||
$this->tpl("macro_recursive.tpl", '{macro factorial(num)}
|
||||
{if $num}
|
||||
{$num} {macro.factorial num=$num-1}
|
||||
{/if}
|
||||
{/macro}
|
||||
|
||||
{macro.factorial num=10}');
|
||||
}
|
||||
|
||||
public function _testSandbox() {
|
||||
try {
|
||||
$this->fenom->compile("macro_recursive.tpl");
|
||||
$this->fenom->flush();
|
||||
var_dump($this->fenom->fetch("macro_recursive.tpl", []));
|
||||
} catch(\Exception $e) {
|
||||
var_dump($e->getMessage().": ".$e->getTraceAsString());
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
public function testMacros() {
|
||||
@@ -72,4 +91,11 @@ class MacrosTest extends TestCase {
|
||||
|
||||
$this->assertSame('a: x + y = 3 , x - y - z = 3 , new minus macros .', Modifier::strip($tpl->fetch(array()), true));
|
||||
}
|
||||
|
||||
public function testRecursive() {
|
||||
$this->fenom->compile('macro_recursive.tpl');
|
||||
$this->fenom->flush();
|
||||
$tpl = $this->fenom->getTemplate('macro_recursive.tpl');
|
||||
$this->assertSame("10 9 8 7 6 5 4 3 2 1", Modifier::strip($tpl->fetch(array()), true));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user