From d2df756df882564e48413a8352566fd8cdc4ae11 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 3 Jan 2011 08:03:36 +0100 Subject: [PATCH] added a unit test for previous commit --- test/Twig/Tests/LexerTest.php | 39 +++++++++++++++++++++++++++++++++++++++ 1 files changed, 39 insertions(+), 0 deletions(-) create mode 100644 test/Twig/Tests/LexerTest.php diff --git a/test/Twig/Tests/LexerTest.php b/test/Twig/Tests/LexerTest.php new file mode 100644 index 0000000..f589712 --- /dev/null +++ b/test/Twig/Tests/LexerTest.php @@ -0,0 +1,39 @@ +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; + } +} -- 1.7.2.5