Skip to content

Commit

Permalink
Easier to edit wiki links, and more
Browse files Browse the repository at this point in the history
  • Loading branch information
danuker committed Jan 26, 2021
1 parent 316a93d commit b2a0efe
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
27 changes: 17 additions & 10 deletions test/test_wiki_trac_rst_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,31 @@ def test_empty(self):
A file not ending in a newline character is not POSIX compliant,
and may result in complaints from programs, like `git diff`
saying "\ No newline at end of file".
saying "No newline at end of file".
https://stackoverflow.com/a/729795/235463
"""
self.assertConvertedContent('\n', '')

def test_newline(self):
"""
A newline should not be appended another newline.
A newline will not get appended another newline.
"""
self.assertConvertedContent('\n', '\n')

def test_removes_rst_wrapping(self):
"""
The Trac wiki syntax requires reStructuredText to be wrapped in
{{{ #!rst }}} markers.
They must be removed from the output.
It removes the TracWiki RST armor markup from the output.
"""
self.assertConvertedContent('\n', '{{{#!rst}}}')
self.assertConvertedContent(
'\n',
'\n'
'{{{\n'
'#!rst'
'\n'
'}}}')

def test_does_not_strip_content(self):
"""
Expand All @@ -56,7 +63,7 @@ def test_trac_rst_wiki_link(self):
"""

self.assertConvertedContent(
'`Requirements <Requirements>`__\n',
'`<Requirements>`_\n',
':trac:`wiki:Requirements`'
)

Expand All @@ -67,18 +74,18 @@ def test_trac_rst_wiki_link_to_page_in_subdir(self):
"""

self.assertConvertedContent(
'`General/FreeSoftwareUsage <General-FreeSoftwareUsage>`__\n',
'`<General-FreeSoftwareUsage>`_\n',
':trac:`wiki:General/FreeSoftwareUsage`'
)

def test_trac_rst_wiki_reverse_link(self):
"""
Some Trac RST wiki links are "reversed", with the URL first and
the `:trac:` marker last. Handle them.
Trac RST wiki links that are "reversed", with the URL first and
the `:trac:` marker last are also handled.
"""

self.assertConvertedContent(
'`Infrastructure/Services/LAN#services <Infrastructure-Services-LAN#services>`__\n',
'`<Infrastructure-Services-LAN#services>`_\n',
'`wiki:Infrastructure/Services/LAN#services`:trac:'
)

Expand All @@ -89,9 +96,9 @@ def test_several_trac_wiki_rst_links_with_content(self):
"""

self.assertConvertedContent(
'* `Requirements <Requirements>`__\n'
'* `<Requirements>`_\n'
'* Some content\n'
'* `General/FreeSoftwareUsage <General-FreeSoftwareUsage>`__'
'* `<General-FreeSoftwareUsage>`_'
' List of free software used by Chevah Project.\n',

'* :trac:`wiki:Requirements`\n'
Expand Down
2 changes: 1 addition & 1 deletion wiki_trac_rst_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def _trac_rst_wiki_to_github_links(text: str):
for title in wiki_titles:
text = re.sub(
link_re,
rf'`\1 <{_wiki_url(title)}>`__',
rf'`<{_wiki_url(title)}>`_',
text,
1
)
Expand Down

0 comments on commit b2a0efe

Please sign in to comment.