Lowercase redirect targets for sentence-case link text
This commit is contained in:
parent
3ba7eaefd0
commit
728020d342
2 changed files with 80 additions and 1 deletions
75
test_match.py
Normal file
75
test_match.py
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
import unittest
|
||||
|
||||
from add_links.match import NoMatch, find_link_in_content
|
||||
|
||||
|
||||
class FindLinkInContentTests(unittest.TestCase):
|
||||
def test_links_first_of_two_adjacent_existing_links(self) -> None:
|
||||
content = (
|
||||
"'''''North Star''''' is a 1974 British [[thriller novel]] by "
|
||||
"[[Hammond Innes]].<ref>Vinson & Kirkpatrick p.455</ref> "
|
||||
"A man tries to prevent a plot to blow up a [[North Sea]] [[oil rig]]."
|
||||
)
|
||||
|
||||
new_content, replacement, replaced_text = find_link_in_content(
|
||||
"North Sea oil", content
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
new_content,
|
||||
"'''''North Star''''' is a 1974 British [[thriller novel]] by "
|
||||
"[[Hammond Innes]].<ref>Vinson & Kirkpatrick p.455</ref> "
|
||||
"A man tries to prevent a plot to blow up a "
|
||||
"[[North Sea oil|North Sea]] [[oil rig]].",
|
||||
)
|
||||
self.assertEqual(replacement, "North Sea oil")
|
||||
self.assertEqual(replaced_text, "North Sea]] [[oil")
|
||||
|
||||
def test_merges_existing_link_with_following_plain_text(self) -> None:
|
||||
content = "[[anti-globalization]] movement"
|
||||
|
||||
new_content, replacement, replaced_text = find_link_in_content(
|
||||
"anti-globalization movement", content
|
||||
)
|
||||
|
||||
self.assertEqual(new_content, "[[anti-globalization movement]]")
|
||||
self.assertEqual(replacement, "anti-globalization movement")
|
||||
self.assertEqual(replaced_text, "anti-globalization]] movement")
|
||||
|
||||
def test_links_prefix_before_existing_link(self) -> None:
|
||||
content = "cross-platform [[interchange station]]"
|
||||
|
||||
new_content, replacement, replaced_text = find_link_in_content(
|
||||
"cross-platform interchange", content
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
new_content,
|
||||
"[[cross-platform interchange|cross-platform]] [[interchange station]]",
|
||||
)
|
||||
self.assertEqual(replacement, "cross-platform interchange")
|
||||
self.assertEqual(replaced_text, "cross-platform [[interchange")
|
||||
|
||||
def test_lowercases_redirect_target_for_sentence_case_display_text(self) -> None:
|
||||
content = (
|
||||
"The absence of a voters' roll requirement was controversial, with "
|
||||
"the NCA alleging potential rigging through ballot stuffing and "
|
||||
"coercion in rural areas."
|
||||
)
|
||||
|
||||
new_content, replacement, replaced_text = find_link_in_content(
|
||||
"ballot stuffing", content, "Electoral fraud"
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
new_content,
|
||||
"The absence of a voters' roll requirement was controversial, with "
|
||||
"the NCA alleging potential rigging through "
|
||||
"[[electoral fraud|ballot stuffing]] and coercion in rural areas.",
|
||||
)
|
||||
self.assertEqual(replacement, "electoral fraud|ballot stuffing")
|
||||
self.assertEqual(replaced_text, "ballot stuffing")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue