feat: add Fortran support and tab controls
This commit is contained in:
+23
-4
@@ -262,12 +262,13 @@ def test_document_discovery_filters_optional_code_groups(tmp_path: Path) -> None
|
||||
(tmp_path / "guide.md").write_text("# Guide\n", encoding="utf-8")
|
||||
(tmp_path / "tool.py").write_text("def run():\n return 1\n", encoding="utf-8")
|
||||
(tmp_path / "engine.cpp").write_text("int solve() { return 1; }\n", encoding="utf-8")
|
||||
(tmp_path / "solver.f90").write_text("program demo\nend program demo\n", encoding="utf-8")
|
||||
|
||||
default_entries = discover_documents(tmp_path)
|
||||
all_entries = discover_documents(tmp_path, ("markdown", "python", "cpp"))
|
||||
all_entries = discover_documents(tmp_path, ("markdown", "python", "cpp", "fortran"))
|
||||
|
||||
assert [entry.path.name for entry in default_entries] == ["guide.md"]
|
||||
assert {entry.path.name for entry in all_entries} == {"guide.md", "tool.py", "engine.cpp"}
|
||||
assert {entry.path.name for entry in all_entries} == {"guide.md", "tool.py", "engine.cpp", "solver.f90"}
|
||||
|
||||
|
||||
def test_document_discovery_prunes_excluded_directories(tmp_path: Path) -> None:
|
||||
@@ -310,26 +311,46 @@ def test_code_file_rendering_uses_highlighting_and_line_anchors(tmp_path: Path)
|
||||
renderer = MarkdownRenderer(tmp_path)
|
||||
|
||||
html = renderer.render_code_source(source, code_path, language="python")
|
||||
fortran_html = renderer.render_code_source("program demo\nend program demo\n", tmp_path / "solver.f90", language="fortran")
|
||||
|
||||
assert "code-file-view" in html
|
||||
assert "language-python" in html
|
||||
assert "line-1" in html
|
||||
assert "Runner" in html
|
||||
assert "language-fortran" in fortran_html
|
||||
assert "line-1" in fortran_html
|
||||
assert "program" in fortran_html.lower()
|
||||
|
||||
|
||||
def test_code_headings_extract_python_and_cpp_symbols(tmp_path: Path) -> None:
|
||||
python_path = tmp_path / "tool.py"
|
||||
cpp_path = tmp_path / "engine.cpp"
|
||||
fortran_path = tmp_path / "solver.f90"
|
||||
python_source = "class Runner:\n def run(self):\n return 1\n\nasync def main():\n return None\n"
|
||||
cpp_source = "struct Node { int value; };\n\nint solve(int value) { return value; }\n"
|
||||
fortran_source = (
|
||||
"module solver_mod\n"
|
||||
"type state\nend type state\n"
|
||||
"contains\n"
|
||||
"subroutine advance(dt)\nend subroutine advance\n"
|
||||
"real function energy(x)\nend function energy\n"
|
||||
"end module solver_mod\n"
|
||||
)
|
||||
|
||||
python_headings = extract_code_headings(python_path, python_source)
|
||||
cpp_headings = extract_code_headings(cpp_path, cpp_source)
|
||||
fortran_headings = extract_code_headings(fortran_path, fortran_source)
|
||||
|
||||
assert [heading.title for heading in python_headings] == ["class Runner", "def run", "async def main"]
|
||||
assert [heading.slug for heading in python_headings] == ["line-1", "line-2", "line-5"]
|
||||
assert any(heading.title == "struct Node" for heading in cpp_headings)
|
||||
assert any(heading.title == "function solve" for heading in cpp_headings)
|
||||
assert [heading.title for heading in fortran_headings] == [
|
||||
"module solver_mod",
|
||||
"type state",
|
||||
"subroutine advance",
|
||||
"function energy",
|
||||
]
|
||||
|
||||
|
||||
def test_search_index_reads_optional_code_documents(tmp_path: Path) -> None:
|
||||
@@ -373,5 +394,3 @@ def test_code_headings_read_gbk_source_when_source_not_supplied(tmp_path: Path)
|
||||
assert headings[0].title == "class 中文类"
|
||||
assert headings[1].title == "def run"
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user