fixed unary operators precedence (closes #583)
authorFabien Potencier <fabien.potencier@gmail.com>
Fri, 6 Jan 2012 18:47:50 +0000 (19:47 +0100)
committerFabien Potencier <fabien.potencier@gmail.com>
Fri, 6 Jan 2012 18:47:50 +0000 (19:47 +0100)
lib/Twig/Extension/Core.php
test/Twig/Tests/Fixtures/expressions/unary_precedence.test [new file with mode: 0644]

index f5d2acd..a0dbfc9 100644 (file)
@@ -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 (file)
index 0000000..cc6eef8
--- /dev/null
@@ -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