added a unit test for previous commit
authorFabien Potencier <fabien.potencier@gmail.com>
Mon, 3 Jan 2011 07:03:36 +0000 (08:03 +0100)
committerFabien Potencier <fabien.potencier@gmail.com>
Mon, 3 Jan 2011 07:03:36 +0000 (08:03 +0100)
test/Twig/Tests/LexerTest.php [new file with mode: 0644]

diff --git a/test/Twig/Tests/LexerTest.php b/test/Twig/Tests/LexerTest.php
new file mode 100644 (file)
index 0000000..f589712
--- /dev/null
@@ -0,0 +1,39 @@
+<?php
+
+/*
+ * This file is part of Twig.
+ *
+ * (c) Fabien Potencier
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+class Twig_Tests_LexerTest extends PHPUnit_Framework_TestCase
+{
+    public function testBracketsNesting()
+    {
+        $template = '{{ {"a":{"b":"c"}} }}';
+
+        $this->assertEquals(2, $this->countToken($template, Twig_Token::PUNCTUATION_TYPE, '{'));
+        $this->assertEquals(2, $this->countToken($template, Twig_Token::PUNCTUATION_TYPE, '}'));
+    }
+
+    protected function countToken($template, $type, $value = null)
+    {
+        $lexer = new Twig_Lexer(new Twig_Environment());
+        $stream = $lexer->tokenize($template);
+
+        $count = 0;
+        $tokens = array();
+        while (!$stream->isEOF()) {
+            $token = $stream->next();
+            if ($type === $token->getType()) {
+                if (null === $value || $value === $token->getValue()) {
+                    ++$count;
+                }
+            }
+        }
+
+        return $count;
+    }
+}