diff --git a/jc/parsers/asciitable_m.py b/jc/parsers/asciitable_m.py index e6907d4c..2ae31c89 100644 --- a/jc/parsers/asciitable_m.py +++ b/jc/parsers/asciitable_m.py @@ -95,7 +95,7 @@ def _rstrip(string: str) -> str: rstrip_list = [x for x in string.splitlines() if not len(x.strip()) == 0] end_points = (len(x.rstrip()) for x in rstrip_list) max_point = max(end_points) - new_rstrip_list = (x[:max_point] for x in rstrip_list) + new_rstrip_list = ((x + ' ' * max_point)[:max_point] for x in rstrip_list) return '\n'.join(new_rstrip_list) @@ -341,6 +341,7 @@ def parse( if jc.utils.has_data(data): data = _remove_ansi(data) data = _strip(data) + print(data.replace(' ', '~')) table_type = _table_sniff(data) if table_type == 'pretty': diff --git a/tests/test_asciitable_m.py b/tests/test_asciitable_m.py index d0b29f7d..ea398b4e 100644 --- a/tests/test_asciitable_m.py +++ b/tests/test_asciitable_m.py @@ -1,5 +1,6 @@ import os import unittest +from jc.exceptions import ParseError import jc.parsers.asciitable_m THIS_DIR = os.path.dirname(os.path.abspath(__file__)) @@ -217,6 +218,32 @@ class MyTests(unittest.TestCase): self.assertEqual(jc.parsers.asciitable_m.parse(input, quiet=True), expected) + def test_asciitable_m_markdown(self): + """ + Test 'asciitable_m' with a markdown table. Should raise a ParseError + """ + input = ''' + | type | total | used | free | shared | buff cache | available | + |--------|---------|--------|---------|----------|--------------|-------------| + | Mem | 3861332 | 222820 | 3364176 | 11832 | 274336 | 3389588 | + | Swap | 2097148 | 0 | 2097148 | | | | + ''' + + self.assertRaises(ParseError, jc.parsers.asciitable_m.parse, input, quiet=True) + + def test_asciitable_m_simple(self): + """ + Test 'asciitable_m' with a simple table. Should raise a ParseError + """ + input = ''' + type total used free shared buff cache available + ------ ------- ------ ------- -------- ------------ ----------- + Mem 3861332 222820 3364176 11832 274336 3389588 + Swap 2097148 0 2097148 + ''' + + self.assertRaises(ParseError, jc.parsers.asciitable_m.parse, input, quiet=True) + if __name__ == '__main__': unittest.main()