| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
package gitignore |
| 22 |
|
| 23 |
import ( |
| 24 |
"testing" |
| 25 |
) |
| 26 |
|
| 27 |
func TestMatcher_Match(t *testing.T) { |
| 28 |
pattern := ParsePattern("**/middle/v[uo]l?ano", nil) |
| 29 |
matcher := NewMatcher(pattern) |
| 30 |
|
| 31 |
if !matcher.Match([]string{"head", "middle", "vulkano"}, false) { |
| 32 |
t.Error("Expected to match 'head/middle/vulkano'") |
| 33 |
} |
| 34 |
|
| 35 |
if matcher.Match([]string{"head", "middle", "other"}, false) { |
| 36 |
t.Error("Expected not to match 'head/middle/other'") |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
func TestMatcher_Exclude(t *testing.T) { |
| 41 |
pattern := ParsePattern("!volcano", nil) |
| 42 |
matcher := NewMatcher(pattern) |
| 43 |
|
| 44 |
|
| 45 |
if matcher.Match([]string{"volcano"}, false) { |
| 46 |
t.Error("Include patterns should return false") |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
func TestMatcher_ExcludeHandling(t *testing.T) { |
| 52 |
|
| 53 |
|
| 54 |
excludePattern := ParsePattern("!volcano", nil) |
| 55 |
matcher := NewMatcher(excludePattern) |
| 56 |
|
| 57 |
|
| 58 |
if matcher.Match([]string{"volcano"}, false) { |
| 59 |
t.Error("Include patterns should return false") |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
func TestMatcher_EverythingExceptExample(t *testing.T) { |
| 66 |
|
| 67 |
pattern1 := ParsePattern("/*", nil) |
| 68 |
matcher1 := NewMatcher(pattern1) |
| 69 |
|
| 70 |
if !matcher1.Match([]string{"foo"}, true) { |
| 71 |
t.Error("Expected to match 'foo'") |
| 72 |
} |
| 73 |
|
| 74 |
if !matcher1.Match([]string{"baz"}, false) { |
| 75 |
t.Error("Expected to match 'baz'") |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
pattern2 := ParsePattern("!/foo", nil) |
| 80 |
matcher2 := NewMatcher(pattern2) |
| 81 |
|
| 82 |
if matcher2.Match([]string{"foo"}, true) { |
| 83 |
t.Error("Include patterns should return false") |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
pattern3 := ParsePattern("/foo/*", nil) |
| 88 |
matcher3 := NewMatcher(pattern3) |
| 89 |
|
| 90 |
if !matcher3.Match([]string{"foo", "bar"}, false) { |
| 91 |
t.Error("Expected to match 'foo/bar'") |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
pattern4 := ParsePattern("!/foo/bar", nil) |
| 96 |
matcher4 := NewMatcher(pattern4) |
| 97 |
|
| 98 |
if matcher4.Match([]string{"foo", "bar"}, false) { |
| 99 |
t.Error("Include patterns should return false") |
| 100 |
} |
| 101 |
} |