|
15 | 15 | # 9. every relative link in docs/ and examples/ resolves |
16 | 16 | # 10. a translation carries the same tables and code blocks |
17 | 17 | # 11. every chapter states its reader, its question and its exclusions |
| 18 | +# 12. a citation naming a section lands in the chapter that contains it |
18 | 19 | # |
19 | 20 | # What it deliberately does NOT check: whether a chapter documents what is |
20 | 21 | # implemented, whether an assertion's strength matches its evidence, or whether |
@@ -219,6 +220,32 @@ for f in docs/[0-9]*.md docs/zh/[0-9]*.md; do |
219 | 220 | || bad "$f: the opening states no exclusions" |
220 | 221 | done |
221 | 222 |
|
| 223 | +# ── 12. a citation that names a section lands in the chapter that has it ─ |
| 224 | +# |
| 225 | +# `See *One package, one version* in [04](04-mcpp-toml.md)` survived a split |
| 226 | +# that moved the section to chapter 23, in five places and two languages. Rule 3 |
| 227 | +# could not see it -- the path resolved; it was the wrong chapter. A citation |
| 228 | +# that names a section by TITLE is checkable against that chapter's headings. |
| 229 | +python3 - <<'PYCITE' || fail=1 |
| 230 | +import re, pathlib, sys |
| 231 | +EN = re.compile(r"See \*([^*]{3,60})\* in \[\d{2}[^\]]*\]\((\d{2}-[a-z0-9-]+)\.md\)") |
| 232 | +ZH = re.compile(r"见\s*\[\d{2}[^\]]*\]\((\d{2}-[a-z0-9-]+)\.md\)\s*的\*([^*]{2,40})\*") |
| 233 | +bad = 0 |
| 234 | +for f in list(pathlib.Path("docs").glob("[0-9]*.md")) + list(pathlib.Path("docs/zh").glob("[0-9]*.md")): |
| 235 | + text = f.read_text(errors="ignore") |
| 236 | + for m in EN.finditer(text): |
| 237 | + title, chap = m.group(1), m.group(2) |
| 238 | + t = (f.parent / f"{chap}.md") |
| 239 | + if not t.exists() or title.lower() not in t.read_text(errors="ignore").lower(): |
| 240 | + print(f"FAIL: {f}: cites *{title}* in {chap}, which does not contain it"); bad += 1 |
| 241 | + for m in ZH.finditer(text): |
| 242 | + chap, title = m.group(1), m.group(2) |
| 243 | + t = (f.parent / f"{chap}.md") |
| 244 | + if not t.exists() or title not in t.read_text(errors="ignore"): |
| 245 | + print(f"FAIL: {f}: cites *{title}* in {chap}, which does not contain it"); bad += 1 |
| 246 | +sys.exit(1 if bad else 0) |
| 247 | +PYCITE |
| 248 | + |
222 | 249 | if [[ "$fail" -eq 0 ]]; then |
223 | 250 | echo "OK: docs structure checks pass" |
224 | 251 | fi |
|
0 commit comments