hcl/parser: support bools in lists

This commit is contained in:
Mitchell Hashimoto 2017-01-19 17:06:02 -08:00
parent eb6f65b2d7
commit e59762bcc7
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
4 changed files with 28 additions and 3 deletions

View File

@ -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 {

View File

@ -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

View File

@ -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{},

View File

@ -0,0 +1,6 @@
path {
policy = "write"
permissions = {
"bool" = [false]
}
}