-
Notifications
You must be signed in to change notification settings - Fork 1
/
count_test.go
executable file
·59 lines (50 loc) · 1.08 KB
/
count_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
package xstr
import (
"fmt"
"testing"
)
func TestLen(t *testing.T) {
runner := func(str string) string {
return fmt.Sprint(Len(str))
}
runTestCases(t, runner, _M{
"abcdef": "6",
"中文": "2",
"中yin文hun排": "9",
"": "0",
})
}
func TestWordCount(t *testing.T) {
runner := func(str string) string {
return fmt.Sprint(WordCount(str))
}
runTestCases(t, runner, _M{
"one word: λ": "3",
"中文": "0",
"你好,sekai!": "1",
"oh, it's super-fancy!!a": "4",
"": "0",
"-": "0",
"it's-'s": "1",
})
}
func TestWidth(t *testing.T) {
runner := func(str string) string {
return fmt.Sprint(Width(str))
}
runTestCases(t, runner, _M{
"abcd\t0123\n7890": "12",
"中zh英eng文混排": "15",
"": "0",
})
}
func TestRuneWidth(t *testing.T) {
runner := func(str string) string {
return fmt.Sprint(RuneWidth([]rune(str)[0]))
}
runTestCases(t, runner, _M{
"a": "1",
"中": "2",
"\x11": "0",
})
}