internal/httpd/headings_test.go
20 lines · 573 bytes
1package httpd
2
3import (
4 "strings"
5 "testing"
6)
7
8// A rendered README sits under the page's own h1, so its headings move
9// down one level, ids intact; h6 stays h6 (#133).
10func TestDemoteHeadings(t *testing.T) {
11 out := string(renderReadme("README.md", []byte("# Top\n\n## Next\n\n###### Deep\n")))
12 for _, want := range []string{`<h2 id="top">Top</h2>`, `<h3 id="next">Next</h3>`, `<h6 id="deep">Deep</h6>`} {
13 if !strings.Contains(out, want) {
14 t.Errorf("lacks %s:\n%s", want, out)
15 }
16 }
17 if strings.Contains(out, "<h1") {
18 t.Errorf("an h1 survived:\n%s", out)
19 }
20}