added a unit test for previous commit

This commit is contained in:
Fabien Potencier
2011-01-03 08:03:36 +01:00
parent 1602d9bd52
commit d2df756df8
+39
View File
@@ -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;
}
}