mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-13 10:56:38 +00:00
added a unit test for previous commit
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user