xmtop/utils/runes_test.go
2020-02-14 09:35:58 -06:00

51 lines
1.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package utils
import "testing"
const (
ELLIPSIS = "…"
)
func TestTruncateFront(t *testing.T) {
tests := []struct {
s string
w int
prefix string
want string
}{
{"", 0, ELLIPSIS, ""},
{"", 1, ELLIPSIS, ""},
{"", 10, ELLIPSIS, ""},
{"abcdef", 0, ELLIPSIS, ELLIPSIS},
{"abcdef", 1, ELLIPSIS, ELLIPSIS},
{"abcdef", 2, ELLIPSIS, ELLIPSIS + "f"},
{"abcdef", 5, ELLIPSIS, ELLIPSIS + "cdef"},
{"abcdef", 6, ELLIPSIS, "abcdef"},
{"abcdef", 10, ELLIPSIS, "abcdef"},
{"abcdef", 0, "...", "..."},
{"abcdef", 1, "...", "..."},
{"abcdef", 3, "...", "..."},
{"abcdef", 4, "...", "...f"},
{"abcdef", 5, "...", "...ef"},
{"abcdef", 6, "...", "abcdef"},
{"abcdef", 10, "...", "abcdef"},
{"⦅fullwidth⦆", 15, ".", "⦅fullwidth⦆"},
{"⦅fullwidth⦆", 14, ".", ".fullwidth⦆"},
{"⦅fullwidth⦆", 13, ".", ".ullwidth⦆"},
{"⦅fullwidth⦆", 10, ".", ".width⦆"},
{"⦅fullwidth⦆", 9, ".", ".width⦆"},
{"⦅fullwidth⦆", 8, ".", ".width⦆"},
{"⦅fullwidth⦆", 3, ".", ".⦆"},
{"⦅fullwidth⦆", 2, ".", "."},
}
for _, test := range tests {
if got := TruncateFront(test.s, test.w, test.prefix); got != test.want {
t.Errorf("TruncateFront(%q, %d, %q) = %q; want %q", test.s, test.w, test.prefix, got, test.want)
}
}
}