package mailer import ( "testing" ) func TestHtml2Text(t *testing.T) { scenarios := []struct { html string expected string }{ { "", "", }, { "ab c", "ab c", }, { "", "", }, { " a ", "a", }, { "abc", "abc", }, { `test`, "[test](a/b/c)", }, { `test`, "[test]", }, { "a b", "a b", }, { "a b c", "a b c", }, { "a b
c
", "a b \r\nc", }, { `

Lorem ipsum

Dolor sit amet

Verify


Verify2.1 Verify2.2



  • ul.test1
  • ul.test2
  • ul.test3
  1. ol.test1
  2. ol.test2
  3. ol.test3

Thanks,
PocketBase team

`, "Lorem ipsum \r\nDolor sit amet \r\n[Verify](a/b/c) \r\n[Verify2.1 Verify2.2](a/b/c) \r\n\r\n- ul.test1 \r\n- ul.test2 \r\n- ul.test3 \r\n- ol.test1 \r\n- ol.test2 \r\n- ol.test3 \r\nThanks,\r\nPocketBase team", }, } for i, s := range scenarios { result, err := html2Text(s.html) if err != nil { t.Errorf("(%d) Unexpected error %v", i, err) } if result != s.expected { t.Errorf("(%d) Expected \n(%q)\n%v,\n\ngot:\n\n(%q)\n%v", i, s.expected, s.expected, result, result) } } }