mirror of
https://github.com/fenom-template/fenom.git
synced 2023-08-10 21:13:07 +03:00
Fix ternary operator
This commit is contained in:
parent
e51eb9f3d8
commit
43925ae640
@ -907,9 +907,7 @@ class Template extends Render
|
||||
}
|
||||
} else {
|
||||
$expr1 = $this->parseExp($tokens, true);
|
||||
if (!$tokens->is(":")) {
|
||||
throw new UnexpectedTokenException($tokens, null, "ternary operator");
|
||||
}
|
||||
$tokens->need(':')->skip();
|
||||
$expr2 = $this->parseExp($tokens, true);
|
||||
if ($empty) {
|
||||
return '(empty(' . $var . ') ? ' . $expr2 . ' : ' . $expr1 . ')';
|
||||
|
@ -404,7 +404,11 @@ class TemplateTest extends TestCase
|
||||
array('{if $nonempty.double!} right {/if}', $a),
|
||||
array('{if $nonempty.bool!} right {/if}', $a),
|
||||
// ! ... : ...
|
||||
array('{$unexists ! "no way" : "right"}', $a),
|
||||
array('{$a ! "right" : "no way"}', $a),
|
||||
// !: ...
|
||||
array('{$unexists !: "right"}', $a),
|
||||
array('{$a !: "right"}', $a, '1'),
|
||||
);
|
||||
}
|
||||
|
||||
@ -673,7 +677,7 @@ class TemplateTest extends TestCase
|
||||
public function _testSandbox()
|
||||
{
|
||||
try {
|
||||
var_dump($this->fenom->compileCode('{if 0 is empty} block1 {else} block2 {/if}')->getBody());
|
||||
var_dump($this->fenom->compileCode('{$a!"no way":"right"}')->getBody());
|
||||
} catch (\Exception $e) {
|
||||
print_r($e->getMessage() . "\n" . $e->getTraceAsString());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user