57 lines
825 B
Go
57 lines
825 B
Go
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)
|
|
}
|
|
}
|
|
}
|