-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtranslate_test.go
executable file
·93 lines (77 loc) · 2.73 KB
/
translate_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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package xstr
import (
"fmt"
"strings"
"testing"
)
func TestTranslate(t *testing.T) {
runner := func(str string) string {
input := strings.Split(str, separator)
return Translate(input[0], input[1], input[2])
}
runTestCases(t, runner, _M{
sep("hello", "aeiou", "12345"): "h2ll4",
sep("hello", "aeiou", ""): "hll",
sep("hello", "a-z", "A-Z"): "HELLO",
sep("hello", "z-a", "a-z"): "svool",
sep("hello", "aeiou", "*"): "h*ll*",
sep("hello", "^l", "*"): "**ll*",
sep("hello", "p-z", "*"): "hello",
sep("hello ^ world", `\^lo`, "*"): "he*** * w*r*d",
sep("中文字符测试", "文中谁敢试?", "123456"): "21字符测5",
sep("中文字符测试", "^文中谁敢试?", "123456"): "中文666试",
sep("中文字符测试", "字-试", "0-9"): "中90999",
sep("h1e2l3l4o, w5o6r7l8d", "a-z,0-9", `A-Z\-a-czk-p`): "HbEcLzLkO- WlOmRnLoD",
sep("h1e2l3l4o, w5o6r7l8d", "a-zoh-n", "b-zakt-z"): "t1f2x3x4k, x5k6s7x8e",
sep("h1e2l3l4o, w5o6r7l8d", "helloa-zoh-n", "99999b-zakt-z"): "t1f2x3x4k, x5k6s7x8e",
sep("hello", "e-", "p"): "hpllo",
sep("hello", "-e-", "p"): "hpllo",
sep("hello", "----e---", "p"): "hpllo",
sep("hello", "^---e----", "p"): "peppp",
sep("hel\uFFFDlo", "\uFFFD", "H"): "helHlo",
sep("hel\uFFFDlo", "^\uFFFD", "H"): "HHHHH",
sep("hel\uFFFDlo", "o-\uFFFDh", "H"): "HelHlH",
})
}
func TestDelete(t *testing.T) {
runner := func(str string) string {
input := strings.Split(str, separator)
return Delete(input[0], input[1])
}
runTestCases(t, runner, _M{
sep("hello", "aeiou"): "hll",
sep("hello", "a-k"): "llo",
sep("hello", "^a-k"): "he",
sep("中文字符测试", "文中谁敢试?"): "字符测",
})
}
func TestCountRune(t *testing.T) {
runner := func(str string) string {
input := strings.Split(str, separator)
return fmt.Sprint(CountRune(input[0], input[1]))
}
runTestCases(t, runner, _M{
sep("hello", "aeiou"): "2",
sep("hello", "a-k"): "2",
sep("hello", "^a-k"): "3",
sep("中文字符测试", "文中谁敢试?"): "3",
})
}
func TestSqueeze(t *testing.T) {
runner := func(str string) string {
input := strings.Split(str, separator)
return Squeeze(input[0], input[1])
}
runTestCases(t, runner, _M{
sep("hello", ""): "helo",
sep("hello world", ""): "helo world",
sep("hello world", " "): "hello world",
sep("hello world", " "): "hello world",
sep("hello", "a-k"): "hello",
sep("hello", "^a-k"): "helo",
sep("hello", "^a-l"): "hello",
sep("foooo baaaaar", "a"): "foooo bar",
sep("打打打打个劫!!", ""): "打个劫!",
sep("打打打打个劫!!", "打"): "打个劫!!",
})
}