Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / vendor / symfony / css-selector / Tests / Parser / TokenStreamTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
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 namespace Symfony\Component\CssSelector\Tests\Parser;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\CssSelector\Parser\Token;
16 use Symfony\Component\CssSelector\Parser\TokenStream;
17
18 class TokenStreamTest extends TestCase
19 {
20     public function testGetNext()
21     {
22         $stream = new TokenStream();
23         $stream->push($t1 = new Token(Token::TYPE_IDENTIFIER, 'h1', 0));
24         $stream->push($t2 = new Token(Token::TYPE_DELIMITER, '.', 2));
25         $stream->push($t3 = new Token(Token::TYPE_IDENTIFIER, 'title', 3));
26
27         $this->assertSame($t1, $stream->getNext());
28         $this->assertSame($t2, $stream->getNext());
29         $this->assertSame($t3, $stream->getNext());
30     }
31
32     public function testGetPeek()
33     {
34         $stream = new TokenStream();
35         $stream->push($t1 = new Token(Token::TYPE_IDENTIFIER, 'h1', 0));
36         $stream->push($t2 = new Token(Token::TYPE_DELIMITER, '.', 2));
37         $stream->push($t3 = new Token(Token::TYPE_IDENTIFIER, 'title', 3));
38
39         $this->assertSame($t1, $stream->getPeek());
40         $this->assertSame($t1, $stream->getNext());
41         $this->assertSame($t2, $stream->getPeek());
42         $this->assertSame($t2, $stream->getPeek());
43         $this->assertSame($t2, $stream->getNext());
44     }
45
46     public function testGetNextIdentifier()
47     {
48         $stream = new TokenStream();
49         $stream->push(new Token(Token::TYPE_IDENTIFIER, 'h1', 0));
50
51         $this->assertEquals('h1', $stream->getNextIdentifier());
52     }
53
54     public function testFailToGetNextIdentifier()
55     {
56         $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\CssSelector\Exception\SyntaxErrorException');
57
58         $stream = new TokenStream();
59         $stream->push(new Token(Token::TYPE_DELIMITER, '.', 2));
60         $stream->getNextIdentifier();
61     }
62
63     public function testGetNextIdentifierOrStar()
64     {
65         $stream = new TokenStream();
66
67         $stream->push(new Token(Token::TYPE_IDENTIFIER, 'h1', 0));
68         $this->assertEquals('h1', $stream->getNextIdentifierOrStar());
69
70         $stream->push(new Token(Token::TYPE_DELIMITER, '*', 0));
71         $this->assertNull($stream->getNextIdentifierOrStar());
72     }
73
74     public function testFailToGetNextIdentifierOrStar()
75     {
76         $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\CssSelector\Exception\SyntaxErrorException');
77
78         $stream = new TokenStream();
79         $stream->push(new Token(Token::TYPE_DELIMITER, '.', 2));
80         $stream->getNextIdentifierOrStar();
81     }
82
83     public function testSkipWhitespace()
84     {
85         $stream = new TokenStream();
86         $stream->push($t1 = new Token(Token::TYPE_IDENTIFIER, 'h1', 0));
87         $stream->push($t2 = new Token(Token::TYPE_WHITESPACE, ' ', 2));
88         $stream->push($t3 = new Token(Token::TYPE_IDENTIFIER, 'h1', 3));
89
90         $stream->skipWhitespace();
91         $this->assertSame($t1, $stream->getNext());
92
93         $stream->skipWhitespace();
94         $this->assertSame($t3, $stream->getNext());
95     }
96 }