Skip to content

Commit e090b43

Browse files
authored
Merge pull request #1197 from fsprojects/repo-assist/test-fsx-pynb-latex-coverage-2026-05-03-30d83afa50dbf6b7
[Repo Assist] test: add ToFsx output-comment, ToPynb execution-output, and LaTeX block tests
2 parents 081ff86 + 1cb951a commit e090b43

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

0 commit comments

Comments
 (0)