Drupal investigation

GlobTest.php 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Finder\Tests\Expression;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Finder\Expression\Expression;
  13. /**
  14. * @group legacy
  15. */
  16. class GlobTest extends TestCase
  17. {
  18. /**
  19. * @dataProvider getToRegexData
  20. */
  21. public function testGlobToRegex($glob, $match, $noMatch)
  22. {
  23. foreach ($match as $m) {
  24. $this->assertRegExp(Expression::create($glob)->getRegex()->render(), $m, '::toRegex() converts a glob to a regexp');
  25. }
  26. foreach ($noMatch as $m) {
  27. $this->assertNotRegExp(Expression::create($glob)->getRegex()->render(), $m, '::toRegex() converts a glob to a regexp');
  28. }
  29. }
  30. public function getToRegexData()
  31. {
  32. return array(
  33. array('', array(''), array('f', '/')),
  34. array('*', array('foo'), array('foo/', '/foo')),
  35. array('foo.*', array('foo.php', 'foo.a', 'foo.'), array('fooo.php', 'foo.php/foo')),
  36. array('fo?', array('foo', 'fot'), array('fooo', 'ffoo', 'fo/')),
  37. array('fo{o,t}', array('foo', 'fot'), array('fob', 'fo/')),
  38. array('foo(bar|foo)', array('foo(bar|foo)'), array('foobar', 'foofoo')),
  39. array('foo,bar', array('foo,bar'), array('foo', 'bar')),
  40. array('fo{o,\\,}', array('foo', 'fo,'), array()),
  41. array('fo{o,\\\\}', array('foo', 'fo\\'), array()),
  42. array('/foo', array('/foo'), array('foo')),
  43. );
  44. }
  45. }