summaryrefslogtreecommitdiffstats
path: root/utils/runes_test.go
blob: 67ceefc1e00ffc5ec92cbdfdfa49053d923377fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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"},

		{"⦅full~width⦆", 15, ".", "⦅full~width⦆"},
		{"⦅full~width⦆", 14, ".", ".full~width⦆"},
		{"⦅full~width⦆", 13, ".", ".ull~width⦆"},
		{"⦅full~width⦆", 10, ".", ".~width⦆"},
		{"⦅full~width⦆", 9, ".", ".width⦆"},
		{"⦅full~width⦆", 8, ".", ".width⦆"},
		{"⦅full~width⦆", 3, ".", ".⦆"},
		{"⦅full~width⦆", 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)
		}
	}
}