Yaffs site version 1.1
[yaffs-website] / vendor / symfony / finder / Tests / Expression / RegexTest.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\Finder\Tests\Expression;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Finder\Expression\Expression;
16
17 /**
18  * @group legacy
19  */
20 class RegexTest extends TestCase
21 {
22     /**
23      * @dataProvider getHasFlagsData
24      */
25     public function testHasFlags($regex, $start, $end)
26     {
27         $expr = new Expression($regex);
28
29         $this->assertEquals($start, $expr->getRegex()->hasStartFlag());
30         $this->assertEquals($end, $expr->getRegex()->hasEndFlag());
31     }
32
33     /**
34      * @dataProvider getHasJokersData
35      */
36     public function testHasJokers($regex, $start, $end)
37     {
38         $expr = new Expression($regex);
39
40         $this->assertEquals($start, $expr->getRegex()->hasStartJoker());
41         $this->assertEquals($end, $expr->getRegex()->hasEndJoker());
42     }
43
44     /**
45      * @dataProvider getSetFlagsData
46      */
47     public function testSetFlags($regex, $start, $end, $expected)
48     {
49         $expr = new Expression($regex);
50         $expr->getRegex()->setStartFlag($start)->setEndFlag($end);
51
52         $this->assertEquals($expected, $expr->render());
53     }
54
55     /**
56      * @dataProvider getSetJokersData
57      */
58     public function testSetJokers($regex, $start, $end, $expected)
59     {
60         $expr = new Expression($regex);
61         $expr->getRegex()->setStartJoker($start)->setEndJoker($end);
62
63         $this->assertEquals($expected, $expr->render());
64     }
65
66     public function testOptions()
67     {
68         $expr = new Expression('~abc~is');
69         $expr->getRegex()->removeOption('i')->addOption('m');
70
71         $this->assertEquals('~abc~sm', $expr->render());
72     }
73
74     public function testMixFlagsAndJokers()
75     {
76         $expr = new Expression('~^.*abc.*$~is');
77
78         $expr->getRegex()->setStartFlag(false)->setEndFlag(false)->setStartJoker(false)->setEndJoker(false);
79         $this->assertEquals('~abc~is', $expr->render());
80
81         $expr->getRegex()->setStartFlag(true)->setEndFlag(true)->setStartJoker(true)->setEndJoker(true);
82         $this->assertEquals('~^.*abc.*$~is', $expr->render());
83     }
84
85     /**
86      * @dataProvider getReplaceJokersTestData
87      */
88     public function testReplaceJokers($regex, $expected)
89     {
90         $expr = new Expression($regex);
91         $expr = $expr->getRegex()->replaceJokers('@');
92
93         $this->assertEquals($expected, $expr->renderPattern());
94     }
95
96     public function getHasFlagsData()
97     {
98         return array(
99             array('~^abc~', true, false),
100             array('~abc$~', false, true),
101             array('~abc~', false, false),
102             array('~^abc$~', true, true),
103             array('~^abc\\$~', true, false),
104         );
105     }
106
107     public function getHasJokersData()
108     {
109         return array(
110             array('~.*abc~', true, false),
111             array('~abc.*~', false, true),
112             array('~abc~', false, false),
113             array('~.*abc.*~', true, true),
114             array('~.*abc\\.*~', true, false),
115         );
116     }
117
118     public function getSetFlagsData()
119     {
120         return array(
121             array('~abc~', true, false, '~^abc~'),
122             array('~abc~', false, true, '~abc$~'),
123             array('~abc~', false, false, '~abc~'),
124             array('~abc~', true, true, '~^abc$~'),
125         );
126     }
127
128     public function getSetJokersData()
129     {
130         return array(
131             array('~abc~', true, false, '~.*abc~'),
132             array('~abc~', false, true, '~abc.*~'),
133             array('~abc~', false, false, '~abc~'),
134             array('~abc~', true, true, '~.*abc.*~'),
135         );
136     }
137
138     public function getReplaceJokersTestData()
139     {
140         return array(
141             array('~.abc~', '@abc'),
142             array('~\\.abc~', '\\.abc'),
143             array('~\\\\.abc~', '\\\\@abc'),
144             array('~\\\\\\.abc~', '\\\\\\.abc'),
145         );
146     }
147 }