From 8fb4172a046d2f553769283403fe519cbdde83e7 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 6 Jan 2012 19:47:50 +0100 Subject: [PATCH] fixed unary operators precedence (closes #583) --- lib/Twig/Extension/Core.php | 4 ++-- .../Fixtures/expressions/unary_precedence.test | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 test/Twig/Tests/Fixtures/expressions/unary_precedence.test diff --git a/lib/Twig/Extension/Core.php b/lib/Twig/Extension/Core.php index f5d2acd..a0dbfc9 100644 --- a/lib/Twig/Extension/Core.php +++ b/lib/Twig/Extension/Core.php @@ -189,8 +189,8 @@ class Twig_Extension_Core extends Twig_Extension return array( array( 'not' => array('precedence' => 50, 'class' => 'Twig_Node_Expression_Unary_Not'), - '-' => array('precedence' => 50, 'class' => 'Twig_Node_Expression_Unary_Neg'), - '+' => array('precedence' => 50, 'class' => 'Twig_Node_Expression_Unary_Pos'), + '-' => array('precedence' => 500, 'class' => 'Twig_Node_Expression_Unary_Neg'), + '+' => array('precedence' => 500, 'class' => 'Twig_Node_Expression_Unary_Pos'), ), array( 'b-and' => array('precedence' => 5, 'class' => 'Twig_Node_Expression_Binary_BitwiseAnd', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), diff --git a/test/Twig/Tests/Fixtures/expressions/unary_precedence.test b/test/Twig/Tests/Fixtures/expressions/unary_precedence.test new file mode 100644 index 0000000..cc6eef8 --- /dev/null +++ b/test/Twig/Tests/Fixtures/expressions/unary_precedence.test @@ -0,0 +1,14 @@ +--TEST-- +Twig unary operators precedence +--TEMPLATE-- +{{ -1 - 1 }} +{{ -1 - -1 }} +{{ -1 * -1 }} +{{ 4 / -1 * 5 }} +--DATA-- +return array() +--EXPECT-- +-2 +0 +1 +-20 -- 1.7.2.5