mirror of
https://github.com/fenom-template/fenom.git
synced 2023-08-10 21:13:07 +03:00
Reformat. Fix pipe. Add more tests
This commit is contained in:
@ -7,56 +7,74 @@ class MacrosTest extends TestCase
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->tpl("math.tpl", '
|
||||
{macro plus(x, y)}
|
||||
x + y = {$x + $y}
|
||||
{/macro}
|
||||
$this->tpl(
|
||||
"math.tpl",
|
||||
'
|
||||
{macro plus(x, y)}
|
||||
x + y = {$x + $y}
|
||||
{/macro}
|
||||
|
||||
{macro minus(x, y, z=0)}
|
||||
x - y - z = {$x - $y - $z}
|
||||
{/macro}
|
||||
{macro minus(x, y, z=0)}
|
||||
x - y - z = {$x - $y - $z}
|
||||
{/macro}
|
||||
|
||||
{macro multi(x, y)}
|
||||
x * y = {$x * $y}
|
||||
{/macro}
|
||||
{macro multi(x, y)}
|
||||
x * y = {$x * $y}
|
||||
{/macro}
|
||||
|
||||
Math: {macro.plus x=2 y=3}, {macro.minus x=10 y=4}
|
||||
');
|
||||
Math: {macro.plus x=2 y=3}, {macro.minus x=10 y=4}
|
||||
'
|
||||
);
|
||||
|
||||
$this->tpl("import.tpl", '
|
||||
{import "math.tpl"}
|
||||
{import "math.tpl" as math}
|
||||
$this->tpl(
|
||||
"import.tpl",
|
||||
'
|
||||
{import "math.tpl"}
|
||||
{import "math.tpl" as math}
|
||||
|
||||
Imp: {macro.plus x=1 y=2}, {math.minus x=6 y=2 z=1}
|
||||
');
|
||||
Imp: {macro.plus x=1 y=2}, {math.minus x=6 y=2 z=1}
|
||||
'
|
||||
);
|
||||
|
||||
$this->tpl("import_custom.tpl", '
|
||||
{macro minus($x, $y)}
|
||||
new minus macros
|
||||
{/macro}
|
||||
{import [plus, minus] from "math.tpl" as math}
|
||||
$this->tpl(
|
||||
"import_custom.tpl",
|
||||
'
|
||||
{macro minus($x, $y)}
|
||||
new minus macros
|
||||
{/macro}
|
||||
{import [plus, minus] from "math.tpl" as math}
|
||||
|
||||
a: {math.plus x=1 y=2}, {math.minus x=6 y=2 z=1}, {macro.minus x=5 y=3}.
|
||||
');
|
||||
a: {math.plus x=1 y=2}, {math.minus x=6 y=2 z=1}, {macro.minus x=5 y=3}.
|
||||
'
|
||||
);
|
||||
|
||||
$this->tpl("import_miss.tpl", '
|
||||
{import [minus] from "math.tpl" as math}
|
||||
$this->tpl(
|
||||
"import_miss.tpl",
|
||||
'
|
||||
{import [minus] from "math.tpl" as math}
|
||||
|
||||
a: {macro.plus x=5 y=3}.
|
||||
');
|
||||
a: {macro.plus x=5 y=3}.
|
||||
'
|
||||
);
|
||||
|
||||
$this->tpl("macro_recursive.tpl", '{macro factorial(num)}
|
||||
{if $num}
|
||||
{$num} {macro.factorial num=$num-1} {$num}
|
||||
{/if}
|
||||
{/macro}
|
||||
$this->tpl(
|
||||
"macro_recursive.tpl",
|
||||
'{macro factorial(num)}
|
||||
{if $num}
|
||||
{$num} {macro.factorial num=$num-1} {$num}
|
||||
{/if}
|
||||
{/macro}
|
||||
|
||||
{macro.factorial num=10}');
|
||||
{macro.factorial num=10}'
|
||||
);
|
||||
|
||||
$this->tpl("macro_recursive_import.tpl", '
|
||||
{import "macro_recursive.tpl" as math}
|
||||
$this->tpl(
|
||||
"macro_recursive_import.tpl",
|
||||
'
|
||||
{import "macro_recursive.tpl" as math}
|
||||
|
||||
{math.factorial num=10}');
|
||||
{math.factorial num=10}'
|
||||
);
|
||||
}
|
||||
|
||||
public function _testSandbox()
|
||||
@ -65,11 +83,15 @@ class MacrosTest extends TestCase
|
||||
// $this->fenom->compile("macro_recursive.tpl")->display([]);
|
||||
// $this->fenom->flush();
|
||||
// var_dump($this->fenom->fetch("macro_recursive.tpl", []));
|
||||
var_dump($this->fenom->compileCode('{macro factorial(num)}
|
||||
{if $num}
|
||||
{$num} {macro.factorial num=$num-1} {$num}
|
||||
{/if}
|
||||
{/macro}')->getBody());
|
||||
var_dump(
|
||||
$this->fenom->compileCode(
|
||||
'{macro factorial(num)}
|
||||
{if $num}
|
||||
{$num} {macro.factorial num=$num-1} {$num}
|
||||
{/if}
|
||||
{/macro}'
|
||||
)->getBody()
|
||||
);
|
||||
// var_dump($this->fenom->display("macro_recursive_import.tpl", array()));
|
||||
} catch (\Exception $e) {
|
||||
var_dump($e->getMessage() . ": " . $e->getTraceAsString());
|
||||
@ -99,7 +121,10 @@ class MacrosTest extends TestCase
|
||||
{
|
||||
$tpl = $this->fenom->compile('import_custom.tpl');
|
||||
|
||||
$this->assertSame('a: x + y = 3 , x - y - z = 3 , new minus macros .', Modifier::strip($tpl->fetch(array()), true));
|
||||
$this->assertSame(
|
||||
'a: x + y = 3 , x - y - z = 3 , new minus macros .',
|
||||
Modifier::strip($tpl->fetch(array()), true)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -110,7 +135,10 @@ class MacrosTest extends TestCase
|
||||
{
|
||||
$tpl = $this->fenom->compile('import_miss.tpl');
|
||||
|
||||
$this->assertSame('a: x + y = 3 , x - y - z = 3 , new minus macros .', Modifier::strip($tpl->fetch(array()), true));
|
||||
$this->assertSame(
|
||||
'a: x + y = 3 , x - y - z = 3 , new minus macros .',
|
||||
Modifier::strip($tpl->fetch(array()), true)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user