Skip to content

Commit 27a04ad

Browse files
Merge pull request #26 from Scalr/fix-complex-attributes-load
Fix complex types parsing in attributes_load
2 parents a84b285 + 7ae8702 commit 27a04ad

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

pygohcl.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func ParseAttributes(a *C.char) (resp C.parseResponse) {
6363

6464
var diags hcl.Diagnostics
6565
hclMap := make(jsonObj)
66-
c := converter{}
66+
c := converter{[]byte(input)}
6767

6868
attrs, attrsDiags := hclFile.Body.JustAttributes()
6969
diags = diags.Extend(attrsDiags)

tests/test_attributes.py

+58
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,61 @@ def test_heredoc():
8585
EOT
8686
"""
8787
assert pygohcl.attributes_loads(s) == {"var": "hey\nyou\n"}
88+
89+
90+
def test_complex_objects():
91+
s = """
92+
var = [
93+
{
94+
a = 1
95+
b = 2
96+
},
97+
{
98+
a = "1"
99+
b = false
100+
},
101+
{
102+
a = [1, 2, 3]
103+
b = [4, 5, 6]
104+
},
105+
{
106+
c = {
107+
a = 1
108+
b = [true, false]
109+
}
110+
}
111+
]
112+
"""
113+
assert pygohcl.attributes_loads(s) == {
114+
"var": [
115+
{
116+
"a": 1,
117+
"b": 2,
118+
},
119+
{
120+
"a": "1",
121+
"b": False,
122+
},
123+
{
124+
"a": [
125+
1,
126+
2,
127+
3,
128+
],
129+
"b": [
130+
4,
131+
5,
132+
6,
133+
],
134+
},
135+
{
136+
"c": {
137+
"a": 1,
138+
"b": [
139+
True,
140+
False,
141+
],
142+
},
143+
},
144+
]
145+
}

0 commit comments

Comments
 (0)