Merge pull request #18 from klkvsk/fix-unary-before-brackets

Fix for unary operator ("!", "-", "~") before brackets in expression.
This commit is contained in:
Ivan Shalganov 2013-07-12 02:44:02 -07:00
commit a0d84812af
2 changed files with 5 additions and 2 deletions

View File

@ -608,7 +608,7 @@ class Template extends Render {
} }
$term = 1; $term = 1;
} elseif(!$term && $tokens->is(Tokenizer::MACRO_UNARY)) { } elseif(!$term && $tokens->is(Tokenizer::MACRO_UNARY)) {
if(!$tokens->isNext(T_VARIABLE, T_DNUMBER, T_LNUMBER, T_STRING, T_ISSET, T_EMPTY)) { if(!$tokens->isNext(T_VARIABLE, T_DNUMBER, T_LNUMBER, T_STRING, T_ISSET, T_EMPTY, '(')) {
break; break;
} }
$_exp .= $tokens->getAndNext(); $_exp .= $tokens->getAndNext();

View File

@ -166,8 +166,9 @@ class TemplateTest extends TestCase {
array('Exp: {$y-$x} result', $b, 'Exp: 18 result'), array('Exp: {$y-$x} result', $b, 'Exp: 18 result'),
array('Exp: {$y*$x} result', $b, 'Exp: 243 result'), array('Exp: {$y*$x} result', $b, 'Exp: 243 result'),
array('Exp: {$y^$x} result', $b, 'Exp: 18 result'), array('Exp: {$y^$x} result', $b, 'Exp: 18 result'),
array('Exp: {-$x} result', $b, 'Exp: -9 result'), array('Exp: {-($x)} result', $b, 'Exp: -9 result'),
array('Exp: {!$x} result', $b, 'Exp: result'), array('Exp: {!$x} result', $b, 'Exp: result'),
array('Exp: {!($x)} result', $b, 'Exp: result'),
array('Exp: {!5} result', $b, 'Exp: result'), array('Exp: {!5} result', $b, 'Exp: result'),
array('Exp: {-1} result', $b, 'Exp: -1 result'), array('Exp: {-1} result', $b, 'Exp: -1 result'),
array('Exp: {$z = 5} {$z} result', $b, 'Exp: 5 5 result'), array('Exp: {$z = 5} {$z} result', $b, 'Exp: 5 5 result'),
@ -266,6 +267,8 @@ class TemplateTest extends TestCase {
array('if: {if true} block1 {else} block2 {/if} end', $a, 'if: block1 end'), array('if: {if true} block1 {else} block2 {/if} end', $a, 'if: block1 end'),
array('if: {if false} block1 {else} block2 {/if} end', $a, 'if: block2 end'), array('if: {if false} block1 {else} block2 {/if} end', $a, 'if: block2 end'),
array('if: {if null} block1 {else} block2 {/if} end', $a, 'if: block2 end'), array('if: {if null} block1 {else} block2 {/if} end', $a, 'if: block2 end'),
array('if: {if !($val0 || $val1)} block1 {else} block2 {/if} end',
$a, 'if: block2 end'),
); );
} }