diff --git a/src/wavu/test/test_wave_importer.py b/src/wavu/test/test_wavu_importer.py similarity index 100% rename from src/wavu/test/test_wave_importer.py rename to src/wavu/test/test_wavu_importer.py diff --git a/src/wavu/test/test_wavu_reader.py b/src/wavu/test/test_wavu_reader.py index 7f7044b..d28c3ee 100644 --- a/src/wavu/test/test_wavu_reader.py +++ b/src/wavu/test/test_wavu_reader.py @@ -27,6 +27,11 @@ def test_get_move(self): move = wavu_reader.get_move("Azucena-df+1,4",character_movelist) self.assertEqual(move.id,"Azucena-df+1,4") + def test_process_name(self): + character_movelist = wavu_reader.get_wavu_character_movelist("Jin") + move = wavu_reader.get_move("Jin-1,2,3",character_movelist) + self.assertEqual(move.name,"Left Right > Axe Kick") + def test_complete_parent_input(self): character_movelist = wavu_reader.get_wavu_character_movelist("Azucena") move7 = wavu_reader.get_move("Azucena-BT.3",character_movelist) @@ -56,3 +61,6 @@ def test_first_parent_input(self): move = wavu_reader.get_move("Azucena-b+4,3,4",character_movelist) self.assertEqual(move.startup,"i15~16") + def test_process_links(self): + self.assertEqual(wavu_reader._process_links('[[Snake_Edge|Snake Edge]]'), '[Snake Edge](https://wavu.wiki/t/Snake_Edge \'Snake Edge\')') + self.assertEqual(wavu_reader._process_links('[[Azucena combos#Mini-combos|+27a]]'), '[+27a](https://wavu.wiki/t/Azucena_combos#Mini-combos \'Mini-combo\')'), \ No newline at end of file diff --git a/src/wavu/wavu_reader.py b/src/wavu/wavu_reader.py index cdab1e3..d8becdd 100644 --- a/src/wavu/wavu_reader.py +++ b/src/wavu/wavu_reader.py @@ -119,7 +119,7 @@ def _convert_json_movelist(move_list_json: list) -> List[Move]: if move["title"]["ns"] == "0": alias = [] id = _normalize_data(move["title"]["id"]) - name = _normalize_data(_process_links(move["title"]["name"])) + name = html.unescape(_normalize_data(_process_links(move["title"]["name"]))) input = _normalize_data( _get_all_parent_values_of("input", _normalize_data(move["title"]["parent"]), move_list_json) + _normalize_data(move["title"]["input"])) @@ -159,13 +159,24 @@ def _remove_html_tags(data): return result -link_replace_pattern = re.compile(r'\[\[(?P[^#]+)#(?P
[^|]+)\|(?P[^|]+)\]\]') - +link_replace_pattern = re.compile(r'\[\[(?P[^#]+)(#(?P
[^|]+))?\|(?P[^|]+)\]\]') +WAVU_PAGE_STEM = 'https://wavu.wiki/t/' def _process_links(data: str | None) -> str: - def _replace_link(match): - page, section, data = match.group('page'), match.group('section'), match.group('data') - hover_text = 'Combo' if section == 'Staples' else 'Mini-combo' - return f"[{data}](https://wavu.wiki/t/{page.replace(' ', '_')}#{section} \'{hover_text}\')" + def _replace_link(matchobj): + page, section, data = matchobj.group('page'), matchobj.group('section'), matchobj.group('data') + if section: + match section: + case 'Staples': + hover_text = 'Combo' + case 'Mini-combos': + hover_text = 'Mini-combo' + case _: + hover_text = page.replace('_', ' ').title() + replacement = f"[{data}]({WAVU_PAGE_STEM}{page.replace(' ', '_')}#{section} '{hover_text}')" + else: + hover_text = page.replace('_', ' ').title() + replacement = f"[{data}]({WAVU_PAGE_STEM}{page.replace(' ', '_')} '{hover_text}')" + return replacement return link_replace_pattern.sub(_replace_link, _empty_value_if_none(data))