GlobTest.php 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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\Tests\Component\Finder;
  11. use Symfony\Component\Finder\Glob;
  12. class GlobTest extends \PHPUnit_Framework_TestCase
  13. {
  14. /**
  15. * @dataProvider getToRegexData
  16. */
  17. public function testToRegex($glob, $match, $noMatch)
  18. {
  19. foreach ($match as $m) {
  20. $this->assertRegExp(Glob::toRegex($glob), $m, '::toRegex() converts a glob to a regexp');
  21. }
  22. foreach ($noMatch as $m) {
  23. $this->assertNotRegExp(Glob::toRegex($glob), $m, '::toRegex() converts a glob to a regexp');
  24. }
  25. }
  26. public function getToRegexData()
  27. {
  28. return array(
  29. array('', array(''), array('f', '/')),
  30. array('*', array('foo'), array('foo/', '/foo')),
  31. array('foo.*', array('foo.php', 'foo.a', 'foo.'), array('fooo.php', 'foo.php/foo')),
  32. array('fo?', array('foo', 'fot'), array('fooo', 'ffoo', 'fo/')),
  33. array('fo{o,t}', array('foo', 'fot'), array('fob', 'fo/')),
  34. array('foo(bar|foo)', array('foo(bar|foo)'), array('foobar', 'foofoo')),
  35. array('foo,bar', array('foo,bar'), array('foo', 'bar')),
  36. array('fo{o,\\,}', array('foo', 'fo,'), array()),
  37. array('fo{o,\\\\}', array('foo', 'fo\\'), array()),
  38. array('/foo', array('/foo'), array('foo')),
  39. );
  40. }
  41. }