From e59762bcc79fcf9f77ed8d1745d4186f4fcbc574 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 19 Jan 2017 17:06:02 -0800 Subject: [PATCH] hcl/parser: support bools in lists --- decoder_test.go | 17 +++++++++++++++++ hcl/parser/parser.go | 4 +--- hcl/parser/parser_test.go | 4 ++++ test-fixtures/object_with_bool.hcl | 6 ++++++ 4 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 test-fixtures/object_with_bool.hcl diff --git a/decoder_test.go b/decoder_test.go index 07b369d..e58165f 100644 --- a/decoder_test.go +++ b/decoder_test.go @@ -391,6 +391,23 @@ func TestDecode_interface(t *testing.T) { true, nil, }, + + { + "object_with_bool.hcl", + false, + map[string]interface{}{ + "path": []map[string]interface{}{ + map[string]interface{}{ + "policy": "write", + "permissions": []map[string]interface{}{ + map[string]interface{}{ + "bool": []interface{}{false}, + }, + }, + }, + }, + }, + }, } for _, tc := range cases { diff --git a/hcl/parser/parser.go b/hcl/parser/parser.go index 476ed04..8dd73e0 100644 --- a/hcl/parser/parser.go +++ b/hcl/parser/parser.go @@ -346,7 +346,7 @@ func (p *Parser) listType() (*ast.ListType, error) { } } switch tok.Type { - case token.NUMBER, token.FLOAT, token.STRING, token.HEREDOC: + case token.BOOL, token.NUMBER, token.FLOAT, token.STRING, token.HEREDOC: node, err := p.literalType() if err != nil { return nil, err @@ -388,8 +388,6 @@ func (p *Parser) listType() (*ast.ListType, error) { } l.Add(node) needComma = true - case token.BOOL: - // TODO(arslan) should we support? not supported by HCL yet case token.LBRACK: // TODO(arslan) should we support nested lists? Even though it's // written in README of HCL, it's not a part of the grammar diff --git a/hcl/parser/parser_test.go b/hcl/parser/parser_test.go index ea0d78f..5758658 100644 --- a/hcl/parser/parser_test.go +++ b/hcl/parser/parser_test.go @@ -58,6 +58,10 @@ func TestListType(t *testing.T) { `foo = [123, "123",]`, []token.Type{token.NUMBER, token.STRING}, }, + { + `foo = [false]`, + []token.Type{token.BOOL}, + }, { `foo = []`, []token.Type{}, diff --git a/test-fixtures/object_with_bool.hcl b/test-fixtures/object_with_bool.hcl new file mode 100644 index 0000000..e565fb4 --- /dev/null +++ b/test-fixtures/object_with_bool.hcl @@ -0,0 +1,6 @@ +path { + policy = "write" + permissions = { + "bool" = [false] + } +}