package syntax import "testing" // wantHTML is wantLine for HTML. func wantHTML(t *testing.T, src string, line int, want ...string) { t.Helper() wantLine(t, LanguageHTML, src, line, want...) } func TestHTMLColoursATag(t *testing.T) { wantHTML(t, "

", 0, ":tag") wantHTML(t, "

", 0, ":tag") wantHTML(t, "
", 0, ":tag") } func TestHTMLColoursAttributesAndTheirValues(t *testing.T) { wantHTML(t, `
`, 0, ":tag") } func TestHTMLColoursTheAttributeSpellingsInTheWild(t *testing.T) { wantHTML(t, ``, 0, ":tag") } func TestTextBetweenTagsIsNotColoured(t *testing.T) { got := spansOf(t, LanguageHTML, "

hello

", 0) want := []string{":tag", ":tag"} if len(got) != len(want) { t.Fatalf("got %v, want %v", got, want) } } func TestHTMLColoursAComment(t *testing.T) { wantHTML(t, "", 0, ":comment") wantHTML(t, "

", 0, ":tag", ":comment", ":tag") } func TestAnHTMLCommentCarriesAcrossLines(t *testing.T) { src := "

" wantHTML(t, src, 0, ":comment", ":tag") } func TestTagsInsideACommentAreNotColoured(t *testing.T) { src := "" wantHTML(t, src, 1, `

:comment`) } func TestHTMLColoursTheDoctype(t *testing.T) { wantHTML(t, "", 0, ":keyword") } func TestHTMLColoursEntities(t *testing.T) { wantHTML(t, "a & b", 0, "&:constant") wantHTML(t, "© 2026", 0, "©:constant") } func TestABareAmpersandIsLeftAlone(t *testing.T) { // It is legal text, and colouring the rest of a paragraph after one would // be worse than colouring nothing. if got := spansOf(t, LanguageHTML, "Marks & Spencer", 0); len(got) != 0 { t.Errorf("a bare ampersand gave %v, want nothing coloured", got) } } func TestScriptContentsAreNotColouredAsJavaScript(t *testing.T) { // Documented as out of scope: it needs the element followed across lines // and another scanner's columns mapped back out. src := "" if got := spansOf(t, LanguageHTML, src, 1); len(got) != 0 { t.Errorf("the body of a script gave %v, want plain text", got) } } func TestAnUnclosedTagIsColouredToWhatIsThere(t *testing.T) { // A tag is unfinished most of the time it is being typed. wantHTML(t, `
\n\n

& text

\n" assertSpansFit(t, LanguageHTML, src) } func TestHTMLColoursAPageWithAccents(t *testing.T) { // A byte offset would put this line's spans out of step with what is drawn. wantHTML(t, `

évidemment

`, 0, ":tag", ":tag") }