Cleanup ignore tests

This commit is contained in:
Jakob Borg 2014-01-12 11:10:15 -07:00
parent 45fcf4bc84
commit af399ae9f3
2 changed files with 21 additions and 34 deletions

View File

@ -227,15 +227,6 @@ func (m *Model) cleanTempFiles() {
filepath.Walk(m.dir, m.cleanTempFile) 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 { func ignoreFile(patterns map[string][]string, file string) bool {
first, last := path.Split(file) first, last := path.Split(file)
for prefix, pats := range patterns { for prefix, pats := range patterns {

View File

@ -55,32 +55,28 @@ func TestIgnore(t *testing.T) {
"foo": {"bar", "z*"}, "foo": {"bar", "z*"},
"foo/baz": {"quux", ".*"}, "foo/baz": {"quux", ".*"},
} }
var files = []File{ var tests = []struct {
{Name: "foo/bar"}, f string
{Name: "foo/quux"}, r bool
{Name: "foo/zuux"}, }{
{Name: "foo/qzuux"}, {"foo/bar", true},
{Name: "foo/baz/t1"}, {"foo/quux", false},
{Name: "foo/baz/t2"}, {"foo/zuux", true},
{Name: "foo/baz/bar"}, {"foo/qzuux", false},
{Name: "foo/baz/quuxa"}, {"foo/baz/t1", false},
{Name: "foo/baz/aquux"}, {"foo/baz/t2", true},
{Name: "foo/baz/.quux"}, {"foo/baz/bar", true},
{Name: "foo/baz/zquux"}, {"foo/baz/quuxa", false},
{Name: "foo/baz/quux"}, {"foo/baz/aquux", false},
{Name: "foo/bazz/quux"}, {"foo/baz/.quux", true},
} {"foo/baz/zquux", true},
var remaining = []File{ {"foo/baz/quux", true},
{Name: "foo/quux"}, {"foo/bazz/quux", false},
{Name: "foo/qzuux"},
{Name: "foo/baz/t1"},
{Name: "foo/baz/quuxa"},
{Name: "foo/baz/aquux"},
{Name: "foo/bazz/quux"},
} }
var filtered = ignoreFilter(patterns, files) for i, tc := range tests {
if !reflect.DeepEqual(filtered, remaining) { if r := ignoreFile(patterns, tc.f); r != tc.r {
t.Errorf("Filtering mismatch\n %v\n %v", remaining, filtered) t.Errorf("Incorrect ignoreFile() #%d; E: %v, A: %v", i, tc.r, r)
}
} }
} }