Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add failing structure_list2 decoder test #22

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions src/hcl/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,20 @@ def objectlist_flat(self, lt, replace):
else:
if isinstance(v, dict):
dd = d.setdefault(k, {})
for kk, vv in iteritems(v):
if type(dd) == list:
dd.append({kk: vv})
elif kk in dd.keys():
if hasattr(vv, 'items'):
for k2, v2 in iteritems(vv):
dd[kk][k2] = v2
if type(dd) is list:
dd.append(v)
else:
for kk, vv in iteritems(v):
if kk in dd.keys():
if hasattr(vv, 'items'):
for k2, v2 in iteritems(vv):
dd[kk][k2] = v2
else:
newdd = {kk: vv}
d[k] = [dd, newdd]
dd = newdd
else:
d[k] = [dd, {kk: vv}]
else:
dd[kk] = vv
dd[kk] = vv
else:
d[k] = v

Expand Down
8 changes: 8 additions & 0 deletions tests/fixtures/structure_list2.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
top {
a = "a"
b = "b"
}
top {
b = "b"
c = "c"
}
12 changes: 12 additions & 0 deletions tests/fixtures/structure_list2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"top": [
{
"a": "a",
"b": "b"
},
{
"b": "b",
"c": "c"
}
]
}
7 changes: 7 additions & 0 deletions tests/fixtures/structure_list3.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
top {
a = "a"
b = "b"
}
top {
c = "c"
}
11 changes: 11 additions & 0 deletions tests/fixtures/structure_list3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"top": [
{
"a": "a",
"b": "b"
},
{
"c": "c"
}
]
}
2 changes: 2 additions & 0 deletions tests/test_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
('structure_flatmap.hcl', 'structure_flatmap.json', None),
('structure_list.hcl', 'structure_list.json', None), # these don't match in golang either
('structure_list.hcl', None, {'foo': [{'key': 7}, {'key': 12}]}), # nor this
('structure_list2.hcl', 'structure_list2.json', None),
('structure_list3.hcl', 'structure_list3.json', None),
('issue12.hcl', 'issue12.json', None),
#'structure_list_deep.json'
('structure_multi.hcl', 'structure_multi.json', None),
Expand Down