github.com/itscaro/cli@v0.0.0-20190705081621-c9db0fe93829/cli/command/formatter/displayutils_test.go (about)

     1  package formatter
     2  
     3  import (
     4  	"testing"
     5  
     6  	"gotest.tools/assert"
     7  	is "gotest.tools/assert/cmp"
     8  )
     9  
    10  func TestEllipsis(t *testing.T) {
    11  	var testcases = []struct {
    12  		source   string
    13  		width    int
    14  		expected string
    15  	}{
    16  		{source: "t🐳ststring", width: 0, expected: ""},
    17  		{source: "t🐳ststring", width: 1, expected: "t"},
    18  		{source: "t🐳ststring", width: 2, expected: "t…"},
    19  		{source: "t🐳ststring", width: 6, expected: "t🐳st…"},
    20  		{source: "t🐳ststring", width: 20, expected: "t🐳ststring"},
    21  		{source: "你好世界teststring", width: 0, expected: ""},
    22  		{source: "你好世界teststring", width: 1, expected: "你"},
    23  		{source: "你好世界teststring", width: 3, expected: "你…"},
    24  		{source: "你好世界teststring", width: 6, expected: "你好…"},
    25  		{source: "你好世界teststring", width: 20, expected: "你好世界teststring"},
    26  	}
    27  
    28  	for _, testcase := range testcases {
    29  		assert.Check(t, is.Equal(testcase.expected, Ellipsis(testcase.source, testcase.width)))
    30  	}
    31  }