Skip to content

Commit

Permalink
+ Fixed bug with comma in arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
Genarito committed Jul 30, 2021
1 parent d41d7ea commit ce94fca
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
6 changes: 5 additions & 1 deletion gura/GuraParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,6 @@ def pair(self) -> Optional[MatchResult]:

key = self.match('key')
self.maybe_match('ws')
self.maybe_match('new_line')

# Check indentation
last_indentation_block = self.__get_last_indentation_level()
Expand Down Expand Up @@ -503,6 +502,11 @@ def pair(self) -> Optional[MatchResult]:
else:
result = result.value

# Prevents issues with indentation inside a list that break objects
if isinstance(result, list):
self.__remove_last_indentation_level()
self.indentation_levels.append(current_indentation_level)

self.maybe_match('new_line')

return MatchResult(MatchResultType.PAIR, (key, result, current_indentation_level))
Expand Down
19 changes: 19 additions & 0 deletions tests/arrays/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ def setUp(self):
}
}

self.expected_trailing_comma = {
"foo": [
{
"bar": {
"baz": [
{"far": "faz"}
]
}
}
],
"barbaz": "boo"
}

def __get_file_parsed_data(self, file_name) -> Dict:
"""
Gets the content of a specific file parsed
Expand All @@ -82,6 +95,12 @@ def test_with_comments(self):
parsed_data = self.__get_file_parsed_data('with_comments.ura')
self.assertDictEqual(parsed_data, self.expected)

def test_bug_trailing_comma(self):
"""Tests a bug that breaks arrays with a mandatory trailing comma. In this case the trailing comma is missing
and it should parse correctly"""
parsed_data = self.__get_file_parsed_data('bug_trailing_comma.ura')
self.assertDictEqual(parsed_data, self.expected_trailing_comma)

def test_array_in_object(self):
"""Tests issue https://github.com/gura-conf/gura/issues/1"""
parsed_data = self.__get_file_parsed_data('array_in_object.ura')
Expand Down
7 changes: 7 additions & 0 deletions tests/arrays/tests-files/bug_trailing_comma.ura
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
foo: [
bar:
baz: [
far: "faz"
],
]
barbaz: "boo"

0 comments on commit ce94fca

Please sign in to comment.