-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathsummary_test.go
37 lines (33 loc) · 1.01 KB
/
summary_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package strutil
import (
"fmt"
"testing"
)
func TestSummary(t *testing.T) {
tests := []struct {
colLen int
end string
input string
expected string
}{
{15, "...", "", ""},
{0, "...", "Lorem ipsum dolor sit amet", "Lorem ipsum dolor sit amet"},
{12, "...", "Lorem ipsum dolor sit amet", "Lorem ipsum..."},
{12, "...", "Lorem\nipsum dolor sit amet", "Lorem..."},
{12, "...", "Lorem\tipsum\tdolor sit amet", "Lorem\tipsum..."},
{10, "...", "Lorem ipsum dolor sit amet", "Lorem..."},
{10, "...", "Lorem\nipsum dolor sit amet", "Lorem..."},
{15, "...", "Lorem ipsum", "Lorem ipsum"},
{5, "...", "Lorem ipsum", "Lorem..."},
{4, "...", "Lorem ipsum", "Lore..."},
{15, "...", "Lorem ipsum", "Lorem..."},
}
for i, test := range tests {
output := Summary(test.input, test.colLen, test.end)
Assert(t, test.expected, output, "Test case %d is not successful\n", i)
}
}
func ExampleSummary() {
fmt.Println(Summary("Lorem ipsum dolor sit amet.", 12, "..."))
// Output: Lorem ipsum...
}