annotate vendor/symfony/finder/Tests/GlobTest.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 129ea1e6d783
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 /*
Chris@0 4 * This file is part of the Symfony package.
Chris@0 5 *
Chris@0 6 * (c) Fabien Potencier <fabien@symfony.com>
Chris@0 7 *
Chris@0 8 * For the full copyright and license information, please view the LICENSE
Chris@0 9 * file that was distributed with this source code.
Chris@0 10 */
Chris@0 11
Chris@0 12 namespace Symfony\Component\Finder\Tests;
Chris@0 13
Chris@0 14 use PHPUnit\Framework\TestCase;
Chris@0 15 use Symfony\Component\Finder\Finder;
Chris@0 16 use Symfony\Component\Finder\Glob;
Chris@0 17
Chris@0 18 class GlobTest extends TestCase
Chris@0 19 {
Chris@0 20 public function testGlobToRegexDelimiters()
Chris@0 21 {
Chris@0 22 $this->assertEquals('#^(?=[^\.])\#$#', Glob::toRegex('#'));
Chris@0 23 $this->assertEquals('#^\.[^/]*$#', Glob::toRegex('.*'));
Chris@0 24 $this->assertEquals('^\.[^/]*$', Glob::toRegex('.*', true, true, ''));
Chris@0 25 $this->assertEquals('/^\.[^/]*$/', Glob::toRegex('.*', true, true, '/'));
Chris@0 26 }
Chris@0 27
Chris@0 28 public function testGlobToRegexDoubleStarStrictDots()
Chris@0 29 {
Chris@0 30 $finder = new Finder();
Chris@0 31 $finder->ignoreDotFiles(false);
Chris@0 32 $regex = Glob::toRegex('/**/*.neon');
Chris@0 33
Chris@0 34 foreach ($finder->in(__DIR__) as $k => $v) {
Chris@17 35 $k = str_replace(\DIRECTORY_SEPARATOR, '/', $k);
Chris@17 36 if (preg_match($regex, substr($k, \strlen(__DIR__)))) {
Chris@17 37 $match[] = substr($k, 10 + \strlen(__DIR__));
Chris@0 38 }
Chris@0 39 }
Chris@0 40 sort($match);
Chris@0 41
Chris@17 42 $this->assertSame(['one/b/c.neon', 'one/b/d.neon'], $match);
Chris@0 43 }
Chris@0 44
Chris@0 45 public function testGlobToRegexDoubleStarNonStrictDots()
Chris@0 46 {
Chris@0 47 $finder = new Finder();
Chris@0 48 $finder->ignoreDotFiles(false);
Chris@0 49 $regex = Glob::toRegex('/**/*.neon', false);
Chris@0 50
Chris@0 51 foreach ($finder->in(__DIR__) as $k => $v) {
Chris@17 52 $k = str_replace(\DIRECTORY_SEPARATOR, '/', $k);
Chris@17 53 if (preg_match($regex, substr($k, \strlen(__DIR__)))) {
Chris@17 54 $match[] = substr($k, 10 + \strlen(__DIR__));
Chris@0 55 }
Chris@0 56 }
Chris@0 57 sort($match);
Chris@0 58
Chris@17 59 $this->assertSame(['.dot/b/c.neon', '.dot/b/d.neon', 'one/b/c.neon', 'one/b/d.neon'], $match);
Chris@0 60 }
Chris@0 61
Chris@0 62 public function testGlobToRegexDoubleStarWithoutLeadingSlash()
Chris@0 63 {
Chris@0 64 $finder = new Finder();
Chris@0 65 $finder->ignoreDotFiles(false);
Chris@0 66 $regex = Glob::toRegex('/Fixtures/one/**');
Chris@0 67
Chris@0 68 foreach ($finder->in(__DIR__) as $k => $v) {
Chris@17 69 $k = str_replace(\DIRECTORY_SEPARATOR, '/', $k);
Chris@17 70 if (preg_match($regex, substr($k, \strlen(__DIR__)))) {
Chris@17 71 $match[] = substr($k, 10 + \strlen(__DIR__));
Chris@0 72 }
Chris@0 73 }
Chris@0 74 sort($match);
Chris@0 75
Chris@17 76 $this->assertSame(['one/a', 'one/b', 'one/b/c.neon', 'one/b/d.neon'], $match);
Chris@0 77 }
Chris@0 78
Chris@0 79 public function testGlobToRegexDoubleStarWithoutLeadingSlashNotStrictLeadingDot()
Chris@0 80 {
Chris@0 81 $finder = new Finder();
Chris@0 82 $finder->ignoreDotFiles(false);
Chris@0 83 $regex = Glob::toRegex('/Fixtures/one/**', false);
Chris@0 84
Chris@0 85 foreach ($finder->in(__DIR__) as $k => $v) {
Chris@17 86 $k = str_replace(\DIRECTORY_SEPARATOR, '/', $k);
Chris@17 87 if (preg_match($regex, substr($k, \strlen(__DIR__)))) {
Chris@17 88 $match[] = substr($k, 10 + \strlen(__DIR__));
Chris@0 89 }
Chris@0 90 }
Chris@0 91 sort($match);
Chris@0 92
Chris@17 93 $this->assertSame(['one/.dot', 'one/a', 'one/b', 'one/b/c.neon', 'one/b/d.neon'], $match);
Chris@0 94 }
Chris@0 95 }