-
Notifications
You must be signed in to change notification settings - Fork 7
/
ignore_test.go
70 lines (63 loc) · 1.5 KB
/
ignore_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package chkbit
import (
"testing"
)
func TestShouldIgnore(t *testing.T) {
context := &Context{
IncludeDot: true,
}
ignore1 := &Ignore{
parentIgnore: nil,
context: context,
path: "na",
name: "vienna/",
itemList: []string{"*.txt", "/photo.jpg", "tokyo", "/sydney", "berlin/oslo"},
}
ignore2 := &Ignore{
parentIgnore: ignore1,
context: context,
path: "na",
name: "berlin/",
itemList: []string{"/*.md"},
}
ignore3 := &Ignore{
parentIgnore: ignore2,
context: context,
path: "na",
name: "sydney/",
itemList: []string{},
}
tests := []struct {
ignore *Ignore
filename string
expected bool
}{
// test root
{ignore1, "all.txt", true},
{ignore1, "readme.md", false},
{ignore1, "photo.jpg", true},
{ignore1, "berlin", false},
// test directories
{ignore1, "tokyo", true},
{ignore1, "sydney", true},
// test in berlin
{ignore2, "all.txt", true},
{ignore2, "readme.md", true},
{ignore2, "photo.jpg", false},
// test directories
{ignore2, "tokyo", true},
{ignore2, "sydney", false},
{ignore2, "oslo", true},
// test in sydney
{ignore3, "all.txt", true},
{ignore3, "readme.md", false},
{ignore3, "photo.jpg", false},
}
for _, tt := range tests {
t.Run("test "+tt.filename+" in "+tt.ignore.name, func(t *testing.T) {
if tt.ignore.shouldIgnore(tt.filename) != tt.expected {
t.Errorf("shouldIgnore(%s) = %v, want %v", tt.filename, !tt.expected, tt.expected)
}
})
}
}