diff --git a/filepathfilter/filepathfilter.go b/filepathfilter/filepathfilter.go index 8f1e2693..4a9f808e 100644 --- a/filepathfilter/filepathfilter.go +++ b/filepathfilter/filepathfilter.go @@ -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 diff --git a/filepathfilter/filepathfilter_test.go b/filepathfilter/filepathfilter_test.go index 489e25ad..43c03f05 100644 --- a/filepathfilter/filepathfilter_test.go +++ b/filepathfilter/filepathfilter_test.go @@ -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()) +}