diff -r d436b88d137b -r 7d712d2bde73 printer/html2text/html2text_test.go --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/printer/html2text/html2text_test.go Fri May 12 23:31:21 2017 +0200 @@ -0,0 +1,177 @@ +package html2text + +import ( + "github.com/stretchr/testify/assert" + "testing" +) + +func TestTextify(t *testing.T) { + expected := "body\nbody2" + r, e := Textify("body
body2") + assert.Nil(t, e) + assert.Equal(t, expected, r) +} + +func TestTextifyDiv(t *testing.T) { + expected := "first\nsecond" + r, e := Textify("
first
second") + assert.Nil(t, e) + assert.Equal(t, expected, r) +} + +/* +func TestTextifyLink(t *testing.T) { + expected := "somelink (link: someurl)" + r, e := Textify("somelink") + assert.Nil(t, e) + assert.Equal(t, expected, r) +} +*/ + +func TestTextifyDontDuplicateLink(t *testing.T) { + expected := "www.awesome.com" + r, e := Textify("www.awesome.com") + assert.Nil(t, e) + assert.Equal(t, expected, r) +} + +func TestTextifySpaces(t *testing.T) { + expected := "hello" + r, e := Textify("
hello
") + assert.Nil(t, e) + assert.Equal(t, expected, r) +} + +/* I don't think we want that for Mastodon... +func TestTextifySpacesMultiple(t *testing.T) { + expected := "hello goodbye" + r, e := Textify(" hello goodbye ") + assert.Nil(t, e) + assert.Equal(t, expected, r) +} +*/ + +func TestTextifyNonBreakingSpace(t *testing.T) { + expected := "a a" + r, e := Textify("a   a") + assert.Equal(t, expected, r) + assert.Nil(t, e) +} + +func TestTextifyLimitedNewLines(t *testing.T) { + expected := "abc\nxyz" + r, e := Textify("abc



xyz") + assert.Nil(t, e) + assert.Equal(t, expected, r) +} + +func TestTextifyTable(t *testing.T) { + expected := `Join by phone +1-877-668-4490 Call-in toll-free number (US/Canada) +1-408-792-6300 Call-in toll number (US/Canada) +Access code: 111 111 111 +https://akqa.webex.com/akqa/globalcallin.php?serviceType=MC&ED=299778282&tollFree=1 | http://www.webex.com/pdf/tollfree_restrictions.pdf` + + test := `
Join by phone
1-877-668-4490 Call-in toll-free number (US/Canada)
1-408-792-6300 Call-in toll number (US/Canada)
Access code: 111 111 111
Global call-in numbers  |  Toll-free calling restrictions
` + + r, e := Textify(test) + assert.Nil(t, e) + assert.Equal(t, expected, r) +} + +func TestTextifyComment(t *testing.T) { + expected := "this should appear" + r, e := Textify("this should appear") + assert.Nil(t, e) + assert.Equal(t, expected, r) +} + +func TestTextifyCommentInHead(t *testing.T) { + expected := "qwerty" + + body := ` qwerty ` + + r, e := Textify(body) + assert.Nil(t, e) + assert.Equal(t, expected, r) +} + +func TestTextifyLists(t *testing.T) { + expected := "a\nb\n1\n2" + + body := `
  1. a
  2. b
` + + r, e := Textify(body) + assert.Nil(t, e) + assert.Equal(t, expected, r) +} + +func TestTextifyMastodonSample1(t *testing.T) { + expected := "@magi hello \\U0001F607 @TEST" + + body := `

@magi hello \U0001F607 @TEST

` + + r, e := Textify(body) + assert.Nil(t, e) + assert.Equal(t, expected, r) +} + +func TestTextifyMastodonSample2(t *testing.T) { + expected := "@cadey It looks good at first glance\n\"case <-stop\" Actually you don't listen to stop channel, you close it if you want to stop the listener." + + body := `

@cadey It looks good at first glance

"case <-stop" Actually you don't listen to stop channel, you close it if you want to stop the listener.

` + + r, e := Textify(body) + assert.Nil(t, e) + assert.Equal(t, expected, r) +} + +func TestTextifyMastodonSample3(t *testing.T) { + expected := "From timeline: Materials research creates potential for improved computer chips and transistors #phys #physics ..." + + body := `From timeline: Materials research creates potential for improved computer chips and transistors #phys #physics

...

` + + r, e := Textify(body) + assert.Nil(t, e) + assert.Equal(t, expected, r) +} + +func TestTextifyMastodonSample4(t *testing.T) { + expected := "Vous reprendrez bien un peu de #Tolkein ?\n#Arte +7 propose un ensemble de 6 vidéos en plus du documentaire:\nhttp://www.arte.tv/fr/videos/RC-014610/tolkien/" + + body := `

Vous reprendrez bien un peu de #Tolkein ?
#Arte+7 propose un ensemble de 6 vidéos en plus du documentaire:

arte.tv/fr/videos/RC-014610/to

` + + r, e := Textify(body) + assert.Nil(t, e) + assert.Equal(t, expected, r) +} + +func TestTextifyMastodonMentionAndTag(t *testing.T) { + expected := "@ACh Mais heu ! Moi aussi je fais du #TootRadio de gens morts il y a 5 siècles. Gesulado, Charpentier, Mireille Mathieu..." + + body := `

@ACh Mais heu ! Moi aussi je fais du #TootRadio de gens morts il y a 5 siècles. Gesulado, Charpentier, Mireille Mathieu...

` + + r, e := Textify(body) + assert.Nil(t, e) + assert.Equal(t, expected, r) +} + +func TestTextifyMastodonLinkSpacing(t *testing.T) { + expected := "\"Twitter\" https://twitter.com/holly/status/123456789012345678" + + body := `

"Twitter" twitter.com/holly/status/86266

` + + r, e := Textify(body) + assert.Nil(t, e) + assert.Equal(t, expected, r) +} + +func TestTextifyMastodonMentionGNUSocial(t *testing.T) { + expected := "@username Hello." + + body := `@username Hello.` + + r, e := Textify(body) + assert.Nil(t, e) + assert.Equal(t, expected, r) +}