-
Notifications
You must be signed in to change notification settings - Fork 1
/
match_test.go
74 lines (67 loc) · 1.62 KB
/
match_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
package main
import "testing"
func TestMatch(t *testing.T) {
tab := []struct {
pat string
str string
res bool
}{
{"a", "a", true},
{"a", "b", false},
{"a*", "abc", true},
{"a*c", "abc", true},
{"*c", "abc", true},
{"*", "a", true},
{"*", "ab", true},
{"**", "ab", false},
{"**", "a*", true},
// match handles literal string
{"one", "one", true},
{"one", "", false},
{"one", "on", false},
{"one", "onf", false},
{"one", "one*", false},
{"one", "onetwo", false},
// match handles empty string
{"", "", true},
{"", "x", false},
// match handles full-line wildcard
{"*", "", true},
{"*", "x", true},
{"*", "*", true},
{"*", "one", true},
// match handles ending wildcard
{"one*", "one", true},
{"one*", "one*", true},
{"one*", "onetwo", true},
{"one*", "", false},
{"one*", "x", false},
{"one*", "on", false},
{"one*", "onf", false},
// match handles wildcard termination
{"* one", " one", true},
{"* one", "x one", true},
{"* one", "* one", true},
{"* one", "xy one", true},
{"* one", "one", false},
{"* one", " two", false},
{"* one", " one", false},
{"* one", "xy one ", false},
// match handles multiple wildcards
{"* * one", " one", true},
{"* * one", "x one", true},
{"* * one", " y one", true},
{"* * one", "x y one", true},
{"* * one", "one", false},
{"* * one", " one", false},
{"* * one", " one", false},
{"* * one", " one", true},
}
for _, entry := range tab {
res := match(entry.pat, entry.str)
if res != entry.res {
t.Errorf("match(%s,%s) returned not %v, but %v",
entry.pat, entry.str, entry.res, res)
}
}
}