package render import ( "strings" "testing" ) func TestReadmeHTML(t *testing.T) { for _, c := range []struct{ name, in, want string }{ {"centred header", "

\n \"Rhea\n

\n\n

Rhea

\n", "

\n \"Rhea\n

\n

Rhea

"}, {"div around markdown", "
\n\n**hi**\n\n
\n", "
\n

hi

\n
"}, {"inline badge", "see \"ci\" now", "

see \"ci\" now

"}, {"unclosed tags end with the document", "
\nx\n", "
\nx\n
"}, {"stray close", "
\n\ntext", "

text

"}, {"script and its text", "\n", ""}, {"handlers and styles", "

hi

\n", "

hi

"}, {"javascript link", "

x

\n", "

x

"}, {"http image keeps alt", "

\"pic\"

\n", "

pic

"}, {"unknown tags keep text", "

hi & bye

\n", "

hi & bye

"}, {"bad sizes", "\n", ""}, {"comment", "\n", ""}, } { got, err := Markdown([]byte(c.in), "/rhea", "") if err != nil { t.Fatal(err) } if g := strings.TrimSpace(string(got)); g != c.want { t.Errorf("%s:\n got %q\nwant %q", c.name, g, c.want) } } }