GlobTest.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /*
  3. * This file is part of the symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.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\Components\Finder;
  11. use Symfony\Components\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. {
  21. $this->assertRegExp(Glob::toRegex($glob), $m, '::toRegex() converts a glob to a regexp');
  22. }
  23. foreach ($noMatch as $m)
  24. {
  25. $this->assertNotRegExp(Glob::toRegex($glob), $m, '::toRegex() converts a glob to a regexp');
  26. }
  27. }
  28. public function getToRegexData()
  29. {
  30. return array(
  31. array('', array(''), array('f', '/')),
  32. array('*', array('foo'), array('foo/', '/foo')),
  33. array('foo.*', array('foo.php', 'foo.a', 'foo.'), array('fooo.php', 'foo.php/foo')),
  34. array('fo?', array('foo', 'fot'), array('fooo', 'ffoo', 'fo/')),
  35. array('fo{o,t}', array('foo', 'fot'), array('fob', 'fo/')),
  36. array('foo(bar|foo)', array('foo(bar|foo)'), array('foobar', 'foofoo')),
  37. array('foo,bar', array('foo,bar'), array('foo', 'bar')),
  38. array('fo{o,\\,}', array('foo', 'fo,'), array()),
  39. array('fo{o,\\\\}', array('foo', 'fo\\'), array()),
  40. array('/foo', array('/foo'), array('foo')),
  41. );
  42. }
  43. }