-
-
Notifications
You must be signed in to change notification settings - Fork 540
Expand file tree
/
Copy pathlex_test.go
More file actions
63 lines (57 loc) · 1.48 KB
/
lex_test.go
File metadata and controls
63 lines (57 loc) · 1.48 KB
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
package toml
import "testing"
func TestPositionString(t *testing.T) {
tests := []struct {
in Position
want string
}{
{Position{}, "at line 0; start 0; length 0"},
{Position{Line: 1, Col: 1, Len: 1, Start: 1}, "at line 1; start 1; length 1"},
}
for _, tt := range tests {
t.Run("", func(t *testing.T) {
have := tt.in.String()
if have != tt.want {
t.Errorf("\nhave: %q\nwant: %q", have, tt.want)
}
})
}
}
func TestItemTypeString(t *testing.T) {
for _, it := range []itemType{itemError, itemEOF, itemText,
itemString, itemStringEsc, itemRawString, itemMultilineString,
itemRawMultilineString, itemBool, itemInteger, itemFloat, itemDatetime,
itemArray, itemArrayEnd, itemTableStart, itemTableEnd, itemArrayTableStart,
itemArrayTableEnd, itemKeyStart, itemKeyEnd, itemCommentStart,
itemInlineTableStart, itemInlineTableEnd,
} {
have := it.String()
if have == "" {
t.Errorf("empty String for %T", it)
}
}
}
func TestItemString(t *testing.T) {
it := item{typ: itemString, val: "xxx", pos: Position{Line: 42, Col: 3}}
have := it.String()
want := "(String, xxx)"
if have != want {
t.Errorf("\nhave: %q\nwant: %q", have, want)
}
}
func TestStateFnString(t *testing.T) {
{
var fn stateFn = lexString
have, want := fn.String(), "lexString()"
if have != want {
t.Errorf("\nhave: %q\nwant: %q", have, want)
}
}
{
var fn stateFn
have, want := fn.String(), "<nil>"
if have != want {
t.Errorf("\nhave: %q\nwant: %q", have, want)
}
}
}