package stringutil import "testing" func TestHTML2Text(t *testing.T) { tests := []struct { name string html string want string }{ { name: "accented entities and formatting", html: `
Olá, tudo bem? Segue o relatório.

Abraços,
João
`, want: "Olá, tudo bem? Segue o relatório.\n\nAbraços,\nJoão.", }, { name: "links dropped", html: `

Hello,

See the invoice or mail billing.

`, want: "Hello,\n\nSee the invoice or mail billing.", }, { name: "lists", html: `
  1. One
  2. Two
`, want: "First\nSecond\n\nOne\nTwo", }, { name: "table flattened", html: `
PlanPrice
Pro€29
`, want: "Plan Price Pro €29", }, { name: "entities and nbsp", html: `

 spaced & entities <x> "q"

`, want: "spaced & entities \"q\"", }, { name: "multilingual with hidden preheader", html: `
preheader hidden
visible 您好 مرحبا שלום Grüße
`, want: "preheader hidden\nvisible 您好 مرحبا שלום Grüße", }, { name: "script and style stripped", html: `

a
b

after

`, want: "a\nb\n\nafter", }, { name: "images dropped", html: `Logotext after images`, want: "text after images", }, { name: "malformed nesting", html: `
unclosed bold both italic? end`, want: "unclosed bold both. italic? end", }, { name: "linked image keeps alt", html: `Banner`, want: "Banner", }, { name: "blockquote flattened", html: `
quoted line
after 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) } }) } }