Skip to content

Commit

Permalink
Fix complex types parsing in attributes_load
Browse files Browse the repository at this point in the history
  • Loading branch information
petroprotsakh committed Jul 3, 2024
1 parent a84b285 commit 7ae8702
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pygohcl.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func ParseAttributes(a *C.char) (resp C.parseResponse) {

var diags hcl.Diagnostics
hclMap := make(jsonObj)
c := converter{}
c := converter{[]byte(input)}

attrs, attrsDiags := hclFile.Body.JustAttributes()
diags = diags.Extend(attrsDiags)
Expand Down
58 changes: 58 additions & 0 deletions tests/test_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,61 @@ def test_heredoc():
EOT
"""
assert pygohcl.attributes_loads(s) == {"var": "hey\nyou\n"}


def test_complex_objects():
s = """
var = [
{
a = 1
b = 2
},
{
a = "1"
b = false
},
{
a = [1, 2, 3]
b = [4, 5, 6]
},
{
c = {
a = 1
b = [true, false]
}
}
]
"""
assert pygohcl.attributes_loads(s) == {
"var": [
{
"a": 1,
"b": 2,
},
{
"a": "1",
"b": False,
},
{
"a": [
1,
2,
3,
],
"b": [
4,
5,
6,
],
},
{
"c": {
"a": 1,
"b": [
True,
False,
],
},
},
]
}

0 comments on commit 7ae8702

Please sign in to comment.