-
Notifications
You must be signed in to change notification settings - Fork 0
/
pattern_test.go
36 lines (30 loc) · 885 Bytes
/
pattern_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
package main
import "testing"
func TestMatchWildcard(t *testing.T) {
type payload struct {
pattern string
text string
match bool
}
tcs := []payload{
{pattern: "*a*b", text: "adceb", match: true},
{pattern: "*b", text: "adceb", match: true},
{pattern: "a*c?b", text: "aacdcb", match: false},
{pattern: "*ab***ba**b*b*aaab*b", text: "aaabababaaabaababbbaaaabbbbbbabbbbabbbabbaabbababab", match: true},
}
for _, tc := range tcs {
match := MatchWildcard(tc.pattern, tc.text)
if match != tc.match {
t.Fatalf("text = `%s`, pattern = `%s`, got match = %v, expected match = %v\n",
tc.text, tc.pattern, match, tc.match)
}
}
}
func BenchmarkMatchWildcard(b *testing.B) {
b.ReportAllocs()
pattern := "*ab***ba**b*b*aaab*b"
text := "aaabababaaabaababbbaaaabbbbbbabbbbabbbabbaabbababab"
for n := 0; n < b.N; n++ {
MatchWildcard(pattern, text)
}
}