package web
import (
"regexp"
"strings"
"testing"
)
// NO FORM INSIDE A PARAGRAPH.
//
// HTML closes a <p> the moment a <form> opens, so the text after the
// form falls out of the paragraph and onto a line of its own: the CI
// page's "Acknowledge all · gate history" rendered as a button, then a
// stray "· gate history" underneath. Any template that nests one is
// caught here.
func TestNoFormSitsInsideAParagraph(t *testing.T) {
src := webSource(t)
open := regexp.MustCompile(`<p(\s[^>]*)?>`)
for _, m := range open.FindAllStringIndex(src, -1) {
end := strings.Index(src[m[1]:], "</p>")
if end < 0 {
continue
}
body := src[m[1] : m[1]+end]
if strings.Contains(body, "<form") && !strings.Contains(body, "<p") {
line := strings.Count(src[:m[0]], "\n") + 1
t.Errorf("FAIL: web.go:%d nests a <form> inside a <p>: %.80s", line, src[m[0]:])
}
}
}