From: Fabien Potencier Date: Mon, 3 Jan 2011 07:03:36 +0000 (+0100) Subject: added a unit test for previous commit X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=d2df756df882564e48413a8352566fd8cdc4ae11;p=web%2Fkonrad%2Ftwig.git added a unit test for previous commit --- 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; + } +}