package htmlutil
import "testing"
func TestExtractText(t *testing.T) {
testcases := [][2]string{
{"hello", "
hello
"},
{"hello world", "hello
world"},
{"helloworld", "hello
world"},
{"hello world", "hello world
"},
{"helloworld", "helloworld
"},
{"hello world!", "hello world
!"},
{"hello world !", "hello world\r\n
!"},
}
for _, testcase := range testcases {
want := testcase[0]
base := testcase[1]
have := ExtractText(base)
if want != have {
t.Logf("base: %#v\n", base)
t.Logf("want: %#v\n", want)
t.Logf("have: %#v\n", have)
t.Fail()
}
}
}
func TestTruncateText(t *testing.T) {
input := "Lorem ipsum — классический текст-«рыба»"
size := 30
want := "Lorem ipsum — классический ..."
have := TruncateText(input, size)
if want != have {
t.Errorf("\nsize: %d\nwant: %#v\nhave: %#v", size, want, have)
}
size = 1000
want = input
have = TruncateText(input, size)
if want != have {
t.Errorf("\nsize: %d\nwant: %#v\nhave: %#v", size, want, have)
}
}