From 76205f1eaad26d4e57e3957c6c1ad70d22c0ba6d Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 14 Apr 2011 07:35:58 +0200 Subject: [PATCH] added null as an alias to none and made TRUE, FALSE, and NONE equivalent to true, false, and none --- CHANGELOG | 2 + lib/Twig/ExpressionParser.php | 5 ++++ test/Twig/Tests/Fixtures/expressions/literals.test | 22 ++++++++++++++++++++ 3 files changed, 29 insertions(+), 0 deletions(-) create mode 100644 test/Twig/Tests/Fixtures/expressions/literals.test diff --git a/CHANGELOG b/CHANGELOG index 673cbe5..1d70d47 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,6 +4,8 @@ Flush your cache after upgrading. Changes: + * added null as an alias for none + * made TRUE, FALSE, NONE equivalent to their lowercase counterparts * wrapped all runtime exceptions with Twig_Error_Runtime and added logic to guess the template name and line * moved display() method to Twig_Template (generated templates should now use doDisplay() instead) diff --git a/lib/Twig/ExpressionParser.php b/lib/Twig/ExpressionParser.php index 2e2b4b1..b355f08 100644 --- a/lib/Twig/ExpressionParser.php +++ b/lib/Twig/ExpressionParser.php @@ -117,14 +117,19 @@ class Twig_ExpressionParser $this->parser->getStream()->next(); switch ($token->getValue()) { case 'true': + case 'TRUE': $node = new Twig_Node_Expression_Constant(true, $token->getLine()); break; case 'false': + case 'FALSE': $node = new Twig_Node_Expression_Constant(false, $token->getLine()); break; case 'none': + case 'NONE': + case 'null': + case 'NULL': $node = new Twig_Node_Expression_Constant(null, $token->getLine()); break; diff --git a/test/Twig/Tests/Fixtures/expressions/literals.test b/test/Twig/Tests/Fixtures/expressions/literals.test new file mode 100644 index 0000000..7ae3bae --- /dev/null +++ b/test/Twig/Tests/Fixtures/expressions/literals.test @@ -0,0 +1,22 @@ +--TEST-- +Twig supports literals +--TEMPLATE-- +1 {{ true }} +2 {{ TRUE }} +3 {{ false }} +4 {{ FALSE }} +5 {{ none }} +6 {{ NONE }} +7 {{ null }} +8 {{ NULL }} +--DATA-- +return array() +--EXPECT-- +1 1 +2 1 +3 +4 +5 +6 +7 +8 -- 1.7.2.5