8 func TestTypeString(t *testing.T) {
9 var tokens = []struct {
33 for _, token := range tokens {
34 if token.tt.String() != token.str {
35 t.Errorf("want: %q got:%q\n", token.str, token.tt)
41 func TestTokenValue(t *testing.T) {
42 var tokens = []struct {
46 {Token{Type: BOOL, Text: `true`}, true},
47 {Token{Type: BOOL, Text: `false`}, false},
48 {Token{Type: FLOAT, Text: `3.14`}, float64(3.14)},
49 {Token{Type: NUMBER, Text: `42`}, int64(42)},
50 {Token{Type: IDENT, Text: `foo`}, "foo"},
51 {Token{Type: STRING, Text: `"foo"`}, "foo"},
52 {Token{Type: STRING, Text: `"foo\nbar"`}, "foo\nbar"},
53 {Token{Type: STRING, Text: `"${file("foo")}"`}, `${file("foo")}`},
57 Text: `"${replace("foo", ".", "\\.")}"`,
59 `${replace("foo", ".", "\\.")}`},
60 {Token{Type: HEREDOC, Text: "<<EOF\nfoo\nbar\nEOF"}, "foo\nbar"},
63 for _, token := range tokens {
64 if val := token.tt.Value(); !reflect.DeepEqual(val, token.v) {
65 t.Errorf("want: %v got:%v\n", token.v, val)