forked from marcusolsson/tui-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
text_test.go
68 lines (64 loc) · 1.3 KB
/
text_test.go
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package tui
import "testing"
func TestRuneWidth(t *testing.T) {
for n, tt := range []struct {
r rune
result int
}{
{' ', 1},
{'a', 1},
{'あ', 2},
} {
if got, want := runeWidth(tt.r), tt.result; got != want {
t.Errorf("[%d] runeWidth(%q) = %d, want %d", n, tt.r, got, want)
}
}
}
func TestStringWidth(t *testing.T) {
for n, tt := range []struct {
s string
result int
}{
{"", 0},
{" ", 1},
{"a", 1},
{"a ", 2},
{"abc", 3},
{"あ", 2},
{"あいう", 6},
{"abcあいう123", 12},
} {
if got, want := stringWidth(tt.s), tt.result; got != want {
t.Errorf("[%d] stringWidth(%q) = %d, want %d", n, tt.s, got, want)
}
}
}
func TestTrimRightLen(t *testing.T) {
for n, tt := range []struct {
s string
n int
result string
}{
{"", 0, ""},
{"", 1, ""},
{"", -1, ""},
{" ", 1, ""},
{"abc", -1, "abc"},
{"abc", 0, "abc"},
{"abc", 1, "ab"},
{"abc ", 1, "abc"},
{"abc", 2, "a"},
{"abc", 3, ""},
{"abc", 4, ""},
{"あいう", -1, "あいう"},
{"あいう", 0, "あいう"},
{"あいう", 1, "あい"},
{"あいう", 2, "あ"},
{"あいう", 3, ""},
{"あいう", 4, ""},
} {
if got, want := trimRightLen(tt.s, tt.n), tt.result; got != want {
t.Errorf("[%d] trimRightLen(%q, %d) = %q, want %q", n, tt.s, tt.n, got, want)
}
}
}