-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
trim_test.go
54 lines (50 loc) · 994 Bytes
/
trim_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
package text
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestTrimSpace(t *testing.T) {
cases := []struct {
line string
output string
}{
{
"foo",
"foo",
},
{
"foo ",
"foo",
},
{
" foo",
"foo",
},
{
" \x1b[31mbar\x1b[0m ",
"\x1b[31mbar\x1b[0m",
},
{
"\x1b[31m bar \x1b[0m",
"\x1b[31mbar\x1b[0m",
},
{
" \x1b[31m bar \x1b[0m ",
"\x1b[31mbar\x1b[0m",
},
{
" 敏捷 A \x1b31mquick\n的狐狸 fox\n跳\x1b0m过 jumps\nover a lazy\n了一只懒狗\ndog。 ",
"敏捷 A \x1b31mquick\n的狐狸 fox\n跳\x1b0m过 jumps\nover a lazy\n了一只懒狗\ndog。",
},
}
for _, tc := range cases {
out := TrimSpace(tc.line)
assert.Equal(t, tc.output, out)
}
}
func BenchmarkTrimSpace(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
TrimSpace(" 敏捷 A \x1b31mquick\n的狐狸 fox\n跳\x1b0m过 jumps\nover a lazy\n了一只懒狗\ndog。 ")
}
}