7
var runewidthtests = []struct {
16
{'☆', 2}, // double width in ambiguous
22
func TestRuneWidth(t *testing.T) {
24
c.EastAsianWidth = true
25
for _, tt := range runewidthtests {
26
if out := c.RuneWidth(tt.in); out != tt.out {
27
t.Errorf("Width(%q) = %q, want %q", tt.in, out, tt.out)
32
var isambiguouswidthtests = []struct {
64
func TestIsAmbiguousWidth(t *testing.T) {
65
for _, tt := range isambiguouswidthtests {
66
if out := IsAmbiguousWidth(tt.in); out != tt.out {
67
t.Errorf("IsAmbiguousWidth(%q) = %q, want %q", tt.in, out, tt.out)
72
var stringwidthtests = []struct {
80
func TestStringWidth(t *testing.T) {
82
c.EastAsianWidth = true
83
for _, tt := range stringwidthtests {
84
if out := c.StringWidth(tt.in); out != tt.out {
85
t.Errorf("StringWidth(%q) = %q, want %q", tt.in, out, tt.out)
90
func TestStringWidthInvalid(t *testing.T) {
92
if out := StringWidth(s); out != 14 {
93
t.Errorf("StringWidth(%q) = %q, want %q", s, out, 14)
97
func TestTruncate(t *testing.T) {
98
s := "あいうえおあいうえおえおおおおおおおおおおおおおおおおおおおおおおおおおおおおおお"
99
expected := "あいうえおあいうえおえおおおおおおおおおおおおおおおおおおおおおおおおおおお..."
101
if out := Truncate(s, 80, "..."); out != expected {
102
t.Errorf("Truncate(%q) = %q, want %q", s, out, expected)
106
func TestWrap(t *testing.T) {
107
s := `東京特許許可局局長はよく柿喰う客だ/東京特許許可局局長はよく柿喰う客だ
108
123456789012345678901234567890
111
expected := `東京特許許可局局長はよく柿喰う
114
123456789012345678901234567890
118
if out := Wrap(s, 30); out != expected {
119
t.Errorf("Wrap(%q) = %q, want %q", s, out, expected)
123
func TestTruncateNoNeeded(t *testing.T) {
125
expected := "あいうえおあい"
127
if out := Truncate(s, 80, "..."); out != expected {
128
t.Errorf("Truncate(%q) = %q, want %q", s, out, expected)
132
var isneutralwidthtests = []struct {
145
func TestIsNeutralWidth(t *testing.T) {
146
for _, tt := range isneutralwidthtests {
147
if out := IsNeutralWidth(tt.in); out != tt.out {
148
t.Errorf("IsNeutralWidth(%q) = %q, want %q", tt.in, out, tt.out)
153
func TestFillLeft(t *testing.T) {
155
expected := " あxいうえお"
157
if out := FillLeft(s, 15); out != expected {
158
t.Errorf("FillLeft(%q) = %q, want %q", s, out, expected)
162
func TestFillRight(t *testing.T) {
164
expected := "あxいうえお "
166
if out := FillRight(s, 15); out != expected {
167
t.Errorf("FillRight(%q) = %q, want %q", s, out, expected)