-
Notifications
You must be signed in to change notification settings - Fork 0
/
glob_test.go
88 lines (80 loc) · 2.34 KB
/
glob_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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package mapreduce
import (
"testing"
)
func TestPotentialMatches(t *testing.T) {
data := map[string]struct {
filter PathFilter
path string
expected bool
}{
"partial directory": {Wildcard + "/" + Wildcard, "foo", true},
"partial match": {"*o", "foo", true},
"exact directory": {"foo/" + Wildcard, "foo", true},
"non-matching directory": {"bar/" + Wildcard, "foo", false},
"matching file": {Wildcard, "foo.json", true},
"recursive directory": {RecursiveWildcard + "/foo.json", "a", true},
"two directory depth": {"a/b/foo.json", "a/b", true},
"non-matching sub directory": {Wildcard + "/c", "a/b", false},
}
for k, d := range data {
if r := d.filter.CouldMatch(d.path); r != d.expected {
t.Errorf(
"%v failed: Filter %v on %v - result %v",
k,
d.filter,
d.path,
r,
)
}
}
}
func TestMatches(t *testing.T) {
data := map[string]struct {
filter PathFilter
path string
expected bool
}{
"two wild": {Wildcard + "/" + Wildcard, "foo/bar.json", true},
"file match wild": {Wildcard + ".json", "bar.json", true},
"no file match": {Wildcard + ".txt", "bar.json", false},
"recursive match": {RecursiveWildcard + "/a.txt", "a/b/c/a.txt", true},
"too deep": {"*/*/a.txt", "a/b/c/a.txt", false},
"recursive and wildcard": {RecursiveWildcard + "/" + Wildcard, "a/b/c/a.txt", true},
"front recursive": {"a/" + RecursiveWildcard, "a/b/c/a.txt", true},
"middle recursive": {"a/" + RecursiveWildcard + "/c/a.txt", "a/b/c/a.txt", true},
}
for k, d := range data {
if r := d.filter.Match(d.path); r != d.expected {
t.Errorf(
"%v failed: Filter %v on %v - result %v",
k,
d.filter,
d.path,
r,
)
}
}
}
func TestExpectedFailures(t *testing.T) {
t.Skip("These tests are known failure cases")
data := map[string]struct {
filter PathFilter
path string
expected bool
}{
"two wild": {RecursiveWildcard + "/" + RecursiveWildcard, "foo/bar.json", true},
"split recursive": {RecursiveWildcard + "/foo/" + RecursiveWildcard, "a/foo/bar.json", true},
}
for k, d := range data {
if r := d.filter.Match(d.path); r != d.expected {
t.Errorf(
"%v failed: Filter %v on %v - result %v",
k,
d.filter,
d.path,
r,
)
}
}
}