showcase
- v0.2.4
- 37 commits
- 1 branch
- 6 tags
- updated
- CI 2/2
markdown_test.go
1.8 KB · 34 lines
1package render23import (4 "strings"5 "testing"6)78func TestReadmeHTML(t *testing.T) {9 for _, c := range []struct{ name, in, want string }{10 {"centred header",11 "<p align=\"center\">\n <img src=\"Packaging/screenshots/hero.png\" width=\"800\" alt=\"Rhea — app\">\n</p>\n\n<h1 align=\"center\">Rhea</h1>\n",12 "<p align=\"center\">\n <img src=\"/rhea/raw/Packaging/screenshots/hero.png\" width=\"800\" alt=\"Rhea — app\">\n</p>\n<h1 align=\"center\">Rhea</h1>"},13 {"div around markdown", "<div align=\"center\">\n\n**hi**\n\n</div>\n", "<div align=\"center\">\n<p><strong>hi</strong></p>\n</div>"},14 {"inline badge", "see <a href=\"https://ci.example\"><img src=\"https://ci.example/b.svg\" alt=\"ci\"></a> now",15 "<p>see <a href=\"https://ci.example\"><img src=\"https://ci.example/b.svg\" alt=\"ci\"></a> now</p>"},16 {"unclosed tags end with the document", "<div>\n<b>x\n", "<div>\n<b>x\n</b></div>"},17 {"stray close", "</div></section>\n\ntext", "<p>text</p>"},18 {"script and its text", "<script>alert(1)</script>\n", ""},19 {"handlers and styles", "<p onclick=\"x()\" style=\"color:red\" class=\"a\">hi</p>\n", "<p>hi</p>"},20 {"javascript link", "<p><a href=\"javascript:alert(1)\">x</a></p>\n", "<p><a>x</a></p>"},21 {"http image keeps alt", "<p><img src=\"http://x/a.png\" alt=\"pic\"></p>\n", "<p>pic</p>"},22 {"unknown tags keep text", "<p><span><iframe src=x></iframe>hi & <marquee>bye</marquee></span></p>\n", "<p>hi & bye</p>"},23 {"bad sizes", "<img src=\"a.png\" width=\"1;x\" height=\"20\">\n", "<img src=\"/rhea/raw/a.png\" height=\"20\">"},24 {"comment", "<!-- <script>x</script> -->\n", ""},25 } {26 got, err := Markdown([]byte(c.in), "/rhea", "")27 if err != nil {28 t.Fatal(err)29 }30 if g := strings.TrimSpace(string(got)); g != c.want {31 t.Errorf("%s:\n got %q\nwant %q", c.name, g, c.want)32 }33 }34}