1 package toml
2
3 import "testing"
4
5 func TestTokenStringer(t *testing.T) {
6 var tests = []struct {
7 tt tokenType
8 expect string
9 }{
10 {tokenError, "Error"},
11 {tokenEOF, "EOF"},
12 {tokenComment, "Comment"},
13 {tokenKey, "Key"},
14 {tokenString, "String"},
15 {tokenInteger, "Integer"},
16 {tokenTrue, "True"},
17 {tokenFalse, "False"},
18 {tokenFloat, "Float"},
19 {tokenEqual, "="},
20 {tokenLeftBracket, "["},
21 {tokenRightBracket, "]"},
22 {tokenLeftCurlyBrace, "{"},
23 {tokenRightCurlyBrace, "}"},
24 {tokenLeftParen, "("},
25 {tokenRightParen, ")"},
26 {tokenDoubleLeftBracket, "]]"},
27 {tokenDoubleRightBracket, "[["},
28 {tokenLocalDate, "LocalDate"},
29 {tokenLocalTime, "LocalTime"},
30 {tokenTimeOffset, "TimeOffset"},
31 {tokenKeyGroup, "KeyGroup"},
32 {tokenKeyGroupArray, "KeyGroupArray"},
33 {tokenComma, ","},
34 {tokenColon, ":"},
35 {tokenDollar, "$"},
36 {tokenStar, "*"},
37 {tokenQuestion, "?"},
38 {tokenDot, "."},
39 {tokenDotDot, ".."},
40 {tokenEOL, "EOL"},
41 {tokenEOL + 1, "Unknown"},
42 }
43
44 for i, test := range tests {
45 got := test.tt.String()
46 if got != test.expect {
47 t.Errorf("[%d] invalid string of token type; got %q, expected %q", i, got, test.expect)
48 }
49 }
50 }
51
52 func TestTokenString(t *testing.T) {
53 var tests = []struct {
54 tok token
55 expect string
56 }{
57 {token{Position{1, 1}, tokenEOF, ""}, "EOF"},
58 {token{Position{1, 1}, tokenError, "Δt"}, "Δt"},
59 {token{Position{1, 1}, tokenString, "bar"}, `"bar"`},
60 {token{Position{1, 1}, tokenString, "123456789012345"}, `"123456789012345"`},
61 }
62
63 for i, test := range tests {
64 got := test.tok.String()
65 if got != test.expect {
66 t.Errorf("[%d] invalid of string token; got %q, expected %q", i, got, test.expect)
67 }
68 }
69 }
70
View as plain text