toolbox/tui/wordwrap_test.go

57 lines
825 B
Go
Raw Normal View History

2021-03-31 08:27:54 +00:00
package tui
import (
"reflect"
"testing"
)
func TestWrapText(t *testing.T) {
type TestCase struct {
In string
W int
Lines []string
Width int
}
cases := []TestCase{
{
In: "The rain in spain falls mainly in the plane.",
W: 9,
Lines: []string{
"The rain",
"in spain",
"falls",
"mainly in",
"the",
"plane.",
},
Width: 9,
}, {
In: "The\n\nrain in spain falls mainly in the plane.",
W: 9,
Lines: []string{
"The",
"",
"rain in",
"spain",
"falls",
"mainly in",
"the",
"plane.",
},
Width: 9,
},
}
for _, tc := range cases {
lines, width := WrapText(tc.In, tc.W)
if !reflect.DeepEqual(lines, tc.Lines) {
t.Fatalf("%#v %#v", lines, tc.Lines)
}
if width != tc.Width {
t.Fatal(width, tc.Width)
}
}
}