-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstring_test.go
52 lines (45 loc) · 1.09 KB
/
string_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
// Copyright ©2022 Foolin. All rights reserved.
package gotab
import (
"testing"
"unicode/utf8"
)
var cases = []string{
"Hello",
"HelloWorld",
"Hello, World",
"Hello,World",
"Hello,世界",
"你好, 世界",
"您好,世界",
"Hello Go World",
"您好Go World",
"您好Go语言世界!",
"您好, Go世界",
"您好, Go语言世界!",
}
func TestStrWidth(t *testing.T) {
for _, s := range cases {
println(s, "W:", StrWidth(s))
println(s, "L:", len(s))
println(s, "R:", utf8.RuneCountInString(s))
}
}
func TestStrPadding(t *testing.T) {
n := 24
println(Padding("Hello", "-", 12+n) + "|")
println(Padding("Hello, World", "-", 12+n) + "|")
println(Padding("Hello界", "-", 12+n) + "|")
println(Padding("Hello世界", "-", 11+n) + "|")
println(Padding("Hello,世界", "-", 10+n) + "|")
println(Padding("您好,世界", "-", 9+n) + "|")
println(Padding("您好中世界", "-", 9+n) + "|")
}
func TestStrPadding2(t *testing.T) {
for i := 14; i < 30; i++ {
println("\n\n------ Width:", i, " ------")
for _, s := range cases {
println(Padding(s, "-", i) + "|")
}
}
}