diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 65b199e..3cafa53 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,5 +1,6 @@ Unreleased ---------- +- Fixed a bug in ``plain_text``. (#126) - Fixed another bug in parsing tables that end without a ``|}`` mark. (#125) v0.55.6 diff --git a/tests/wikitext/test_get_bolds_and_italics.py b/tests/wikitext/test_get_bolds_and_italics.py index 47776dd..7b0ff17 100644 --- a/tests/wikitext/test_get_bolds_and_italics.py +++ b/tests/wikitext/test_get_bolds_and_italics.py @@ -1,36 +1,42 @@ from wikitextparser import Bold, Italic, parse +def assert_bold( + input_string: str, expected_bold_string: str, recursive: bool = True, / +): + assert ( + parse(input_string).get_bolds(recursive)[0].string + == expected_bold_string + ) + + +def assert_no_bold(input_string: str): + assert not parse(input_string).get_bolds(True) + + def test_get_bolds(): - def ab(s: str, o: str, r: bool = True): - assert parse(s).get_bolds(r)[0].string == o - - def anb(s: str): - assert not parse(s).get_bolds(True) - - ab("A''''''''''B", "'''B") - ab("''''''a''''''", "'''a''''") # 'a' - ab("a''''''BI", "'''BI") - ab("'''b'''", "'''b'''") - anb("''i1'''s") - anb("") - ab( + assert_bold("A''''''''''B", "'''B") + assert_bold("''''''a''''''", "'''a''''") # 'a' + assert_bold("a''''''BI", "'''BI") + assert_bold("'''b'''", "'''b'''") + assert_no_bold("''i1'''s") + assert_no_bold("") + assert_bold( "a'''" "b'''d", "'''b'''", ) - ab("'''b{{a|'''}}", "'''b{{a|'''}}") # ? - ab("a'''b{{text|c|d}}e'''f", "'''b{{text|c|d}}e'''") - ab("{{text|'''b'''}}", "'''b'''") - ab("{{text|'''b}}", "'''b") # ? - ab("[[a|'''b]] c", "'''b") - ab("{{{PARAM|'''b}}} c", "'''b") # ? + assert_bold("'''b{{a|'''}}", "'''b{{a|'''}}") # ? + assert_bold("a'''b{{text|c|d}}e'''f", "'''b{{text|c|d}}e'''") + assert_bold("{{text|'''b'''}}", "'''b'''") + assert_bold("{{text|'''b}}", "'''b") # ? + assert_bold("{{{PARAM|'''b}}} c", "'''b") # ? assert ( repr(parse("'''b\na'''c").get_bolds()) == """[Bold("'''b"), Bold("'''c")]""" ) - ab("'''b'''", "'''b'''") - ab("'''br'''c", "'''br'''") - ab("'''''b'''i", "'''b'''") + assert_bold("'''b'''", "'''b'''") + assert_bold("'''br'''c", "'''br'''") + assert_bold("'''''b'''i", "'''b'''") assert ( repr(parse("'''br'''ca").get_bolds()) == """[Bold("'''br'''ca"), Bold("'''c")]""" @@ -39,12 +45,16 @@ def anb(s: str): repr(parse("'''br'''ca").get_bolds(False)) == """[Bold("'''br'''ca")]""" ) - ab("'''b{{{p|'''}}}", "'''b{{{p|'''}}}") # ? - ab("'''a'''b", "'''a") - anb("' ' ' a ' ' '") - ab("x''' '''y", "''' '''") - ab("x''''''y", "'''y") - ab("{{text|{{text|'''b'''}}}}", "'''b'''") + assert_bold("'''b{{{p|'''}}}", "'''b{{{p|'''}}}") # ? + assert_bold("'''a'''b", "'''a") + assert_no_bold("' ' ' a ' ' '") + assert_bold("x''' '''y", "''' '''") + assert_bold("x''''''y", "'''y") + assert_bold("{{text|{{text|'''b'''}}}}", "'''b'''") + + +def test_no_end_in_wikilink(): + assert_bold("[[a|'''b]] c", "'''b") def test_get_italics(): diff --git a/tests/wikitext/test_plain_text.py b/tests/wikitext/test_plain_text.py index 566e471..8258cb6 100644 --- a/tests/wikitext/test_plain_text.py +++ b/tests/wikitext/test_plain_text.py @@ -217,3 +217,16 @@ def test_file_links(): # Fails for the following cases: # assert parse('[[Media:Example.jpg]]').plain_text() == 'Media:Example.jpg' # assert parse('[[Media:n.jpg|Sunflowers]]').plain_text() == 'Sunflowers' + + +def test_tag_containing_comment_with_no_end(): # 126 + parsed = parse( + """ + [[a|b]] + +