@@ -0,0 +1,75 @@
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# Ensure server/src is on sys.path for imports
|
||||
THIS_DIR = Path(__file__).parent
|
||||
SRC_DIR = THIS_DIR.parent.parent / "src"
|
||||
if str(SRC_DIR) not in sys.path:
|
||||
sys.path.insert(0, str(SRC_DIR))
|
||||
|
||||
import lsprotocol.types as lsp # type: ignore
|
||||
from tools.parser import CustomParser
|
||||
from tools.proc_docs import build_proc_docs
|
||||
|
||||
|
||||
def test_example_is_marked_as_tcl_code_block():
|
||||
source_lines = [
|
||||
"#____________________________________________________________________________________________",
|
||||
"# <Documentation>",
|
||||
"# This procedure creates a new directory if it does not exist.",
|
||||
"# <Arguments>",
|
||||
"# directory",
|
||||
"#\tThe full pathname of the directory to be created.",
|
||||
"# <Returnvalue>",
|
||||
"# 0 - directory created or already exists",
|
||||
"# 1 - error",
|
||||
"# <Example>",
|
||||
"# name: Example 1",
|
||||
"# code: LIB_FH_create_directory \"C:/Temp/Test\"",
|
||||
"# desc: If error = 0, the directory is created.",
|
||||
"proc LIB_FH_create_directory {directory} {",
|
||||
" return 0",
|
||||
"}",
|
||||
]
|
||||
source = "\n".join(source_lines)
|
||||
|
||||
tree = CustomParser().parse(source)
|
||||
docs = build_proc_docs(tree, source)
|
||||
|
||||
assert "LIB_FH_create_directory" in docs
|
||||
md = docs["LIB_FH_create_directory"]
|
||||
|
||||
# Headings preserved
|
||||
assert "### Documentation" in md
|
||||
assert "### Arguments" in md
|
||||
assert "### Return value" in md
|
||||
assert "### Example" in md
|
||||
|
||||
# Code fence with tcl language hint and the code line present
|
||||
assert "```tcl" in md
|
||||
assert "LIB_FH_create_directory \"C:/Temp/Test\"" in md
|
||||
assert md.strip().endswith("```")
|
||||
|
||||
|
||||
def test_internal_example_is_marked_as_tcl_code_block():
|
||||
source_lines = [
|
||||
"# <Internal Documentation>",
|
||||
"# Helper utility",
|
||||
"# <Internal Example>",
|
||||
"# code: puts \"hello\"",
|
||||
"proc helper {} {",
|
||||
" return",
|
||||
"}",
|
||||
]
|
||||
source = "\n".join(source_lines)
|
||||
|
||||
tree = CustomParser().parse(source)
|
||||
docs = build_proc_docs(tree, source)
|
||||
|
||||
assert "helper" in docs
|
||||
md = docs["helper"]
|
||||
|
||||
assert "### Internal Documentation" in md
|
||||
assert "### Internal Example" in md
|
||||
assert "```tcl" in md and "puts \"hello\"" in md and md.strip().endswith("```")
|
||||
|
||||
Reference in New Issue
Block a user