]>
Commit | Line | Data |
---|---|---|
4f5b44bd NL |
1 | <?php |
2 | ||
3 | /* | |
4 | * This file is part of Twig. | |
5 | * | |
6 | * (c) Fabien Potencier | |
7 | * | |
8 | * For the full copyright and license information, please view the LICENSE | |
9 | * file that was distributed with this source code. | |
10 | */ | |
11 | ||
12 | class Twig_Tests_TokenStreamTest extends PHPUnit_Framework_TestCase | |
13 | { | |
14 | protected static $tokens; | |
15 | ||
16 | public function setUp() | |
17 | { | |
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), | |
27 | ); | |
28 | } | |
29 | ||
30 | public function testNext() | |
31 | { | |
32 | $stream = new Twig_TokenStream(self::$tokens); | |
33 | $repr = array(); | |
34 | while (!$stream->isEOF()) { | |
35 | $token = $stream->next(); | |
36 | ||
37 | $repr[] = $token->getValue(); | |
38 | } | |
39 | $this->assertEquals('1, 2, 3, 4, 5, 6, 7', implode(', ', $repr), '->next() advances the pointer and returns the current token'); | |
40 | } | |
41 | ||
42 | /** | |
43 | * @expectedException Twig_Error_Syntax | |
44 | * @expectedMessage Unexpected end of template | |
45 | */ | |
46 | public function testEndOfTemplateNext() | |
47 | { | |
48 | $stream = new Twig_TokenStream(array( | |
49 | new Twig_Token(Twig_Token::BLOCK_START_TYPE, 1, 1), | |
50 | )); | |
51 | while (!$stream->isEOF()) { | |
52 | $stream->next(); | |
53 | } | |
54 | } | |
55 | ||
56 | /** | |
57 | * @expectedException Twig_Error_Syntax | |
58 | * @expectedMessage Unexpected end of template | |
59 | */ | |
60 | public function testEndOfTemplateLook() | |
61 | { | |
62 | $stream = new Twig_TokenStream(array( | |
63 | new Twig_Token(Twig_Token::BLOCK_START_TYPE, 1, 1), | |
64 | )); | |
65 | while (!$stream->isEOF()) { | |
66 | $stream->look(); | |
67 | $stream->next(); | |
68 | } | |
69 | } | |
70 | } |