package stringutil import "testing" func TestHTML2Text(t *testing.T) { tests := []struct { name string html string want string }{ { name: "accented entities and formatting", html: `
Hello,
See the invoice or mail billing.
`, want: "Hello,\n\nSee the invoice or mail billing.", }, { name: "lists", html: `| Plan | Price |
|---|---|
| Pro | €29 |
spaced & entities <x> "q"
`, want: "spaced & entitiesa
b
after
`, want: "a\nb\n\nafter", }, { name: "images dropped", html: `
text after images`,
want: "text after images",
},
{
name: "malformed nesting",
html: `quoted lineafter quote`, want: "quoted line\n\nafter quote", }, { name: "plain text passthrough", html: `plain text, no html at all`, want: "plain text, no html at all", }, { name: "empty input", html: ``, want: "", }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if got := HTML2Text(tt.html); got != tt.want { t.Errorf("got %q, want %q", got, tt.want) } }) } }