-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrings_test.go
More file actions
208 lines (188 loc) · 3.92 KB
/
Copy pathstrings_test.go
File metadata and controls
208 lines (188 loc) · 3.92 KB
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
package main
import (
"fmt"
"testing"
)
var toggleTests = []struct {
s rune
m rune // matching
st state
start bool
d bool // disableOnNoMatch
e bool
}{
{'\\', '\\', state{}, true, true, true},
{'\\', '\\', state{}, false, false, true},
{'\\', 'x', state{}, true, true, false},
}
var stripSlashesTests = []struct {
s string
e string
}{
{"Test \\@1\\, both", "Test @1, both"},
{"Test\\@ at", "Test@ at"},
{"Test \\,comma", "Test ,comma"},
}
var lupGroupTests = []struct {
s int
e string
}{
{1, fmt.Sprintf("##LUP_GROUP_%d##", 1)},
{99, fmt.Sprintf("##LUP_GROUP_%d##", 99)},
}
var addSlashesTests = []struct {
s string
e string
}{
{"Test @1, both", "Test \\@1\\, both"},
{"Test@ at", "Test\\@ at"},
{"Test ,comma", "Test \\,comma"},
}
var stripCommasTests = []struct {
s string
e string
}{
{",beginning,and,end,", "beginning,and,end"},
{",just,the,start", "just,the,start"},
{"one,right,", "one,right"},
{"multi,right,,,", "multi,right"},
{",,,multi,left", "multi,left"},
}
var hasGlobsTests = []struct {
s string
e bool
}{
{"/tmp/*/", true},
{"/tmp/*", true},
{"/tmp/a?c/", true},
{"/tmp/1!2/", true},
{"/tmp/3{4/", true},
{"/tmp/5}6/", true},
{"/tmp/506/", false},
}
var isEscapedTests = []struct {
s string // text
n int // position
e bool
}{
{"He\\llo", 3, true},
{"He\\llo", 4, false},
{"He\\llo", 2, false},
{"\\Hello", 1, true},
{"Hell\\o", 5, true},
{"Hell\\\\o", 6, true},
}
var runeInTests = []struct {
r rune // text
e bool
}{
{'a', false},
{'x', false},
{'?', true},
{'{', true},
{'}', true},
{'!', true},
{'*', true},
}
var unescapeGlobCharsTests = []struct {
s string // text
e string
}{
{"/tmp/\\*/", "/tmp/*/"},
{"/tmp/*", "/tmp/*"},
{"/tmp/a\\?c/", "/tmp/a?c/"},
{"/tmp/1\\!2/", "/tmp/1!2/"},
{"/tmp/3\\{4/", "/tmp/3{4/"},
{"/tmp/5\\}6/", "/tmp/5}6/"},
{"/t\\*\\\\m\\?\\{\\!\\?p/5\\}6/", "/t*\\\\m?{!?p/5}6/"},
}
var splitByTests = []struct {
s string // text
r rune // split on
e []string
}{
{"hello,world", ',', []string{"hello", "world"}},
{"this\\,is,a,test", ',', []string{"this,is", "a", "test"}},
}
var isHiddenTests = []struct {
s string
e bool
o string
}{
{"-:Hello", true, "Hello"},
{"-Goodbye", false, "-Goodbye"},
{"cat", false, "cat"},
{":-dog", false, ":-dog"},
}
func TestHasGlobs(t *testing.T) {
for _, x := range hasGlobsTests {
result := hasGlobs(x.s)
if result != x.e {
t.Errorf("hasGlobs failed on '%s'", x.s)
}
}
}
func TestIsEscaped(t *testing.T) {
for _, x := range isEscapedTests {
result := isEscaped(x.s, x.n)
if result != x.e {
t.Errorf("isEscaped failed on '%s:%d'", x.s, x.n)
}
}
}
func TestRuneIn(t *testing.T) {
for _, x := range runeInTests {
result := runeIn(globChars, x.r)
if result != x.e {
t.Errorf("runeIn failed on '%c'", x.r)
}
}
}
func TestUnescapeGlobChars(t *testing.T) {
for _, x := range unescapeGlobCharsTests {
result := unescapeGlobChars(x.s)
if result != x.e {
t.Errorf("unescapeGlobChars failed - got: %s, expect: %s", x.s, x.e)
}
}
}
func TestStripSlashes(t *testing.T) {
for _, x := range stripSlashesTests {
result := stripSlashes(x.s)
if result != x.e {
t.Errorf("stripSlashes failed. Got: %s, Want: %s", result, x.e)
}
}
}
func TestAddSlashes(t *testing.T) {
for _, x := range addSlashesTests {
result := addSlashes(x.s)
if result != x.e {
t.Errorf("addSlashes failed. Got: %s, Want: %s", result, x.e)
}
}
}
func TestLupGroup(t *testing.T) {
for _, x := range lupGroupTests {
result := lupGroup(x.s)
if result != x.e {
t.Errorf("lupGroup failed. Got: %s, Want: %s", result, x.e)
}
}
}
func TestToggle(t *testing.T) {
for _, x := range toggleTests {
x.st.toggle(x.s, x.m, x.d)
if x.st.on != x.e {
t.Errorf("lupGroup failed. Got: %t, Want: %t", x.st.on, x.e)
}
}
}
func TestIsHidden(t *testing.T) {
for _, x := range isHiddenTests {
b, o := isHidden(x.s)
if b != x.e || o != x.o {
t.Errorf("isHidden failed on '%s'", x.s)
}
}
}