This repository has been archived on 2021-03-25. You can view files and clone it, but cannot push or open issues/pull-requests.
tui/stringutil_test.go

78 lines
1.1 KiB
Go

package tui
import (
"reflect"
"testing"
)
func TestNormalizeText(t *testing.T) {
type TestCase struct {
In string
Out string
}
cases := []TestCase{
{"a", "a"},
{" a\n", "a"},
{" a\nbc\n\nd ", "a bc\n\nd"},
{" a\n b\n \n\n\tc d ", "a b\n\nc d"},
}
for _, tc := range cases {
out := normalizeText(tc.In)
if out != tc.Out {
t.Fatal(out, tc.Out)
}
}
}
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)
}
}
}