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
|
package ui
import "testing"
func assertStringWidth(t *testing.T, input string, expected int) {
actual := StringWidth(input)
if actual != expected {
t.Errorf("%q: expected width of %d got %d", input, expected, actual)
}
}
func TestStringWidth(t *testing.T) {
assertStringWidth(t, "", 0)
assertStringWidth(t, "hello", 5)
assertStringWidth(t, "\x02hello", 5)
assertStringWidth(t, "\x035hello", 5)
assertStringWidth(t, "\x0305hello", 5)
assertStringWidth(t, "\x0305,0hello", 5)
assertStringWidth(t, "\x0305,09hello", 5)
assertStringWidth(t, "\x0305,hello", 6)
assertStringWidth(t, "\x03050hello", 6)
assertStringWidth(t, "\x0305,090hello", 6)
}
|