Files
AnyPS5/tools/tests/test_check_conventions_doc_links.py
T

34 lines
1.3 KiB
Python

from pathlib import Path
import sys
import unittest
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
import check_conventions
FENCE = "`" * 3
class DocLinkTests(unittest.TestCase):
def test_code_blocks_and_inline_code_have_no_links(self):
text = f"{FENCE}cpp\nauto f = [](int a) {{ return a; }};\n{FENCE}\n~~~\nauto g = [](int b) {{}};\n~~~\nuse `[](auto)` here\n"
self.assertEqual(check_conventions.links("docs/x.md", text), [])
def test_real_link_outside_block_is_kept(self):
text = f"{FENCE}\n[](int a)\n{FENCE}\nsee [guide](../README.md)\n"
self.assertEqual(check_conventions.links("docs/x.md", text), [("../README.md", "README.md")])
def test_real_link_after_crlf_code_block_is_kept(self):
text = f"{FENCE}\r\ncode\r\n{FENCE}\r\nsee [guide](../README.md)\r\n"
self.assertEqual(check_conventions.links("docs/x.md", text), [("../README.md", "README.md")])
def test_empty_link_text_is_ignored(self):
self.assertEqual(check_conventions.links("docs/x.md", "![](img.png) and [](empty.md)"), [])
def test_fenced_lines(self):
text = f"a\n{FENCE}\n[](int a)\n{FENCE}\nb\n"
self.assertEqual(check_conventions.fenced_lines(text), {2, 3, 4})
if __name__ == "__main__":
unittest.main()