package classes import "testing" // TestSetImageAlt pins the alt rewrite: only the matching img tag is // rewritten from its token, the alt is escaped, a missing alt is added and // every other byte is kept (T-33-04). func TestSetImageAlt(t *testing.T) { const doc = `
x & y

`
out, n, old := SetImageAlt(doc, "https://cdn.example.test/a.jpg?x=1&y=2", `Lion's "mane" `)
want := `x & y

`
if out != want || n != 1 || old != nil {
t.Fatalf("SetImageAlt = %q, %d, %v; want %q, 1, nil", out, n, old, want)
}
out, n, old = SetImageAlt(doc, "b.jpg", "")
if out != `x & y

` || n != 1 || old == nil || *old != "old" {
t.Fatalf("decorative = %q, %d, %v", out, n, old)
}
if out, n, _ := SetImageAlt(doc, "missing.jpg", "x"); out != doc || n != 0 {
t.Fatalf("missing = %q, %d", out, n)
}
}