diff options
-rw-r--r-- | pom_parser/__init__.py | 5 | ||||
-rw-r--r-- | tests/__init__.py | 15 | ||||
-rw-r--r-- | tests/parsing.py | 16 |
3 files changed, 36 insertions, 0 deletions
diff --git a/pom_parser/__init__.py b/pom_parser/__init__.py index 4604a78..35d0f49 100644 --- a/pom_parser/__init__.py +++ b/pom_parser/__init__.py @@ -437,6 +437,9 @@ class _Parser: except UnicodeDecodeError: self._error('Bad UTF-8') return '' + if self.line_number == 1 and line.startswith('\ufeff'): + # skip byte order mark + line = line[1:] if line.endswith('\r\n'): line = line[:-2] elif line.endswith('\n'): @@ -496,6 +499,8 @@ class _Parser: value = line[equals_idx+1:].lstrip(' \t') if value.startswith('"') or value.startswith('`'): value = self._parse_quoted_value(value) + else: + value = value.rstrip(' \t') key = f'{self.current_section}.{relative_key}' if self.current_section else relative_key item = Item() item.key = key diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e9737ec --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1,15 @@ +import unittest +import os +from tests import parsing + +class TestParsing(unittest.TestCase): + def test_all(self) -> None: + test_dir = '../tests/parsing' + for file in os.listdir(test_dir): + if not file.endswith('.flat.pom'): continue + with self.subTest(file): + parsing.test_path(self, f'{test_dir}/{file}') + +if __name__ == '__main__': + unittest.main() + diff --git a/tests/parsing.py b/tests/parsing.py new file mode 100644 index 0000000..185cde9 --- /dev/null +++ b/tests/parsing.py @@ -0,0 +1,16 @@ +import pom_parser +import unittest + +def test_path(tester: unittest.TestCase, flat_path: str) -> None: + conf_path = flat_path.replace('.flat.pom', '.pom') + conf = pom_parser.load_path(conf_path) + flat = pom_parser.load_path(flat_path) + conf_items = {} + for item in conf.items(): + tester.assertTrue(flat.has(item.key), f'{conf_path} has key {item.key} but {flat_path} does not') + conf_items[item.key] = item + for item in flat.items(): + tester.assertTrue(conf.has(item.key), f'{flat_path} has key {item.key} but {conf_path} does not') + conf_item = conf_items[item.key] + tester.assertEqual(conf_item.value, item.value, f'Values for key {item.key} do not match.') + |