2018-05-27 10:51:42 +00:00
|
|
|
package termstatus
|
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
|
|
|
func TestTruncate(t *testing.T) {
|
|
|
|
var tests = []struct {
|
|
|
|
input string
|
2020-11-02 11:06:21 +00:00
|
|
|
width int
|
2018-05-27 10:51:42 +00:00
|
|
|
output string
|
|
|
|
}{
|
|
|
|
{"", 80, ""},
|
|
|
|
{"", 0, ""},
|
|
|
|
{"", -1, ""},
|
|
|
|
{"foo", 80, "foo"},
|
|
|
|
{"foo", 4, "foo"},
|
|
|
|
{"foo", 3, "foo"},
|
|
|
|
{"foo", 2, "fo"},
|
|
|
|
{"foo", 1, "f"},
|
|
|
|
{"foo", 0, ""},
|
|
|
|
{"foo", -1, ""},
|
2020-11-02 11:06:21 +00:00
|
|
|
{"Löwen", 4, "Löwe"},
|
|
|
|
{"あああああああああ/data", 10, "あああああ"},
|
|
|
|
{"あああああああああ/data", 11, "あああああ"},
|
2018-05-27 10:51:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
t.Run("", func(t *testing.T) {
|
2020-11-02 11:06:21 +00:00
|
|
|
out := truncate(test.input, test.width)
|
2018-05-27 10:51:42 +00:00
|
|
|
if out != test.output {
|
2020-11-02 11:06:21 +00:00
|
|
|
t.Fatalf("wrong output for input %v, width %d: want %q, got %q",
|
|
|
|
test.input, test.width, test.output, out)
|
2018-05-27 10:51:42 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|