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:
@ -907,9 +907,7 @@ class Template extends Render
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$expr1 = $this->parseExp($tokens, true);
|
$expr1 = $this->parseExp($tokens, true);
|
||||||
if (!$tokens->is(":")) {
|
$tokens->need(':')->skip();
|
||||||
throw new UnexpectedTokenException($tokens, null, "ternary operator");
|
|
||||||
}
|
|
||||||
$expr2 = $this->parseExp($tokens, true);
|
$expr2 = $this->parseExp($tokens, true);
|
||||||
if ($empty) {
|
if ($empty) {
|
||||||
return '(empty(' . $var . ') ? ' . $expr2 . ' : ' . $expr1 . ')';
|
return '(empty(' . $var . ') ? ' . $expr2 . ' : ' . $expr1 . ')';
|
||||||
|
@ -404,7 +404,11 @@ class TemplateTest extends TestCase
|
|||||||
array('{if $nonempty.double!} right {/if}', $a),
|
array('{if $nonempty.double!} right {/if}', $a),
|
||||||
array('{if $nonempty.bool!} 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()
|
public function _testSandbox()
|
||||||
{
|
{
|
||||||
try {
|
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) {
|
} catch (\Exception $e) {
|
||||||
print_r($e->getMessage() . "\n" . $e->getTraceAsString());
|
print_r($e->getMessage() . "\n" . $e->getTraceAsString());
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user