Resolve every name in a citation and pin the arrow spelling
This commit is contained in:
@@ -4,14 +4,18 @@ import subprocess
|
||||
import unittest
|
||||
|
||||
ROOT = pathlib.Path(__file__).resolve().parents[1]
|
||||
CITATION = re.compile(r'CLAUDE\.md`?[ ,→]+"([^"]+)"')
|
||||
CITATION = re.compile(r'`?CLAUDE\.md`? → ("[^"]+"(?:,? (?:and )?"[^"]+")*)')
|
||||
HEADING = re.compile(r"^#+ (.+?)(?: \(.*\))?$", re.MULTILINE)
|
||||
LEAD = re.compile(r"^(?:- )?\*\*(.+?)(?:\*\*|[:.]| —)", re.MULTILINE)
|
||||
NAME = re.compile(r'"([^"]+)"')
|
||||
|
||||
|
||||
class Citations(unittest.TestCase):
|
||||
def test_every_cited_heading_is_in_claude_md(self):
|
||||
headings = set(HEADING.findall((ROOT / "CLAUDE.md").read_text()))
|
||||
def test_every_citation_names_a_heading_then_headings_or_bold_leads_of_claude_md(self):
|
||||
text = (ROOT / "CLAUDE.md").read_text()
|
||||
headings = set(HEADING.findall(text))
|
||||
leads = headings | set(LEAD.findall(text))
|
||||
tracked = subprocess.run(["git", "ls-files", "-z"], capture_output=True, check=True, cwd=ROOT, text=True).stdout.split("\0")
|
||||
cited = [(path, heading) for path in filter(None, tracked) for heading in CITATION.findall((ROOT / path).read_text())]
|
||||
cited = [(path, NAME.findall(run)) for path in filter(None, tracked) for run in CITATION.findall((ROOT / path).read_text())]
|
||||
self.assertTrue(cited)
|
||||
self.assertEqual([f"{path}: {heading}" for path, heading in cited if heading not in headings], [])
|
||||
self.assertEqual([f"{path}: {names}" for path, names in cited if names[0] not in headings or set(names[1:]) - leads], [])
|
||||
|
||||
Reference in New Issue
Block a user