diff options
Diffstat (limited to 'vendor/github.com/hashicorp/hcl/hcl/token/token_test.go')
-rw-r--r-- | vendor/github.com/hashicorp/hcl/hcl/token/token_test.go | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/hcl/hcl/token/token_test.go b/vendor/github.com/hashicorp/hcl/hcl/token/token_test.go new file mode 100644 index 000000000..e4b4af25b --- /dev/null +++ b/vendor/github.com/hashicorp/hcl/hcl/token/token_test.go @@ -0,0 +1,69 @@ +package token + +import ( + "reflect" + "testing" +) + +func TestTypeString(t *testing.T) { + var tokens = []struct { + tt Type + str string + }{ + {ILLEGAL, "ILLEGAL"}, + {EOF, "EOF"}, + {COMMENT, "COMMENT"}, + {IDENT, "IDENT"}, + {NUMBER, "NUMBER"}, + {FLOAT, "FLOAT"}, + {BOOL, "BOOL"}, + {STRING, "STRING"}, + {HEREDOC, "HEREDOC"}, + {LBRACK, "LBRACK"}, + {LBRACE, "LBRACE"}, + {COMMA, "COMMA"}, + {PERIOD, "PERIOD"}, + {RBRACK, "RBRACK"}, + {RBRACE, "RBRACE"}, + {ASSIGN, "ASSIGN"}, + {ADD, "ADD"}, + {SUB, "SUB"}, + } + + for _, token := range tokens { + if token.tt.String() != token.str { + t.Errorf("want: %q got:%q\n", token.str, token.tt) + } + } + +} + +func TestTokenValue(t *testing.T) { + var tokens = []struct { + tt Token + v interface{} + }{ + {Token{Type: BOOL, Text: `true`}, true}, + {Token{Type: BOOL, Text: `false`}, false}, + {Token{Type: FLOAT, Text: `3.14`}, float64(3.14)}, + {Token{Type: NUMBER, Text: `42`}, int64(42)}, + {Token{Type: IDENT, Text: `foo`}, "foo"}, + {Token{Type: STRING, Text: `"foo"`}, "foo"}, + {Token{Type: STRING, Text: `"foo\nbar"`}, "foo\nbar"}, + {Token{Type: STRING, Text: `"${file("foo")}"`}, `${file("foo")}`}, + { + Token{ + Type: STRING, + Text: `"${replace("foo", ".", "\\.")}"`, + }, + `${replace("foo", ".", "\\.")}`}, + {Token{Type: HEREDOC, Text: "<<EOF\nfoo\nbar\nEOF"}, "foo\nbar"}, + } + + for _, token := range tokens { + if val := token.tt.Value(); !reflect.DeepEqual(val, token.v) { + t.Errorf("want: %v got:%v\n", token.v, val) + } + } + +} |