GlobTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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;
  11. use Symfony\Component\Finder\Expression\Expression;
  12. class GlobTest extends \PHPUnit_Framework_TestCase
  13. {
  14. /**
  15. * @dataProvider getToRegexData
  16. */
  17. public function testGlobToRegex($glob, $match, $noMatch)
  18. {
  19. foreach ($match as $m) {
  20. $this->assertRegExp(Expression::create($glob)->getRegex()->render(), $m, '::toRegex() converts a glob to a regexp');
  21. }
  22. foreach ($noMatch as $m) {
  23. $this->assertNotRegExp(Expression::create($glob)->getRegex()->render(), $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. }