-
Notifications
You must be signed in to change notification settings - Fork 9
/
lexer_test.go
57 lines (52 loc) · 1.14 KB
/
lexer_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
package parser
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestGenKeywordIdent(t *testing.T) {
testCases := map[string][]byte{
"a": []byte("[Aa]"),
"B": []byte("[Bb]"),
"case": []byte("[Cc][Aa][Ss][Ee]"),
"CASE": []byte("[Cc][Aa][Ss][Ee]"),
"CaSe": []byte("[Cc][Aa][Ss][Ee]"),
"a_b": []byte("[Aa]_[Bb]"),
"": nil,
}
for input, expect := range testCases {
actual := genKeywordIdent(input)
assert.Equal(t, string(expect), string(actual))
}
}
type genGroupKeywordCase struct {
expect []byte
input []string
}
func TestGenGroupKeywordIdent(t *testing.T) {
testCases := []genGroupKeywordCase{
{
input: []string{},
expect: nil,
},
{
input: []string{"a"},
expect: []byte("[Aa]"),
},
{
input: []string{"B"},
expect: []byte("[Bb]"),
},
{
input: []string{"a", "B"},
expect: []byte("[Aa]( |\t|\n|\r)+[Bb]"),
},
{
input: []string{"a", "B", "CasE"},
expect: []byte("[Aa]( |\t|\n|\r)+[Bb]( |\t|\n|\r)+[Cc][Aa][Ss][Ee]"),
},
}
for _, c := range testCases {
actual := genGroupKeywordIdent(c.input...)
assert.Equal(t, string(c.expect), string(actual))
}
}