-
Notifications
You must be signed in to change notification settings - Fork 0
/
regex_test.go
61 lines (54 loc) · 1.13 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
package goabnf_test
import (
"regexp"
"testing"
goabnf "github.com/pandatix/go-abnf"
"github.com/stretchr/testify/assert"
)
var testsRegex = map[string]struct {
Grammar *goabnf.Grammar
Rulename string
ExpectErr bool
}{
"abnf-alpha": {
Grammar: goabnf.ABNF,
Rulename: "alpha",
ExpectErr: false,
},
"cycle": {
Grammar: mustGrammar(string(cycleAbnf)),
Rulename: "a",
ExpectErr: true,
},
"void": {
Grammar: mustGrammar(string(voidAbnf)),
Rulename: "",
ExpectErr: true,
},
"nocycle": {
Grammar: mustGrammar(string(nocycleAbnf)),
Rulename: "a",
ExpectErr: false,
},
"group-option": {
Grammar: mustGrammar("a = 1*(*[\"b.\"] *3%x61.7a)\r\n"),
Rulename: "a",
ExpectErr: false,
},
}
func Test_U_Regex(t *testing.T) {
t.Parallel()
for testname, tt := range testsRegex {
t.Run(testname, func(t *testing.T) {
assert := assert.New(t)
reg, err := tt.Grammar.Regex(tt.Rulename)
if (err != nil) != tt.ExpectErr {
t.Fatalf("Expected err: %t ; got %s", tt.ExpectErr, err)
return
}
// Check can compile to Go regex
_, err = regexp.Compile(reg)
assert.Nil(err)
})
}
}