mirror of
https://github.com/fenom-template/fenom.git
synced 2023-08-10 21:13:07 +03:00
proper fix for array params (now works with both positional and named params), tests
This commit is contained in:
parent
eb1fa83174
commit
a2b5b43cb1
@ -644,6 +644,10 @@ class Template extends Render {
|
|||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} elseif($tokens->is('[')) {
|
||||||
|
$_exp .= $this->parseArray($tokens);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1126,11 +1130,7 @@ class Template extends Render {
|
|||||||
}
|
}
|
||||||
if($tokens->is("=")) {
|
if($tokens->is("=")) {
|
||||||
$tokens->next();
|
$tokens->next();
|
||||||
if ($tokens->is('[')) {
|
|
||||||
$params[ $key ] = $this->parseArray($tokens);
|
|
||||||
} else {
|
|
||||||
$params[ $key ] = $this->parseExp($tokens);
|
$params[ $key ] = $this->parseExp($tokens);
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
$params[ $key ] = 'true';
|
$params[ $key ] = 'true';
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,7 @@ class FunctionsTest extends TestCase {
|
|||||||
$this->tpl('function_default_param_empty_array.tpl', '{sum}');
|
$this->tpl('function_default_param_empty_array.tpl', '{sum}');
|
||||||
$this->tpl('function_default_param_const.tpl', '{inc a=1}');
|
$this->tpl('function_default_param_const.tpl', '{inc a=1}');
|
||||||
$this->tpl('function_array_param.tpl', '{sum of=[1, 2, 3, 4, 5]}');
|
$this->tpl('function_array_param.tpl', '{sum of=[1, 2, 3, 4, 5]}');
|
||||||
|
$this->tpl('function_array_param_pos.tpl', '{sum [1, 2, 3, 4, 5]}');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFunctionWithParams() {
|
public function testFunctionWithParams() {
|
||||||
@ -56,9 +57,14 @@ class FunctionsTest extends TestCase {
|
|||||||
$this->assertEquals('2', $output);
|
$this->assertEquals('2', $output);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFunctionWithArrayParam() {
|
public function testFunctionWithArrayNamedParam() {
|
||||||
$output = $this->fenom->fetch('function_array_param.tpl');
|
$output = $this->fenom->fetch('function_array_param.tpl');
|
||||||
$this->assertEquals('15', $output);
|
$this->assertEquals('15', $output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testFunctionWithArrayPositionalParam() {
|
||||||
|
$output = $this->fenom->fetch('function_array_param_pos.tpl');
|
||||||
|
$this->assertEquals('15', $output);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user