2017-10-13 05:01:32 -04:00
|
|
|
package formatter
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-02-22 12:12:14 -05:00
|
|
|
"gotest.tools/v3/assert"
|
|
|
|
is "gotest.tools/v3/assert/cmp"
|
2017-10-13 05:01:32 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestEllipsis(t *testing.T) {
|
2022-09-29 11:21:51 -04:00
|
|
|
testcases := []struct {
|
2017-10-13 05:01:32 -04:00
|
|
|
source string
|
|
|
|
width int
|
|
|
|
expected string
|
|
|
|
}{
|
|
|
|
{source: "t🐳ststring", width: 0, expected: ""},
|
|
|
|
{source: "t🐳ststring", width: 1, expected: "t"},
|
|
|
|
{source: "t🐳ststring", width: 2, expected: "t…"},
|
|
|
|
{source: "t🐳ststring", width: 6, expected: "t🐳st…"},
|
|
|
|
{source: "t🐳ststring", width: 20, expected: "t🐳ststring"},
|
|
|
|
{source: "你好世界teststring", width: 0, expected: ""},
|
|
|
|
{source: "你好世界teststring", width: 1, expected: "你"},
|
|
|
|
{source: "你好世界teststring", width: 3, expected: "你…"},
|
|
|
|
{source: "你好世界teststring", width: 6, expected: "你好…"},
|
|
|
|
{source: "你好世界teststring", width: 20, expected: "你好世界teststring"},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, testcase := range testcases {
|
2018-03-05 18:53:52 -05:00
|
|
|
assert.Check(t, is.Equal(testcase.expected, Ellipsis(testcase.source, testcase.width)))
|
2017-10-13 05:01:32 -04:00
|
|
|
}
|
|
|
|
}
|