filepathfilter: return include/exclude patterns via Include(), Exclude()

This commit is contained in:
Taylor Blau 2017-06-23 12:05:46 -06:00
parent d284a9908e
commit 266296eb5c
2 changed files with 31 additions and 0 deletions

@ -27,6 +27,25 @@ func New(include, exclude []string) *Filter {
return NewFromPatterns(convertToPatterns(include), convertToPatterns(exclude))
}
// Include returns the result of calling String() on each Pattern in the
// include set of this *Filter.
func (f *Filter) Include() []string { return patternsToStrings(f.include...) }
// Exclude returns the result of calling String() on each Pattern in the
// exclude set of this *Filter.
func (f *Filter) Exclude() []string { return patternsToStrings(f.exclude...) }
// patternsToStrings maps the given set of Pattern's to a string slice by
// calling String() on each pattern.
func patternsToStrings(ps ...Pattern) []string {
s := make([]string, 0, len(ps))
for _, p := range ps {
s = append(s, p.String())
}
return s
}
func (f *Filter) Allows(filename string) bool {
_, allowed := f.AllowsPattern(filename)
return allowed

@ -205,3 +205,15 @@ func TestFilterAllows(t *testing.T) {
}
}
}
func TestFilterReportsIncludePatterns(t *testing.T) {
filter := New([]string{"*.foo", "*.bar"}, nil)
assert.Equal(t, []string{"*.foo", "*.bar"}, filter.Include())
}
func TestFilterReportsExcludePatterns(t *testing.T) {
filter := New(nil, []string{"*.baz", "*.quux"})
assert.Equal(t, []string{"*.baz", "*.quux"}, filter.Exclude())
}