Backend: Refactor .ppignore pattern matching
Signed-off-by: Michael Mayer <michael@lastzero.net>
This commit is contained in:
parent
9eef7b37ab
commit
c8ded4c7c1
11 changed files with 21 additions and 4 deletions
|
@ -15,9 +15,10 @@ func TestDirs(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
assert.Len(t, result, 7)
|
||||
assert.Len(t, result, 8)
|
||||
assert.Contains(t, result, "/directory")
|
||||
assert.Contains(t, result, "/directory/subdirectory")
|
||||
assert.Contains(t, result, "/directory/subdirectory/animals")
|
||||
assert.Contains(t, result, "/linked")
|
||||
})
|
||||
|
||||
|
@ -30,6 +31,7 @@ func TestDirs(t *testing.T) {
|
|||
|
||||
assert.Contains(t, result, "/directory")
|
||||
assert.Contains(t, result, "/directory/subdirectory")
|
||||
assert.Contains(t, result, "/directory/subdirectory/animals")
|
||||
assert.Contains(t, result, "/linked")
|
||||
})
|
||||
|
||||
|
|
|
@ -34,8 +34,8 @@ func (i IgnoreItem) Ignore(dir, base string) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
if ignore, err := filepath.Match(i.Pattern, filepath.Join(dir, base)); ignore && err == nil {
|
||||
return true
|
||||
if strings.ContainsRune(i.Pattern, filepath.Separator) {
|
||||
base = filepath.Join(RelName(dir, i.Dir), base)
|
||||
}
|
||||
|
||||
if ignore, err := filepath.Match(i.Pattern, base); ignore && err == nil {
|
||||
|
|
|
@ -94,6 +94,9 @@ func TestIgnoreList_Ignored(t *testing.T) {
|
|||
expectIgnored := []string{
|
||||
"testdata/directory/bar.txt",
|
||||
"testdata/directory/baz.xml",
|
||||
"testdata/directory/subdirectory/animals/dog.json",
|
||||
"testdata/directory/subdirectory/animals/gopher.json",
|
||||
"testdata/directory/subdirectory/animals/gopher.md",
|
||||
"testdata/directory/subdirectory/bar",
|
||||
"testdata/directory/subdirectory/example.txt",
|
||||
"testdata/directory/subdirectory/foo.txt",
|
||||
|
|
2
pkg/fs/testdata/directory/.ppignore
vendored
2
pkg/fs/testdata/directory/.ppignore
vendored
|
@ -1,7 +1,7 @@
|
|||
subdirectory/animals/dog.*
|
||||
*.txt
|
||||
test.md
|
||||
|
||||
# This is a comment
|
||||
somefile.*
|
||||
baz*
|
||||
bar
|
||||
|
|
1
pkg/fs/testdata/directory/subdirectory/.ppignore
vendored
Normal file
1
pkg/fs/testdata/directory/subdirectory/.ppignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
bar
|
1
pkg/fs/testdata/directory/subdirectory/animals/.ppignore
vendored
Normal file
1
pkg/fs/testdata/directory/subdirectory/animals/.ppignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
gopher*
|
1
pkg/fs/testdata/directory/subdirectory/animals/cat.json
vendored
Normal file
1
pkg/fs/testdata/directory/subdirectory/animals/cat.json
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
{"name":"cat"}
|
1
pkg/fs/testdata/directory/subdirectory/animals/dog.json
vendored
Normal file
1
pkg/fs/testdata/directory/subdirectory/animals/dog.json
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
{"name":"dog"}
|
1
pkg/fs/testdata/directory/subdirectory/animals/gopher.json
vendored
Normal file
1
pkg/fs/testdata/directory/subdirectory/animals/gopher.json
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
{"name":"gopher"}
|
1
pkg/fs/testdata/directory/subdirectory/animals/gopher.md
vendored
Normal file
1
pkg/fs/testdata/directory/subdirectory/animals/gopher.md
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
# Gopher!
|
|
@ -97,6 +97,12 @@ func TestSkipWalk(t *testing.T) {
|
|||
"testdata/directory/baz.xml",
|
||||
"testdata/directory/subdirectory",
|
||||
"testdata/directory/subdirectory/.hiddenfile",
|
||||
"testdata/directory/subdirectory/.ppignore",
|
||||
"testdata/directory/subdirectory/animals",
|
||||
"testdata/directory/subdirectory/animals/.ppignore",
|
||||
"testdata/directory/subdirectory/animals/dog.json",
|
||||
"testdata/directory/subdirectory/animals/gopher.json",
|
||||
"testdata/directory/subdirectory/animals/gopher.md",
|
||||
"testdata/directory/subdirectory/example.txt",
|
||||
"testdata/directory/subdirectory/foo.txt",
|
||||
"testdata/directory/subdirectory/symlink",
|
||||
|
|
Loading…
Reference in a new issue