2010-04-21 08:31:18 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2010-04-25 16:06:54 +01:00
|
|
|
* This file is part of the Symfony package.
|
2010-04-21 08:31:18 +01:00
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2010-04-21 08:31:18 +01:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2010-08-20 22:09:55 +01:00
|
|
|
namespace Symfony\Tests\Component\Finder;
|
2010-04-21 08:31:18 +01:00
|
|
|
|
2010-08-20 22:09:55 +01:00
|
|
|
use Symfony\Component\Finder\Glob;
|
2010-04-21 08:31:18 +01:00
|
|
|
|
|
|
|
class GlobTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
2010-05-06 12:25:53 +01:00
|
|
|
/**
|
|
|
|
* @dataProvider getToRegexData
|
|
|
|
*/
|
|
|
|
public function testToRegex($glob, $match, $noMatch)
|
2010-04-21 08:31:18 +01:00
|
|
|
{
|
2010-05-07 15:09:11 +01:00
|
|
|
foreach ($match as $m) {
|
2010-05-06 12:25:53 +01:00
|
|
|
$this->assertRegExp(Glob::toRegex($glob), $m, '::toRegex() converts a glob to a regexp');
|
|
|
|
}
|
|
|
|
|
2010-05-07 15:09:11 +01:00
|
|
|
foreach ($noMatch as $m) {
|
2010-05-06 12:25:53 +01:00
|
|
|
$this->assertNotRegExp(Glob::toRegex($glob), $m, '::toRegex() converts a glob to a regexp');
|
|
|
|
}
|
2010-04-21 08:31:18 +01:00
|
|
|
}
|
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
public function getToRegexData()
|
2010-04-21 08:31:18 +01:00
|
|
|
{
|
2010-05-06 12:25:53 +01:00
|
|
|
return array(
|
|
|
|
array('', array(''), array('f', '/')),
|
|
|
|
array('*', array('foo'), array('foo/', '/foo')),
|
|
|
|
array('foo.*', array('foo.php', 'foo.a', 'foo.'), array('fooo.php', 'foo.php/foo')),
|
|
|
|
array('fo?', array('foo', 'fot'), array('fooo', 'ffoo', 'fo/')),
|
|
|
|
array('fo{o,t}', array('foo', 'fot'), array('fob', 'fo/')),
|
|
|
|
array('foo(bar|foo)', array('foo(bar|foo)'), array('foobar', 'foofoo')),
|
|
|
|
array('foo,bar', array('foo,bar'), array('foo', 'bar')),
|
|
|
|
array('fo{o,\\,}', array('foo', 'fo,'), array()),
|
|
|
|
array('fo{o,\\\\}', array('foo', 'fo\\'), array()),
|
|
|
|
array('/foo', array('/foo'), array('foo')),
|
|
|
|
);
|
2010-04-21 08:31:18 +01:00
|
|
|
}
|
|
|
|
}
|