-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconvert_re2_test.go
99 lines (72 loc) · 2.45 KB
/
convert_re2_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
package main
import (
"testing"
"github.com/dlclark/regexp2/syntax"
)
func runNoMatch(t *testing.T, pattern, reExec, input string) {
m := matchString(t, pattern, reExec, input)
validateNoMatch(t, pattern, m, input)
}
func runMatch(t *testing.T, pattern, reExec, input, expected string) {
m := matchString(t, pattern, reExec, input)
validateMatch(t, pattern, m, expected, input)
}
func TestRE2NamedAscii_Concat(t *testing.T) {
pattern := "[[:digit:]a]"
exec := generateAndCompile(t, pattern, syntax.RE2)
runNoMatch(t, pattern, exec, "b")
runMatch(t, pattern, exec, "a", " 0: a")
runNoMatch(t, pattern, exec, "[")
runMatch(t, pattern, exec, "5", " 0: 5")
}
func TestRE2Dollar_Singleline(t *testing.T) {
// PCRE allows for \n after the $ and RE2 doesn't
pattern := `^ac$\n`
exec := generateAndCompile(t, pattern, syntax.RE2)
runNoMatch(t, pattern, exec, "ac")
runNoMatch(t, pattern, exec, "ac\n")
}
func TestRE2Dollar_Multiline(t *testing.T) {
pattern := `^ac$\n`
exec := generateAndCompile(t, pattern, syntax.RE2|syntax.Multiline)
runNoMatch(t, pattern, exec, "ac")
runMatch(t, pattern, exec, "ac\n", " 0: ac\\x0a")
}
func TestRE2ExtendedZero(t *testing.T) {
notZero := "߀" // \u07c0
exec := generateAndCompile(t, `^\d$`, syntax.RE2)
runNoMatch(t, `^\d$`, exec, notZero)
exec = generateAndCompile(t, `^\D$`, syntax.RE2)
runMatch(t, `^\D$`, exec, notZero, " 0: \\xdf\\x80")
}
func TestRegularExtendedZero(t *testing.T) {
notZero := "߀" // \u07c0
exec := generateAndCompile(t, `^\d$`, 0)
runMatch(t, `^\d$`, exec, notZero, " 0: \\xdf\\x80")
exec = generateAndCompile(t, `^\D$`, 0)
runNoMatch(t, `^\D$`, exec, notZero)
}
func TestRE2Word(t *testing.T) {
exec := generateAndCompile(t, `\w`, syntax.RE2)
runNoMatch(t, `\w`, exec, "å")
exec = generateAndCompile(t, `\W`, syntax.RE2)
runMatch(t, `\W`, exec, "å", " 0: \\xc3\\xa5")
}
func TestRegularWord(t *testing.T) {
exec := generateAndCompile(t, `\w`, 0)
runMatch(t, `\w`, exec, "å", " 0: \\xc3\\xa5")
exec = generateAndCompile(t, `\W`, 0)
runNoMatch(t, `\W`, exec, "å")
}
func TestRE2Space(t *testing.T) {
exec := generateAndCompile(t, `\s`, syntax.RE2)
runNoMatch(t, `\s`, exec, "\x0b")
exec = generateAndCompile(t, `\S`, syntax.RE2)
runMatch(t, `\S`, exec, "\x0b", " 0: \\x0b")
}
func TestRegularSpace(t *testing.T) {
exec := generateAndCompile(t, `\s`, 0)
runMatch(t, `\s`, exec, "\x0b", " 0: \\x0b")
exec = generateAndCompile(t, `\S`, 0)
runNoMatch(t, `\S`, exec, "\x0b")
}