-
Notifications
You must be signed in to change notification settings - Fork 31
/
items_test.go
115 lines (104 loc) · 2.04 KB
/
items_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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package uci
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestItemTypeString(t *testing.T) {
assert := assert.New(t)
names := []string{
"Error",
"BOF",
"EOF",
"Package",
"Config",
"Option",
"List",
"Ident",
"String",
"%itemType(9)",
}
for i, expected := range names {
subject := itemType(i)
assert.Equal(expected, subject.String())
}
}
func TestScanTokenString(t *testing.T) {
assert := assert.New(t)
names := []string{
"[not initialized]",
"error",
"eof",
"package",
"config",
"option",
"list",
"%scanToken(7)",
}
for i, expected := range names {
subject := scanToken(i)
assert.Equal(expected, subject.String())
}
}
func TestItemString(t *testing.T) {
assert := assert.New(t)
tt := []struct {
subject item
expected string
}{
{
item{itemString, "foo", -1},
`(String "foo")`,
}, {
item{itemString, "foo 0123456789 bar 0123456789", -1},
`(String "foo 0123456789 bar 012345"...)`,
}, {
item{itemError, "foo 0123456789 bar 0123456789", -1},
`(Error "foo 0123456789 bar 0123456789")`,
}, {
item{itemString, "foo", 42},
`(String "foo" 42)`,
}, {
item{itemString, "foo 0123456789 bar 0123456789", 42},
`(String "foo 0123456789 bar 012345"... 42)`,
}, {
item{itemError, "foo 0123456789 bar 0123456789", 42},
`(Error "foo 0123456789 bar 0123456789" 42)`,
},
}
for i := range tt {
tc := tt[i]
assert.Equal(tc.expected, tc.subject.String())
}
}
func TestTokenString(t *testing.T) {
assert := assert.New(t)
tt := []struct {
subject token
expected string
}{
{
token{tokList, nil},
`list[]`,
}, {
token{tokPackage, []item{
{itemIdent, "foo", -1},
}},
`package[(Ident "foo")]`,
}, {
token{tokPackage, []item{
{itemIdent, "foo", 42},
}},
`package[(Ident "foo" 42)]`,
}, {
token{tokPackage, []item{
{itemIdent, "foo", 42},
{itemIdent, "bar", -1},
}},
`package[(Ident "foo" 42) (Ident "bar")]`,
},
}
for i := range tt {
tc := tt[i]
assert.Equal(tc.expected, tc.subject.String())
}
}