-
Notifications
You must be signed in to change notification settings - Fork 6
/
tokens_test.go
89 lines (82 loc) · 2.31 KB
/
tokens_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
package bar
import (
"reflect"
"testing"
)
func TestTokenize(t *testing.T) {
var testCases = []struct {
formatString string
expected tokens
}{
{"", nil},
{" ", tokens{spaceToken{}}},
{":bar", tokens{barToken{}}},
{" :bar", tokens{spaceToken{}, barToken{}}},
{" :bar ", tokens{spaceToken{}, barToken{}, spaceToken{}}},
{" :bar", tokens{spaceToken{}, spaceToken{}, barToken{}}},
{":bar:bar", tokens{barToken{}, barToken{}}},
{":bar:rate", tokens{barToken{}, rateToken{}}},
{"bar", tokens{literalToken{"bar"}}},
{"bar:bar", tokens{literalToken{"bar"}, barToken{}}},
{"不与", tokens{literalToken{"不与"}}},
{"不与:bar", tokens{literalToken{"不与"}, barToken{}}},
}
for i, testCase := range testCases {
got := tokenize(testCase.formatString, nil)
if !reflect.DeepEqual(got, testCase.expected) {
t.Errorf(
"[%d] tokenize(%#v, nil)\n\n got %#v\n want %#v",
i,
testCase.formatString,
got,
testCase.expected,
)
}
}
}
func TestTokenizeWithBoundaryCharacters(t *testing.T) {
var testCases = []struct {
formatString string
expected tokens
}{
{"(:bar", tokens{literalToken{"("}, barToken{}}},
{"(:bar)", tokens{literalToken{"("}, barToken{}, literalToken{")"}}},
{":bar (:eta remaining)", tokens{barToken{}, spaceToken{}, literalToken{"("}, etaToken{}, spaceToken{}, literalToken{"remaining)"}}},
}
for i, testCase := range testCases {
got := tokenize(testCase.formatString, nil)
if !reflect.DeepEqual(got, testCase.expected) {
t.Errorf(
"[%d] tokenize(%#v, nil)\n\n got %#v\n want %#v",
i,
testCase.formatString,
got,
testCase.expected,
)
}
}
}
func TestTokenizeWithCustomVerbs(t *testing.T) {
var testCases = []struct {
formatString string
customVerbs []string
expected tokens
}{
{":custom", nil, tokens{literalToken{":custom"}}},
{":custom", []string{"custom"}, tokens{customVerbToken{"custom"}}},
{":bar:custom", []string{"custom"}, tokens{barToken{}, customVerbToken{"custom"}}},
}
for i, testCase := range testCases {
got := tokenize(testCase.formatString, testCase.customVerbs)
if !reflect.DeepEqual(got, testCase.expected) {
t.Errorf(
"[%d] tokenize(%#v, %#v)\n\n got %#v\n want %#v",
i,
testCase.formatString,
testCase.customVerbs,
got,
testCase.expected,
)
}
}
}