mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-21 00:19:42 +02:00
add bold bar seperator and ANSI code tests
This commit is contained in:
@ -208,7 +208,7 @@ def _normalize_rows(table: str) -> List[str]:
|
||||
continue
|
||||
|
||||
# data row - remove column separators
|
||||
line = line.replace('│', ' ').replace('|', ' ')
|
||||
line = line.replace('│', ' ').replace('|', ' ').replace('┃', ' ')
|
||||
result.append(line)
|
||||
|
||||
result[0] = _snake_case(result[0])
|
||||
@ -244,6 +244,7 @@ def parse(
|
||||
|
||||
if jc.utils.has_data(data):
|
||||
data = _remove_ansi(data)
|
||||
print(data)
|
||||
data = _strip(data)
|
||||
data_list = _normalize_rows(data)
|
||||
raw_output = _parse_pretty(data_list)
|
||||
|
@ -204,7 +204,7 @@ def _snake_case(line: str) -> str:
|
||||
def _fixup_separators(line: str) -> str:
|
||||
"""Normalize separators, and remove first and last separators"""
|
||||
# normalize separator
|
||||
line = line.replace('│', '|')
|
||||
line = line.replace('│', '|').replace('┃', '|')
|
||||
|
||||
# remove first separator if it is the first char in the line
|
||||
if line[0] == '|':
|
||||
|
@ -270,6 +270,37 @@ class MyTests(unittest.TestCase):
|
||||
|
||||
self.assertEqual(jc.parsers.asciitable.parse(input, quiet=True), expected)
|
||||
|
||||
def test_asciitable_pretty_ansi(self):
|
||||
"""
|
||||
Test 'asciitable' with a pretty table with ANSI codes
|
||||
"""
|
||||
input = '''┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┓ \n ┃\x1b[1m \x1b[0m\x1b[1mReleased \x1b[0m\x1b[1m \x1b[0m┃\x1b[1m \x1b[0m\x1b[1mTitle \x1b[0m\x1b[1m \x1b[0m┃\x1b[1m \x1b[0m\x1b[1m Box Office\x1b[0m\x1b[1m \x1b[0m┃ \n ┡━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━┩ \n │\x1b[36m \x1b[0m\x1b[36mDec 20, 2019\x1b[0m\x1b[36m \x1b[0m│\x1b[35m \x1b[0m\x1b[35mStar Wars: The Rise of Skywalker \x1b[0m\x1b[35m \x1b[0m│\x1b[32m \x1b[0m\x1b[32m $952,110,690\x1b[0m\x1b[32m \x1b[0m│ \n │\x1b[36m \x1b[0m\x1b[36mMay 25, 2018\x1b[0m\x1b[36m \x1b[0m│\x1b[35m \x1b[0m\x1b[35mSolo: A Star Wars Story \x1b[0m\x1b[35m \x1b[0m│\x1b[32m \x1b[0m\x1b[32m $393,151,347\x1b[0m\x1b[32m \x1b[0m│ \n │\x1b[36m \x1b[0m\x1b[36mDec 15, 2017\x1b[0m\x1b[36m \x1b[0m│\x1b[35m \x1b[0m\x1b[35mStar Wars Ep. V111: The Last Jedi\x1b[0m\x1b[35m \x1b[0m│\x1b[32m \x1b[0m\x1b[32m$1,332,539,889\x1b[0m\x1b[32m \x1b[0m│ \n │\x1b[36m \x1b[0m\x1b[36mDec 16, 2016\x1b[0m\x1b[36m \x1b[0m│\x1b[35m \x1b[0m\x1b[35mRogue One: A Star Wars Story \x1b[0m\x1b[35m \x1b[0m│\x1b[32m \x1b[0m\x1b[32m$1,332,439,889\x1b[0m\x1b[32m \x1b[0m│ \n └──────────────┴───────────────────────────────────┴────────────────┘ \n'''
|
||||
|
||||
expected = [
|
||||
{
|
||||
"released": "Dec 20, 2019",
|
||||
"title": "Star Wars: The Rise of Skywalker",
|
||||
"box_office": "$952,110,690"
|
||||
},
|
||||
{
|
||||
"released": "May 25, 2018",
|
||||
"title": "Solo: A Star Wars Story",
|
||||
"box_office": "$393,151,347"
|
||||
},
|
||||
{
|
||||
"released": "Dec 15, 2017",
|
||||
"title": "Star Wars Ep. V111: The Last Jedi",
|
||||
"box_office": "$1,332,539,889"
|
||||
},
|
||||
{
|
||||
"released": "Dec 16, 2016",
|
||||
"title": "Rogue One: A Star Wars Story",
|
||||
"box_office": "$1,332,439,889"
|
||||
}
|
||||
]
|
||||
|
||||
self.assertEqual(jc.parsers.asciitable.parse(input, quiet=True), expected)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
@ -218,6 +218,30 @@ class MyTests(unittest.TestCase):
|
||||
|
||||
self.assertEqual(jc.parsers.asciitable_m.parse(input, quiet=True), expected)
|
||||
|
||||
def test_asciitable_m_pretty_ansi(self):
|
||||
"""
|
||||
Test 'asciitable-m' with a pretty table with ANSI codes
|
||||
"""
|
||||
input = '''
|
||||
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┓
|
||||
┃\x1b[1m \x1b[0m\x1b[1mReleased \x1b[0m\x1b[1m \x1b[0m┃\x1b[1m \x1b[0m\x1b[1mTitle \x1b[0m\x1b[1m \x1b[0m┃\x1b[1m \x1b[0m\x1b[1m Box Office\x1b[0m\x1b[1m \x1b[0m┃
|
||||
┡━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━┩
|
||||
│\x1b[36m \x1b[0m\x1b[36mDec 20, 2019\x1b[0m\x1b[36m \x1b[0m│\x1b[35m \x1b[0m\x1b[35mStar Wars: The Rise of Skywalker \x1b[0m\x1b[35m \x1b[0m│\x1b[32m \x1b[0m\x1b[32m $952,110,690\x1b[0m\x1b[32m \x1b[0m│
|
||||
│\x1b[36m \x1b[0m\x1b[36mMay 25, 2018\x1b[0m\x1b[36m \x1b[0m│\x1b[35m \x1b[0m\x1b[35mSolo: A Star Wars Story \x1b[0m\x1b[35m \x1b[0m│\x1b[32m \x1b[0m\x1b[32m $393,151,347\x1b[0m\x1b[32m \x1b[0m│
|
||||
│\x1b[36m \x1b[0m\x1b[36mDec 15, 2017\x1b[0m\x1b[36m \x1b[0m│\x1b[35m \x1b[0m\x1b[35mStar Wars Ep. V111: The Last Jedi\x1b[0m\x1b[35m \x1b[0m│\x1b[32m \x1b[0m\x1b[32m$1,332,539,889\x1b[0m\x1b[32m \x1b[0m│
|
||||
│\x1b[36m \x1b[0m\x1b[36mDec 16, 2016\x1b[0m\x1b[36m \x1b[0m│\x1b[35m \x1b[0m\x1b[35mRogue One: A Star Wars Story \x1b[0m\x1b[35m \x1b[0m│\x1b[32m \x1b[0m\x1b[32m$1,332,439,889\x1b[0m\x1b[32m \x1b[0m│
|
||||
└──────────────┴───────────────────────────────────┴────────────────┘
|
||||
'''
|
||||
expected = [
|
||||
{
|
||||
"released": "Dec 20, 2019\nMay 25, 2018\nDec 15, 2017\nDec 16, 2016",
|
||||
"title": "Star Wars: The Rise of Skywalker\nSolo: A Star Wars Story\nStar Wars Ep. V111: The Last Jedi\nRogue One: A Star Wars Story",
|
||||
"box_office": "$952,110,690\n$393,151,347\n$1,332,539,889\n$1,332,439,889"
|
||||
}
|
||||
]
|
||||
|
||||
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
|
||||
|
Reference in New Issue
Block a user