4 * This file is part of Twig.
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 class Twig_Tests_TokenStreamTest extends PHPUnit_Framework_TestCase
14 protected static $tokens;
16 protected function setUp()
18 self::$tokens = array(
19 new Twig_Token(Twig_Token::TEXT_TYPE, 1, 1),
20 new Twig_Token(Twig_Token::TEXT_TYPE, 2, 1),
21 new Twig_Token(Twig_Token::TEXT_TYPE, 3, 1),
22 new Twig_Token(Twig_Token::TEXT_TYPE, 4, 1),
23 new Twig_Token(Twig_Token::TEXT_TYPE, 5, 1),
24 new Twig_Token(Twig_Token::TEXT_TYPE, 6, 1),
25 new Twig_Token(Twig_Token::TEXT_TYPE, 7, 1),
26 new Twig_Token(Twig_Token::EOF_TYPE, 0, 1),
33 public function testLegacyConstructorSignature()
35 $stream = new Twig_TokenStream(array(), 'foo', '{{ foo }}');
36 $this->assertEquals('foo', $stream->getFilename());
37 $this->assertEquals('{{ foo }}', $stream->getSource());
38 $this->assertEquals('foo', $stream->getSourceContext()->getName());
39 $this->assertEquals('{{ foo }}', $stream->getSourceContext()->getCode());
42 public function testNext()
44 $stream = new Twig_TokenStream(self::$tokens);
46 while (!$stream->isEOF()) {
47 $token = $stream->next();
49 $repr[] = $token->getValue();
51 $this->assertEquals('1, 2, 3, 4, 5, 6, 7', implode(', ', $repr), '->next() advances the pointer and returns the current token');
55 * @expectedException Twig_Error_Syntax
56 * @expectedExceptionMessage Unexpected end of template
58 public function testEndOfTemplateNext()
60 $stream = new Twig_TokenStream(array(
61 new Twig_Token(Twig_Token::BLOCK_START_TYPE, 1, 1),
63 while (!$stream->isEOF()) {
69 * @expectedException Twig_Error_Syntax
70 * @expectedExceptionMessage Unexpected end of template
72 public function testEndOfTemplateLook()
74 $stream = new Twig_TokenStream(array(
75 new Twig_Token(Twig_Token::BLOCK_START_TYPE, 1, 1),
77 while (!$stream->isEOF()) {