From: Fabien Potencier Date: Sun, 7 Nov 2010 20:44:05 +0000 (+0100) Subject: fixed unary expressions X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=7d78ab416dee42a17408e23a6cd2e0e6dba7b835;p=web%2Fkonrad%2Ftwig.git fixed unary expressions --- diff --git a/lib/Twig/Node/Expression/Binary.php b/lib/Twig/Node/Expression/Binary.php index 8a05969..464d441 100644 --- a/lib/Twig/Node/Expression/Binary.php +++ b/lib/Twig/Node/Expression/Binary.php @@ -26,11 +26,11 @@ abstract class Twig_Node_Expression_Binary extends Twig_Node_Expression $compiler ->raw('(') ->subcompile($this->getNode('left')) - ->raw(') ') + ->raw(' ') ; $this->operator($compiler); $compiler - ->raw(' (') + ->raw(' ') ->subcompile($this->getNode('right')) ->raw(')') ; diff --git a/test/Twig/Tests/Fixtures/expressions/binary.test b/test/Twig/Tests/Fixtures/expressions/binary.test index 009c8c8..f5e6845 100644 --- a/test/Twig/Tests/Fixtures/expressions/binary.test +++ b/test/Twig/Tests/Fixtures/expressions/binary.test @@ -14,6 +14,8 @@ Twig supports binary operations (+, -, *, /, ~, %, and, or) {{ 1 or 0 }} {{ 0 or 1 }} {{ 0 or 0 }} +{{ 0 or 1 and 0 }} +{{ 1 or 0 and 1 }} {{ "foo" ~ "bar" }} {{ foo ~ "bar" }} {{ "foo" ~ bar }} @@ -35,6 +37,8 @@ return array('foo' => 'bar', 'bar' => 'foo') 1 1 + +1 foobar barbar foofoo diff --git a/test/Twig/Tests/Fixtures/expressions/unary.test b/test/Twig/Tests/Fixtures/expressions/unary.test index 2e1cb35..b79219a 100644 --- a/test/Twig/Tests/Fixtures/expressions/unary.test +++ b/test/Twig/Tests/Fixtures/expressions/unary.test @@ -3,8 +3,10 @@ Twig supports unary operators (not, -, +) --TEMPLATE-- {{ not 1 }}/{{ not 0 }} {{ +1 + 1 }}/{{ -1 - 1 }} +{{ not (false or true) }} --DATA-- return array() --EXPECT-- /1 2/-2 + diff --git a/test/Twig/Tests/Node/Expression/Binary/AddTest.php b/test/Twig/Tests/Node/Expression/Binary/AddTest.php index f2bec4c..80d318f 100644 --- a/test/Twig/Tests/Node/Expression/Binary/AddTest.php +++ b/test/Twig/Tests/Node/Expression/Binary/AddTest.php @@ -43,7 +43,7 @@ class Twig_Tests_Node_Expression_Binary_AddTest extends Twig_Tests_Node_TestCase $node = new Twig_Node_Expression_Binary_Add($left, $right, 0); return array( - array($node, '(1) + (2)'), + array($node, '(1 + 2)'), ); } } diff --git a/test/Twig/Tests/Node/Expression/Binary/AndTest.php b/test/Twig/Tests/Node/Expression/Binary/AndTest.php index fc67850..a6ed4f2 100644 --- a/test/Twig/Tests/Node/Expression/Binary/AndTest.php +++ b/test/Twig/Tests/Node/Expression/Binary/AndTest.php @@ -43,7 +43,7 @@ class Twig_Tests_Node_Expression_Binary_AndTest extends Twig_Tests_Node_TestCase $node = new Twig_Node_Expression_Binary_And($left, $right, 0); return array( - array($node, '(1) && (2)'), + array($node, '(1 && 2)'), ); } } diff --git a/test/Twig/Tests/Node/Expression/Binary/ConcatTest.php b/test/Twig/Tests/Node/Expression/Binary/ConcatTest.php index 4c16171..a04edc9 100644 --- a/test/Twig/Tests/Node/Expression/Binary/ConcatTest.php +++ b/test/Twig/Tests/Node/Expression/Binary/ConcatTest.php @@ -43,7 +43,7 @@ class Twig_Tests_Node_Expression_Binary_ConcatTest extends Twig_Tests_Node_TestC $node = new Twig_Node_Expression_Binary_Concat($left, $right, 0); return array( - array($node, '(1) . (2)'), + array($node, '(1 . 2)'), ); } } diff --git a/test/Twig/Tests/Node/Expression/Binary/DivTest.php b/test/Twig/Tests/Node/Expression/Binary/DivTest.php index 9a63994..42002fc 100644 --- a/test/Twig/Tests/Node/Expression/Binary/DivTest.php +++ b/test/Twig/Tests/Node/Expression/Binary/DivTest.php @@ -43,7 +43,7 @@ class Twig_Tests_Node_Expression_Binary_DivTest extends Twig_Tests_Node_TestCase $node = new Twig_Node_Expression_Binary_Div($left, $right, 0); return array( - array($node, '(1) / (2)'), + array($node, '(1 / 2)'), ); } } diff --git a/test/Twig/Tests/Node/Expression/Binary/FloorDivTest.php b/test/Twig/Tests/Node/Expression/Binary/FloorDivTest.php index f900b15..cfa335c 100644 --- a/test/Twig/Tests/Node/Expression/Binary/FloorDivTest.php +++ b/test/Twig/Tests/Node/Expression/Binary/FloorDivTest.php @@ -43,7 +43,7 @@ class Twig_Tests_Node_Expression_Binary_FloorDivTest extends Twig_Tests_Node_Tes $node = new Twig_Node_Expression_Binary_FloorDiv($left, $right, 0); return array( - array($node, 'floor((1) / (2))'), + array($node, 'floor((1 / 2))'), ); } } diff --git a/test/Twig/Tests/Node/Expression/Binary/ModTest.php b/test/Twig/Tests/Node/Expression/Binary/ModTest.php index 88d82a0..67612a5 100644 --- a/test/Twig/Tests/Node/Expression/Binary/ModTest.php +++ b/test/Twig/Tests/Node/Expression/Binary/ModTest.php @@ -43,7 +43,7 @@ class Twig_Tests_Node_Expression_Binary_ModTest extends Twig_Tests_Node_TestCase $node = new Twig_Node_Expression_Binary_Mod($left, $right, 0); return array( - array($node, '(1) % (2)'), + array($node, '(1 % 2)'), ); } } diff --git a/test/Twig/Tests/Node/Expression/Binary/MulTest.php b/test/Twig/Tests/Node/Expression/Binary/MulTest.php index c1cccb0..c817d02 100644 --- a/test/Twig/Tests/Node/Expression/Binary/MulTest.php +++ b/test/Twig/Tests/Node/Expression/Binary/MulTest.php @@ -43,7 +43,7 @@ class Twig_Tests_Node_Expression_Binary_MulTest extends Twig_Tests_Node_TestCase $node = new Twig_Node_Expression_Binary_Mul($left, $right, 0); return array( - array($node, '(1) * (2)'), + array($node, '(1 * 2)'), ); } } diff --git a/test/Twig/Tests/Node/Expression/Binary/OrTest.php b/test/Twig/Tests/Node/Expression/Binary/OrTest.php index afea4ff..d8e2f8d 100644 --- a/test/Twig/Tests/Node/Expression/Binary/OrTest.php +++ b/test/Twig/Tests/Node/Expression/Binary/OrTest.php @@ -43,7 +43,7 @@ class Twig_Tests_Node_Expression_Binary_OrTest extends Twig_Tests_Node_TestCase $node = new Twig_Node_Expression_Binary_Or($left, $right, 0); return array( - array($node, '(1) || (2)'), + array($node, '(1 || 2)'), ); } } diff --git a/test/Twig/Tests/Node/Expression/Binary/SubTest.php b/test/Twig/Tests/Node/Expression/Binary/SubTest.php index 3b00e77..6583d09 100644 --- a/test/Twig/Tests/Node/Expression/Binary/SubTest.php +++ b/test/Twig/Tests/Node/Expression/Binary/SubTest.php @@ -43,7 +43,7 @@ class Twig_Tests_Node_Expression_Binary_SubTest extends Twig_Tests_Node_TestCase $node = new Twig_Node_Expression_Binary_Sub($left, $right, 0); return array( - array($node, '(1) - (2)'), + array($node, '(1 - 2)'), ); } }