generated from coulomb/repo-seed
61 lines
1.9 KiB
Python
61 lines
1.9 KiB
Python
from pathlib import Path
|
|
|
|
from markitect_tool.core import parse_markdown_file
|
|
from markitect_tool.explode import explode_markdown_file, implode_markdown_directory
|
|
from markitect_tool.ops import resolve_includes
|
|
from markitect_tool.processor import ProcessorContext, run_fenced_processors
|
|
from markitect_tool.reference import load_namespaces
|
|
from markitect_tool.literate import tangle_markdown
|
|
|
|
|
|
EXAMPLES = Path("examples/migration")
|
|
|
|
|
|
def test_migration_explode_example_roundtrips(tmp_path: Path):
|
|
source = EXAMPLES / "legacy-explode-source.md"
|
|
original = source.read_text(encoding="utf-8")
|
|
|
|
explode_markdown_file(source, tmp_path / "exploded", variant="hierarchical")
|
|
result = implode_markdown_directory(tmp_path / "exploded")
|
|
|
|
assert result.markdown == original
|
|
|
|
|
|
def test_migration_reference_backed_transclusion_example():
|
|
source = EXAMPLES / "legacy-transclusion-context.md"
|
|
document = parse_markdown_file(source)
|
|
context = ProcessorContext(
|
|
root=EXAMPLES,
|
|
current_path=source,
|
|
namespaces=load_namespaces(document.frontmatter),
|
|
)
|
|
|
|
result = run_fenced_processors(source.read_text(encoding="utf-8"), context=context)
|
|
|
|
assert result.valid
|
|
assert "Payment is due within 30 days" in result.results[0].content
|
|
|
|
|
|
def test_migration_path_include_example():
|
|
source = EXAMPLES / "legacy-path-include.md"
|
|
|
|
result = resolve_includes(
|
|
source.read_text(encoding="utf-8"),
|
|
base_dir=EXAMPLES,
|
|
current_path=source,
|
|
)
|
|
|
|
assert "## Warranty" in result.markdown
|
|
assert "Warranty begins on the effective date" in result.markdown
|
|
|
|
|
|
def test_migration_literate_example_tangles():
|
|
source = EXAMPLES / "legacy-literate.md"
|
|
|
|
result = tangle_markdown(source.read_text(encoding="utf-8"), source_path=source)
|
|
|
|
assert result.valid
|
|
assert result.files[0].path == "src/app.py"
|
|
assert "CONFIG" in result.files[0].content
|
|
assert "<<config>>" not in result.files[0].content
|