Badges / coveralls (push) Successful in 1m1s
Reviewed-on: #33 Co-authored-by: Natercio Moniz <[email protected]>
25 lines
941 B
Go
25 lines
941 B
Go
package tabledef
|
|
|
|
import "testing"
|
|
|
|
func TestTruncateHeader(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
val string
|
|
width int
|
|
want string
|
|
}{
|
|
{name: "fits unchanged", val: "TAX PAID ABROAD", width: 15, want: "TAX PAID ABROAD"},
|
|
{name: "cut mid-word keeps the most runes", val: "EXPENSES AND CHARGES", width: 15, want: "EXPENSES AND C…"},
|
|
{name: "single overlong word is hard cut", val: "ESTRANGEIRO", width: 8, want: "ESTRANG…"},
|
|
{name: "cut ignores word boundaries", val: "IMPOSTO PAGO NO ESTRANGEIRO", width: 15, want: "IMPOSTO PAGO N…"},
|
|
{name: "multibyte runes count as one", val: "PAÍS DA CONTRAPARTE", width: 12, want: "PAÍS DA CON…"},
|
|
{name: "narrow width", val: "ABCD", width: 2, want: "A…"},
|
|
}
|
|
for _, tt := range tests {
|
|
if got := truncateHeader(tt.val, tt.width); got != tt.want {
|
|
t.Errorf("%s: truncateHeader(%q, %d) = %q, want %q", tt.name, tt.val, tt.width, got, tt.want)
|
|
}
|
|
}
|
|
}
|