mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-10 15:20:56 +00:00
Cleanup ignore tests
This commit is contained in:
parent
45fcf4bc84
commit
af399ae9f3
@ -227,15 +227,6 @@ func (m *Model) cleanTempFiles() {
|
||||
filepath.Walk(m.dir, m.cleanTempFile)
|
||||
}
|
||||
|
||||
func ignoreFilter(patterns map[string][]string, files []File) (filtered []File) {
|
||||
for _, f := range files {
|
||||
if !ignoreFile(patterns, f.Name) {
|
||||
filtered = append(filtered, f)
|
||||
}
|
||||
}
|
||||
return filtered
|
||||
}
|
||||
|
||||
func ignoreFile(patterns map[string][]string, file string) bool {
|
||||
first, last := path.Split(file)
|
||||
for prefix, pats := range patterns {
|
||||
|
@ -55,32 +55,28 @@ func TestIgnore(t *testing.T) {
|
||||
"foo": {"bar", "z*"},
|
||||
"foo/baz": {"quux", ".*"},
|
||||
}
|
||||
var files = []File{
|
||||
{Name: "foo/bar"},
|
||||
{Name: "foo/quux"},
|
||||
{Name: "foo/zuux"},
|
||||
{Name: "foo/qzuux"},
|
||||
{Name: "foo/baz/t1"},
|
||||
{Name: "foo/baz/t2"},
|
||||
{Name: "foo/baz/bar"},
|
||||
{Name: "foo/baz/quuxa"},
|
||||
{Name: "foo/baz/aquux"},
|
||||
{Name: "foo/baz/.quux"},
|
||||
{Name: "foo/baz/zquux"},
|
||||
{Name: "foo/baz/quux"},
|
||||
{Name: "foo/bazz/quux"},
|
||||
}
|
||||
var remaining = []File{
|
||||
{Name: "foo/quux"},
|
||||
{Name: "foo/qzuux"},
|
||||
{Name: "foo/baz/t1"},
|
||||
{Name: "foo/baz/quuxa"},
|
||||
{Name: "foo/baz/aquux"},
|
||||
{Name: "foo/bazz/quux"},
|
||||
var tests = []struct {
|
||||
f string
|
||||
r bool
|
||||
}{
|
||||
{"foo/bar", true},
|
||||
{"foo/quux", false},
|
||||
{"foo/zuux", true},
|
||||
{"foo/qzuux", false},
|
||||
{"foo/baz/t1", false},
|
||||
{"foo/baz/t2", true},
|
||||
{"foo/baz/bar", true},
|
||||
{"foo/baz/quuxa", false},
|
||||
{"foo/baz/aquux", false},
|
||||
{"foo/baz/.quux", true},
|
||||
{"foo/baz/zquux", true},
|
||||
{"foo/baz/quux", true},
|
||||
{"foo/bazz/quux", false},
|
||||
}
|
||||
|
||||
var filtered = ignoreFilter(patterns, files)
|
||||
if !reflect.DeepEqual(filtered, remaining) {
|
||||
t.Errorf("Filtering mismatch\n %v\n %v", remaining, filtered)
|
||||
for i, tc := range tests {
|
||||
if r := ignoreFile(patterns, tc.f); r != tc.r {
|
||||
t.Errorf("Incorrect ignoreFile() #%d; E: %v, A: %v", i, tc.r, r)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user