4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Finder\Tests\Expression;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Finder\Expression\Expression;
20 class RegexTest extends TestCase
23 * @dataProvider getHasFlagsData
25 public function testHasFlags($regex, $start, $end)
27 $expr = new Expression($regex);
29 $this->assertEquals($start, $expr->getRegex()->hasStartFlag());
30 $this->assertEquals($end, $expr->getRegex()->hasEndFlag());
34 * @dataProvider getHasJokersData
36 public function testHasJokers($regex, $start, $end)
38 $expr = new Expression($regex);
40 $this->assertEquals($start, $expr->getRegex()->hasStartJoker());
41 $this->assertEquals($end, $expr->getRegex()->hasEndJoker());
45 * @dataProvider getSetFlagsData
47 public function testSetFlags($regex, $start, $end, $expected)
49 $expr = new Expression($regex);
50 $expr->getRegex()->setStartFlag($start)->setEndFlag($end);
52 $this->assertEquals($expected, $expr->render());
56 * @dataProvider getSetJokersData
58 public function testSetJokers($regex, $start, $end, $expected)
60 $expr = new Expression($regex);
61 $expr->getRegex()->setStartJoker($start)->setEndJoker($end);
63 $this->assertEquals($expected, $expr->render());
66 public function testOptions()
68 $expr = new Expression('~abc~is');
69 $expr->getRegex()->removeOption('i')->addOption('m');
71 $this->assertEquals('~abc~sm', $expr->render());
74 public function testMixFlagsAndJokers()
76 $expr = new Expression('~^.*abc.*$~is');
78 $expr->getRegex()->setStartFlag(false)->setEndFlag(false)->setStartJoker(false)->setEndJoker(false);
79 $this->assertEquals('~abc~is', $expr->render());
81 $expr->getRegex()->setStartFlag(true)->setEndFlag(true)->setStartJoker(true)->setEndJoker(true);
82 $this->assertEquals('~^.*abc.*$~is', $expr->render());
86 * @dataProvider getReplaceJokersTestData
88 public function testReplaceJokers($regex, $expected)
90 $expr = new Expression($regex);
91 $expr = $expr->getRegex()->replaceJokers('@');
93 $this->assertEquals($expected, $expr->renderPattern());
96 public function getHasFlagsData()
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),
107 public function getHasJokersData()
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),
118 public function getSetFlagsData()
121 array('~abc~', true, false, '~^abc~'),
122 array('~abc~', false, true, '~abc$~'),
123 array('~abc~', false, false, '~abc~'),
124 array('~abc~', true, true, '~^abc$~'),
128 public function getSetJokersData()
131 array('~abc~', true, false, '~.*abc~'),
132 array('~abc~', false, true, '~abc.*~'),
133 array('~abc~', false, false, '~abc~'),
134 array('~abc~', true, true, '~.*abc.*~'),
138 public function getReplaceJokersTestData()
141 array('~.abc~', '@abc'),
142 array('~\\.abc~', '\\.abc'),
143 array('~\\\\.abc~', '\\\\@abc'),
144 array('~\\\\\\.abc~', '\\\\\\.abc'),