This repository has been archived by the owner on Apr 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trex_test.go
122 lines (118 loc) · 1.84 KB
/
trex_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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package trex
import (
"regexp"
"testing"
)
var (
tcMatch = []struct {
pattern string
text []string
}{
{
`.*`,
[]string{
" ",
"abcd",
},
},
{
`^[a-z]+\[[0-9]+\]$`,
[]string{
"adam[23]",
"eve[7]",
"Job[48]",
"snakey",
},
},
{
`日本語+`,
[]string{
"日本語",
"日本語語語語",
"",
},
},
{
`/$`,
[]string{
"/abc/",
"/abc",
},
},
{
`[a\-\]z]+`,
[]string{
"az]-bcz",
"abcd\n",
"abcd",
"ab1234cd",
},
},
{
`foo.*`,
[]string{
"seafood",
},
},
{
`^abcd$`,
[]string{
"abcd",
"abcde",
},
},
{
`[\w\.+-]+@[\w\.-]+\.[\w\.-]+`,
[]string{
"kuba--@noreplay.github.com",
"kuba--(at)noreplay.github.com",
},
},
{
`[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}[-a-zA-Z0-9@:%_\+.~#?&//=]*`,
[]string{
"http://www.foufos.gr",
"https://www.foufos.gr",
"http://foufos.gr",
"http://www.foufos.gr/kino",
"http://werer.gr",
"www.foufos.gr",
"www.mp3.com",
"www.t.co",
"http://t.co",
"http://www.t.co",
"https://www.t.co",
"www.aa.com",
"http://aa.com",
"http://www.aa.com",
"https://www.aa.com",
"www.foufos",
"www.foufos-.gr",
"www.-foufos.gr",
"foufos.gr",
"http://www.foufos",
"http://foufos",
"www.mp3#.com",
},
},
}
)
func TestCompileAndMatch(t *testing.T) {
for _, tc := range tcMatch {
t.Run(tc.pattern, func(t *testing.T) {
gorex := regexp.MustCompile(tc.pattern)
trex, err := Compile(tc.pattern)
if err != nil {
t.Fatalf("Compile: %v", err)
}
t.Logf("\n%s\n", trex.String())
for _, txt := range tc.text {
exp := gorex.MatchString(txt)
act := trex.Match([]byte(txt))
if act != exp {
t.Errorf("txt: %s, exp: %v, act: %v\n", txt, exp, act)
}
}
})
}
}