Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / vendor / symfony / css-selector / Tests / Parser / ReaderTest.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\Reader;
16
17 class ReaderTest extends TestCase
18 {
19     public function testIsEOF()
20     {
21         $reader = new Reader('');
22         $this->assertTrue($reader->isEOF());
23
24         $reader = new Reader('hello');
25         $this->assertFalse($reader->isEOF());
26
27         $this->assignPosition($reader, 2);
28         $this->assertFalse($reader->isEOF());
29
30         $this->assignPosition($reader, 5);
31         $this->assertTrue($reader->isEOF());
32     }
33
34     public function testGetRemainingLength()
35     {
36         $reader = new Reader('hello');
37         $this->assertEquals(5, $reader->getRemainingLength());
38
39         $this->assignPosition($reader, 2);
40         $this->assertEquals(3, $reader->getRemainingLength());
41
42         $this->assignPosition($reader, 5);
43         $this->assertEquals(0, $reader->getRemainingLength());
44     }
45
46     public function testGetSubstring()
47     {
48         $reader = new Reader('hello');
49         $this->assertEquals('he', $reader->getSubstring(2));
50         $this->assertEquals('el', $reader->getSubstring(2, 1));
51
52         $this->assignPosition($reader, 2);
53         $this->assertEquals('ll', $reader->getSubstring(2));
54         $this->assertEquals('lo', $reader->getSubstring(2, 1));
55     }
56
57     public function testGetOffset()
58     {
59         $reader = new Reader('hello');
60         $this->assertEquals(2, $reader->getOffset('ll'));
61         $this->assertFalse($reader->getOffset('w'));
62
63         $this->assignPosition($reader, 2);
64         $this->assertEquals(0, $reader->getOffset('ll'));
65         $this->assertFalse($reader->getOffset('he'));
66     }
67
68     public function testFindPattern()
69     {
70         $reader = new Reader('hello');
71
72         $this->assertFalse($reader->findPattern('/world/'));
73         $this->assertEquals(array('hello', 'h'), $reader->findPattern('/^([a-z]).*/'));
74
75         $this->assignPosition($reader, 2);
76         $this->assertFalse($reader->findPattern('/^h.*/'));
77         $this->assertEquals(array('llo'), $reader->findPattern('/^llo$/'));
78     }
79
80     public function testMoveForward()
81     {
82         $reader = new Reader('hello');
83         $this->assertEquals(0, $reader->getPosition());
84
85         $reader->moveForward(2);
86         $this->assertEquals(2, $reader->getPosition());
87     }
88
89     public function testToEnd()
90     {
91         $reader = new Reader('hello');
92         $reader->moveToEnd();
93         $this->assertTrue($reader->isEOF());
94     }
95
96     private function assignPosition(Reader $reader, $value)
97     {
98         $position = new \ReflectionProperty($reader, 'position');
99         $position->setAccessible(true);
100         $position->setValue($reader, $value);
101     }
102 }