Skip to content

Commit 643c687

Browse files
test: add ToFsx output-comment, ToPynb execution-output, and LaTeX block tests
Six new unit tests in Markdown.fs: - ToFsx emits output comment when code block is followed by OutputBlock - ToFsx does not emit output comment when code block has no output - ToPynb code block with output produces execution output in notebook - ToPynb empty document produces notebook with empty cells array - ToMd preserves multi-line LaTeX block with align environment - ToMd serialises single-line equation block as compact dollar-dollar notation All 352 tests pass. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 01b5941 commit 643c687

1 file changed

Lines changed: 80 additions & 0 deletions

File tree

tests/FSharp.Markdown.Tests/Markdown.fs

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1894,3 +1894,83 @@ let ``ToLatex EmbedParagraphs delegates to Render()`` () =
18941894
let doc = MarkdownDocument([ EmbedParagraphs(inner, MarkdownRange.zero) ], dict [])
18951895
let result = Markdown.ToLatex(doc)
18961896
result |> should contain "latex text"
1897+
1898+
// --------------------------------------------------------------------------------------
1899+
// Markdown.ToFsx: code-with-output tests
1900+
// --------------------------------------------------------------------------------------
1901+
1902+
[<Test>]
1903+
let ``ToFsx emits output comment when code block is followed by an OutputBlock`` () =
1904+
// A CodeBlock immediately followed by an OutputBlock should produce a
1905+
// "(* output: ... *)" comment so round-tripping is faithful.
1906+
let doc =
1907+
MarkdownDocument(
1908+
[ CodeBlock("let x = 42", None, Some "```", "fsharp", "", MarkdownRange.zero)
1909+
OutputBlock("42", "text/plain", Some 1) ],
1910+
dict []
1911+
)
1912+
1913+
let result = Markdown.ToFsx(doc, newline = "\n")
1914+
result |> should contain "let x = 42"
1915+
result |> should contain "(* output:"
1916+
result |> should contain "42"
1917+
1918+
[<Test>]
1919+
let ``ToFsx does not emit output comment when code block has no output`` () =
1920+
let doc = MarkdownDocument([ CodeBlock("let y = 0", None, Some "```", "fsharp", "", MarkdownRange.zero) ], dict [])
1921+
1922+
let result = Markdown.ToFsx(doc, newline = "\n")
1923+
result |> should contain "let y = 0"
1924+
result |> should not' (contain "(* output:")
1925+
1926+
// --------------------------------------------------------------------------------------
1927+
// Markdown.ToPynb: notebook output tests
1928+
// --------------------------------------------------------------------------------------
1929+
1930+
[<Test>]
1931+
let ``ToPynb code block with output produces execution output in notebook`` () =
1932+
// A CodeBlock followed by an OutputBlock should produce a code cell with
1933+
// an "execute_result" output entry.
1934+
let doc =
1935+
MarkdownDocument(
1936+
[ CodeBlock("1 + 1", None, Some "```", "fsharp", "", MarkdownRange.zero)
1937+
OutputBlock("2", "text/plain", Some 1) ],
1938+
dict []
1939+
)
1940+
1941+
let result = Markdown.ToPynb(doc, newline = "\n")
1942+
result |> should contain "execute_result"
1943+
result |> should contain "1 + 1"
1944+
1945+
[<Test>]
1946+
let ``ToPynb empty document produces notebook with empty cells array`` () =
1947+
let doc = MarkdownDocument([], dict [])
1948+
let result = Markdown.ToPynb(doc, newline = "\n")
1949+
result |> should contain "\"nbformat\""
1950+
result |> should contain "\"cells\""
1951+
1952+
// --------------------------------------------------------------------------------------
1953+
// ToMd: multi-line LaTeX block with non-equation environment
1954+
// --------------------------------------------------------------------------------------
1955+
1956+
[<Test>]
1957+
let ``ToMd preserves multi-line LaTeX block with align environment`` () =
1958+
// Multi-line LatexBlock with a non-equation env must round-trip via \begin{}/\end{}.
1959+
// The parser reads $$...$$ as a single-line equation; for multi-line or named envs
1960+
// we construct the AST directly.
1961+
let doc = MarkdownDocument([ LatexBlock("align", [ "a &= b \\\\"; "c &= d" ], MarkdownRange.zero) ], dict [])
1962+
1963+
let result = Markdown.ToMd(doc, newline = "\n")
1964+
result |> should contain "\\begin{align}"
1965+
result |> should contain "a &= b \\\\"
1966+
result |> should contain "c &= d"
1967+
result |> should contain "\\end{align}"
1968+
1969+
[<Test>]
1970+
let ``ToMd serialises single-line equation block as compact dollar-dollar notation`` () =
1971+
// A single-line equation LatexBlock must be rendered as $$...$$ not \begin{equation}
1972+
let doc = MarkdownDocument([ LatexBlock("equation", [ "E = mc^2" ], MarkdownRange.zero) ], dict [])
1973+
1974+
let result = Markdown.ToMd(doc, newline = "\n")
1975+
result |> should contain "$$E = mc^2$$"
1976+
result |> should not' (contain "\\begin{equation}")

0 commit comments

Comments
 (0)