1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Finder\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Finder\Gitignore;
class GitignoreTest extends TestCase
{
/**
* @dataProvider provider
*/
public function testCases(string $patterns, array $matchingCases, array $nonMatchingCases)
{
$regex = Gitignore::toRegex($patterns);
foreach ($matchingCases as $matchingCase) {
$this->assertRegExp($regex, $matchingCase, sprintf('Failed asserting path [%s] matches gitignore patterns [%s] using regex [%s]', $matchingCase, $patterns, $regex));
}
foreach ($nonMatchingCases as $nonMatchingCase) {
$this->assertNotRegExp($regex, $nonMatchingCase, sprintf('Failed asserting path [%s] not matching gitignore patterns [%s] using regex [%s]', $nonMatchingCase, $patterns, $regex));
}
}
/**
* @return array return is array of
* [
* [
* '', // Git-ignore Pattern
* [], // array of file paths matching
* [], // array of file paths not matching
* ],
* ]
*/
public function provider()
{
return [
[
'
*
!/bin/bash
',
['bin/cat', 'abc/bin/cat'],
['bin/bash'],
],
[
'fi#le.txt',
[],
['#file.txt'],
],
[
'
/bin/
/usr/local/
!/bin/bash
!/usr/local/bin/bash
',
['bin/cat'],
['bin/bash'],
],
[
'*.py[co]',
['file.pyc', 'file.pyc'],
['filexpyc', 'file.pycx', 'file.py'],
],
[
'dir1/**/dir2/',
['dir1/dirA/dir2/', 'dir1/dirA/dirB/dir2/'],
[],
],
[
'dir1/*/dir2/',
['dir1/dirA/dir2/'],
['dir1/dirA/dirB/dir2/'],
],
[
'/*.php',
['file.php'],
['app/file.php'],
],
[
'\#file.txt',
['#file.txt'],
[],
],
[
'*.php',
['app/file.php', 'file.php'],
['file.phps', 'file.phps', 'filephps'],
],
[
'app/cache/',
['app/cache/file.txt', 'app/cache/dir1/dir2/file.txt', 'a/app/cache/file.txt'],
[],
],
[
'
#IamComment
/app/cache/',
['app/cache/file.txt', 'app/cache/subdir/ile.txt'],
['a/app/cache/file.txt'],
],
];
}
}