--- /dev/null
+<?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;
+ }
+}