-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
regex_test.go
64 lines (57 loc) · 1.19 KB
/
regex_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 gouse
import (
"testing"
)
func TestIsMatchReg(t *testing.T) {
var arr = []struct {
regex string
input string
expected bool
}{
{
regex: "^[a-zA-Z0-9]{3,20}$",
input: "zoomer",
expected: true,
},
{
regex: "^[a-zA-Z0-9]{3,20}$",
input: "zoomer123",
expected: true,
},
}
for _, item := range arr {
actual := IsMatchReg(item.regex, item.input)
if actual != item.expected {
t.Errorf("IsMatch(%q, %q): expected %t, actual %t", item.regex, item.input, item.expected, actual)
}
}
}
func BenchmarkIsMatchReg(b *testing.B) {
for i := 0; i < b.N; i++ {
IsMatchReg("^[a-zA-Z0-9]{3,20}$", "zoomer")
}
}
func TestMatchReg(t *testing.T) {
arr := []struct {
regex string
input string
expected []string
}{
{
regex: "[A-Z]",
input: "Hello World 123",
expected: []string{"H", "W"},
},
}
for _, item := range arr {
actual := MatchReg(item.regex, item.input)
if len(actual) != len(item.expected) {
t.Errorf("Match(%q, %q): expected %q, actual %q", item.regex, item.input, item.expected, actual)
}
}
}
func BenchmarkMatch(b *testing.B) {
for i := 0; i < b.N; i++ {
MatchReg("[A-Z]", "Hello World 123")
}
}