Yaffs site version 1.1
[yaffs-website] / vendor / twig / twig / test / Twig / Tests / TokenStreamTest.php
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     protected 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     /**
31      * @group legacy
32      */
33     public function testLegacyConstructorSignature()
34     {
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());
40     }
41
42     public function testNext()
43     {
44         $stream = new Twig_TokenStream(self::$tokens);
45         $repr = array();
46         while (!$stream->isEOF()) {
47             $token = $stream->next();
48
49             $repr[] = $token->getValue();
50         }
51         $this->assertEquals('1, 2, 3, 4, 5, 6, 7', implode(', ', $repr), '->next() advances the pointer and returns the current token');
52     }
53
54     /**
55      * @expectedException        Twig_Error_Syntax
56      * @expectedExceptionMessage Unexpected end of template
57      */
58     public function testEndOfTemplateNext()
59     {
60         $stream = new Twig_TokenStream(array(
61             new Twig_Token(Twig_Token::BLOCK_START_TYPE, 1, 1),
62         ));
63         while (!$stream->isEOF()) {
64             $stream->next();
65         }
66     }
67
68     /**
69      * @expectedException        Twig_Error_Syntax
70      * @expectedExceptionMessage Unexpected end of template
71      */
72     public function testEndOfTemplateLook()
73     {
74         $stream = new Twig_TokenStream(array(
75             new Twig_Token(Twig_Token::BLOCK_START_TYPE, 1, 1),
76         ));
77         while (!$stream->isEOF()) {
78             $stream->look();
79             $stream->next();
80         }
81     }
82 }