-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils_test.go
88 lines (76 loc) · 1.43 KB
/
utils_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
package goabnf
import (
"testing"
"github.com/stretchr/testify/assert"
)
func Test_U_Atob(t *testing.T) {
t.Parallel()
var tests = map[string]struct {
Str string
Base string
ExpectedVal byte
}{
"hex": {
Str: "3c",
Base: "x",
ExpectedVal: 0x3c,
},
"binary": {
Str: "10",
Base: "b",
ExpectedVal: 0b10,
},
"decimal": {
Str: "56",
Base: "d",
ExpectedVal: 56,
},
}
for testname, tt := range tests {
t.Run(testname, func(t *testing.T) {
assert := assert.New(t)
val := atob(tt.Str, tt.Base)
assert.Equal(tt.ExpectedVal, val)
})
}
}
func Test_U_GetRule(t *testing.T) {
t.Parallel()
var tests = map[string]struct {
Rulename string
Rulemap map[string]*Rule
ExpectRule bool
}{
"core-rule": {
Rulename: "WSP",
Rulemap: ABNF.Rulemap,
ExpectRule: true,
},
"rulemap-rule": {
Rulename: "rulelist",
Rulemap: ABNF.Rulemap,
ExpectRule: true,
},
"case-insensitive": {
Rulename: "wsp",
Rulemap: ABNF.Rulemap,
ExpectRule: true,
},
"unexisting-rule": {
Rulename: "im-n07-4-rul3",
Rulemap: ABNF.Rulemap,
ExpectRule: false,
},
}
for testname, tt := range tests {
t.Run(testname, func(t *testing.T) {
assert := assert.New(t)
rule := GetRule(tt.Rulename, tt.Rulemap)
if tt.ExpectRule {
assert.NotNil(rule)
} else {
assert.Nil(rule)
}
})
}
}