40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Verification test: md-heading-normalize produces correct ATX output."""
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
import os
|
|
|
|
SCRIPT = '/root/.hermes/wizard-outputs/quill/work/md-heading-normalize.py'
|
|
|
|
CASES = [
|
|
# (input, expected_output)
|
|
("Title\n=====\n\nBody.\n", "# Title\n\nBody.\n"),
|
|
("Section\n-------\n", "## Section\n"),
|
|
("# H1\n## H2\n### H3\n#### H4\n##### H5\n###### H6\n####### H7\n",
|
|
"# H1\n## H2\n### H3\n#### H4\n##### H5\n###### H6\n###### H7\n"),
|
|
("plain text\n# not setext\n===\n", "plain text\n# not setext\n===\n"), # only setext if *next* line is ===
|
|
("# H1\nsome text\n## H2\n", "# H1\nsome text\n## H2\n"),
|
|
]
|
|
|
|
passed = 0
|
|
failed = 0
|
|
for idx, (src, expected) in enumerate(CASES):
|
|
with tempfile.NamedTemporaryFile('w', suffix='.md', delete=False) as f:
|
|
f.write(src)
|
|
path = f.name
|
|
try:
|
|
result = subprocess.run([sys.executable, SCRIPT, path], capture_output=True, text=True)
|
|
got = result.stdout
|
|
if got == expected:
|
|
passed += 1
|
|
else:
|
|
failed += 1
|
|
print(f'FAIL case {idx}:\n expected={expected!r}\n got={got!r}', file=sys.stderr)
|
|
finally:
|
|
os.unlink(path)
|
|
|
|
print(f'PASS={passed} FAIL={failed}')
|
|
if failed:
|
|
sys.exit(1)
|