package test import ( domainArticle "RenewCMS/internal/domain/article" "RenewCMS/internal/infrastructure/markdown" "errors" "testing" ) func TestMarkdownConverterFidelity(t *testing.T) { converter := markdown.NewConverter() examples := []struct { name, html, markdown string }{ {"headings", "
b i
", "**b** *i*"}, {"link", ``, "[link](https://example.com/x)"}, {"bullet list", "a
b
a
b
a
a
n
", "> q"}, {"code block", `q
x := 1`, "```go\nx := 1\n```"},
{"rule", "
`, ""},
{"script and style removed", "ok
", "ok"}, {"unsupported span stripped", `xy
`, "xy"}, {"inline code", "use go test
a
b
<script>
", "\\", "```\na\nb\n```"}, {"adjacent same marks merge", "ab
", "**ab**"}, {"adjacent different marks stay apart", "ab
", "**a***b*"}, {"two paragraphs", "a
b
", "a\n\nb"}, {"centered paragraph", `hi b
`, "a
`, "a
`, "a
`, "a"}, {"left alignment is the default", `a
`, "a"}, {"unknown alignment ignored", `a
`, "a"}, {"style without value ignored", `a
`, "a"}, {"empty aligned paragraph", ``, ""}, {"aligned paragraph in list item", `a
`, ">q
x
y
a * b _c_ `d` [e]
", "a \\* b \\_c\\_ \\`d\\` \\[e\\]"}, {"leading hash is escaped", "# not a heading
", "\\# not a heading"}, {"hash without space is kept", "#tag
", "#tag"}, {"leading dash is escaped", "- not a list
", "\\- not a list"}, {"leading plus is escaped", "+ not a list
", "\\+ not a list"}, {"leading quote marker is escaped", "> not a quote
", "\\> not a quote"}, {"leading number is escaped", "1. not a list
", "1\\. not a list"}, {"leading number with parenthesis is escaped", "2) not a list
", "2\\) not a list"}, {"leading rule is escaped", "---
", "\\---"}, {"leading equals is escaped", "==
", "\\=="}, {"inner dash is kept", "a - b
", "a - b"}, {"marker after a line break is escaped", "a
- b
Intro bold and it
one
two

x := 1quote
a
" got, err := converter.Render(html, domainArticle.BodyFormatHTML) if err != nil || got != html { t.Errorf("html must pass through unchanged, got %q, %v", got, err) } if _, err := converter.Render(html, domainArticle.BodyFormat("pdf")); !errors.Is(err, domainArticle.ErrUnsupportedBodyFormat) { t.Errorf("expected ErrUnsupportedBodyFormat, got %v", err) } }