forked from ukautz/clif
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common_test.go
138 lines (133 loc) · 2.59 KB
/
common_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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package clif
import (
"fmt"
. "github.com/smartystreets/goconvey/convey"
"strings"
"testing"
)
var testsStringLenth = []struct {
str string
len int
}{
{
str: "foo",
len: 3,
},
{
str: "♞♞♞",
len: 3,
},
{
str: "\033[1mfoo\033[0m",
len: 3,
},
{
str: "\033[34m\033[1mfoo\033[0m",
len: 3,
},
}
func TestStringLength(t *testing.T) {
Convey("Length of strings", t, func() {
for idx, test := range testsStringLenth {
name := rxControlCharacters.ReplaceAllString(test.str, "<CTRL>")
Convey(fmt.Sprintf("%d) %s", idx, name), func() {
l := StringLength(test.str)
So(l, ShouldEqual, test.len)
})
}
})
}
var testsSplitFormattedString = []struct {
str string
expect string
}{
{
str: "fffff",
expect: "fffff",
},
{
str: "\033[1mfffff\033[0m",
expect: "\033[1mfffff\033[0m",
},
{
str: "\033[1mfffff\033[0m\n",
expect: "\033[1mfffff\033[0m\n",
},
{
str: "\033[1mfff\nfff\033[0m",
expect: "\033[1mfff\033[0m\n\033[1mfff\033[0m",
},
{
str: strings.Join([]string{
"\033[34;1mfff",
"fff",
"fff\033[0m",
}, "\n"),
expect: strings.Join([]string{
"\033[34;1mfff\033[0m",
"\033[34;1mfff\033[0m",
"\033[34;1mfff\033[0m",
}, "\n"),
},
{
str: strings.Join([]string{
"\033[34;1mfff",
"fff",
"fff",
"fff",
"fff\033[0m",
}, "\n"),
expect: strings.Join([]string{
"\033[34;1mfff\033[0m",
"\033[34;1mfff\033[0m",
"\033[34;1mfff\033[0m",
"\033[34;1mfff\033[0m",
"\033[34;1mfff\033[0m",
}, "\n"),
},
{
str: strings.Join([]string{
"\033[34;1mfff\033[35m",
"fff",
"fff\033[0m",
}, "\n"),
expect: strings.Join([]string{
"\033[34;1mfff\033[35m\033[0m",
"\033[34;1m\033[35mfff\033[0m",
"\033[34;1m\033[35mfff\033[0m",
}, "\n"),
},
{
str: strings.Join([]string{
"\033[34;1mfff",
"\033[35mfff",
"fff\033[0m",
}, "\n"),
expect: strings.Join([]string{
"\033[34;1mfff\033[0m",
"\033[34;1m\033[35mfff\033[0m",
"\033[34;1m\033[35mfff\033[0m",
}, "\n"),
},
{
str: "\033[34;1mfff",
expect: "\033[34;1mfff\033[0m",
},
{
str: "fff\nfff",
expect: "fff\nfff",
},
}
func TestSplitFormattedString(t *testing.T) {
Convey("Split lines with control characters", t, func() {
for idx, test := range testsSplitFormattedString {
from := strings.Replace(test.str, "\n", "<BR>", -1)
from = rxControlCharacters.ReplaceAllString(from, "<CTRL>")
Convey(fmt.Sprintf("%d) from \"%s\"", idx, from), func() {
to := strings.Join(SplitFormattedString(test.str), "\n")
//_testDumpStrings(to, test.expect)
So(to, ShouldEqual, test.expect)
})
}
})
}