From f3fb9c75eb7117a516cde86604cf1774c1fa4ec3 Mon Sep 17 00:00:00 2001 From: Genarito Date: Wed, 9 Jun 2021 10:59:57 -0300 Subject: [PATCH] + Fixed https://github.com/gura-conf/gura/issues/1 --- gura/GuraParser.py | 2 ++ tests/arrays/test.py | 16 ++++++++++++++++ tests/arrays/tests-files/array_in_object.ura | 5 +++++ .../array_in_object_trailing_comma.ura | 5 +++++ 4 files changed, 28 insertions(+) create mode 100644 tests/arrays/tests-files/array_in_object.ura create mode 100644 tests/arrays/tests-files/array_in_object_trailing_comma.ura diff --git a/gura/GuraParser.py b/gura/GuraParser.py index 1770c74..87fe288 100644 --- a/gura/GuraParser.py +++ b/gura/GuraParser.py @@ -375,9 +375,11 @@ def list(self) -> MatchResult: item = item.value[0] else: item = item.value + result.append(item) self.maybe_match('ws') + self.maybe_match('new_line') if not self.maybe_keyword(','): break diff --git a/tests/arrays/test.py b/tests/arrays/test.py index c4bac19..bdaca47 100644 --- a/tests/arrays/test.py +++ b/tests/arrays/test.py @@ -52,6 +52,15 @@ def setUp(self): ] } + self.expected_inside_object = { + "model": { + "columns": [ + ["var1", "str"], + ["var2", "str"] + ] + } + } + def __get_file_parsed_data(self, file_name) -> Dict: """ Gets the content of a specific file parsed @@ -73,6 +82,13 @@ def test_with_comments(self): parsed_data = self.__get_file_parsed_data('with_comments.ura') self.assertDictEqual(parsed_data, self.expected) + 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') + self.assertDictEqual(parsed_data, self.expected_inside_object) + parsed_data = self.__get_file_parsed_data('array_in_object_trailing_comma.ura') + self.assertDictEqual(parsed_data, self.expected_inside_object) + if __name__ == '__main__': unittest.main() diff --git a/tests/arrays/tests-files/array_in_object.ura b/tests/arrays/tests-files/array_in_object.ura new file mode 100644 index 0000000..0d62a7b --- /dev/null +++ b/tests/arrays/tests-files/array_in_object.ura @@ -0,0 +1,5 @@ +model: + columns: [ + [ "var1", "str" ], + [ "var2", "str" ] + ] \ No newline at end of file diff --git a/tests/arrays/tests-files/array_in_object_trailing_comma.ura b/tests/arrays/tests-files/array_in_object_trailing_comma.ura new file mode 100644 index 0000000..34d47b3 --- /dev/null +++ b/tests/arrays/tests-files/array_in_object_trailing_comma.ura @@ -0,0 +1,5 @@ +model: + columns: [ + [ "var1", "str" ], + [ "var2", "str" ], + ] \ No newline at end of file