-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmatch_test.go
64 lines (55 loc) · 1.46 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
package onigmo
import "testing"
// Code copied from https://github.com/golang/go/blob/go1.14/src/regexp/all_test.go#L79-L134
func matchTest(t *testing.T, test *FindTest) {
re := compileTest(t, test.pat, "")
if re == nil {
return
}
m := re.MatchString(test.text)
if m != (len(test.matches) > 0) {
t.Errorf("MatchString failure on %s: %t should be %t", test, m, len(test.matches) > 0)
}
// now try bytes
m = re.Match([]byte(test.text))
if m != (len(test.matches) > 0) {
t.Errorf("Match failure on %s: %t should be %t", test, m, len(test.matches) > 0)
}
}
func TestMatch(t *testing.T) {
for _, test := range findTests {
matchTest(t, &test)
}
}
func matchFunctionTest(t *testing.T, test *FindTest) {
m, err := MatchString(test.pat, test.text)
if err == nil {
return
}
if m != (len(test.matches) > 0) {
t.Errorf("Match failure on %s: %t should be %t", test, m, len(test.matches) > 0)
}
}
func TestMatchFunction(t *testing.T) {
for _, test := range findTests {
matchFunctionTest(t, &test)
}
}
func copyMatchTest(t *testing.T, test *FindTest) {
re := compileTest(t, test.pat, "")
if re == nil {
return
}
m1 := re.MatchString(test.text)
m2 := re.Copy().MatchString(test.text)
if m1 != m2 {
t.Errorf("Copied Regexp match failure on %s: original gave %t; copy gave %t; should be %t",
test, m1, m2, len(test.matches) > 0)
}
}
func TestCopyMatch(t *testing.T) {
for _, test := range findTests {
copyMatchTest(t, &test)
}
}
// End copied code