Debian Codegraph @

shlex_test.go

raw symbols SCIP
1 package shlexscip-go gomod github.com/anmitsu/go-shlex . `github.com/anmitsu/go-shlex`/
2
3 import (
4 "fmtscip-go gomod github.com/golang/go/src go1.13 fmt/"
5 "testingscip-go gomod github.com/golang/go/src go1.13 testing/"
6 )
7
8 var datanonposixscip-go gomod github.com/anmitsu/go-shlex . `github.com/anmitsu/go-shlex`/datanonposix. = []struct {
9 inscip-go gomod github.com/anmitsu/go-shlex . `github.com/anmitsu/go-shlex`/datanonposix:in. string
10 outscip-go gomod github.com/anmitsu/go-shlex . `github.com/anmitsu/go-shlex`/datanonposix:out. []string
11 errscip-go gomod github.com/anmitsu/go-shlex . `github.com/anmitsu/go-shlex`/datanonposix:err. error
12 }{
13 {`This string has an embedded apostrophe, doesn't it?`,
14 []string{
15 "This",
16 "string",
17 "has",
18 "an",
19 "embedded",
20 "apostrophe",
21 ",",
22 "doesn't",
23 "it",
24 "?",
25 },
26 nil,
27 },
28 {"This string has embedded \"double quotes\" and 'single quotes' in it,\nand even \"a 'nested example'\".\n",
29 []string{
30 "This",
31 "string",
32 "has",
33 "embedded",
34 `"double quotes"`,
35 "and",
36 `'single quotes'`,
37 "in",
38 "it",
39 ",",
40 "and",
41 "even",
42 `"a 'nested example'"`,
43 ".",
44 },
45 nil,
46 },
47 {`Hello world!, こんにちは 世界!`,
48 []string{
49 "Hello",
50 "world",
51 "!",
52 ",",
53 "こんにちは",
54 "世界",
55 "!",
56 },
57 nil,
58 },
59 {`Do"Not"Separate`,
60 []string{`Do"Not"Separate`},
61 nil,
62 },
63 {`"Do"Separate`,
64 []string{`"Do"`, "Separate"},
65 nil,
66 },
67 {`Escaped \e Character not in quotes`,
68 []string{
69 "Escaped",
70 `\`,
71 "e",
72 "Character",
73 "not",
74 "in",
75 "quotes",
76 },
77 nil,
78 },
79 {`Escaped "\e" Character in double quotes`,
80 []string{
81 "Escaped",
82 `"\e"`,
83 "Character",
84 "in",
85 "double",
86 "quotes",
87 },
88 nil,
89 },
90 {`Escaped '\e' Character in single quotes`,
91 []string{
92 "Escaped",
93 `'\e'`,
94 "Character",
95 "in",
96 "single",
97 "quotes",
98 },
99 nil,
100 },
101 {`Escaped '\'' \"\'\" single quote`,
102 []string{
103 "Escaped",
104 `'\'`,
105 `' \"\'`,
106 `\`,
107 `" single quote`,
108 },
109 ErrNoClosingscip-go gomod github.com/anmitsu/go-shlex . `github.com/anmitsu/go-shlex`/ErrNoClosing.,
110 },
111 {`Escaped "\"" \'\"\' double quote`,
112 []string{
113 "Escaped",
114 `"\"`,
115 `" \'\"`,
116 `\`,
117 `' double quote`,
118 },
119 ErrNoClosingscip-go gomod github.com/anmitsu/go-shlex . `github.com/anmitsu/go-shlex`/ErrNoClosing.,
120 },
121 {`"'Strip extra layer of quotes'"`,
122 []string{`"'Strip extra layer of quotes'"`},
123 nil,
124 },
125 }
126
127 var dataposixscip-go gomod github.com/anmitsu/go-shlex . `github.com/anmitsu/go-shlex`/dataposix. = []struct {
128 inscip-go gomod github.com/anmitsu/go-shlex . `github.com/anmitsu/go-shlex`/dataposix:in. string
129 outscip-go gomod github.com/anmitsu/go-shlex . `github.com/anmitsu/go-shlex`/dataposix:out. []string
130 errscip-go gomod github.com/anmitsu/go-shlex . `github.com/anmitsu/go-shlex`/dataposix:err. error
131 }{
132 {`This string has an embedded apostrophe, doesn't it?`,
133 []string{
134 "This",
135 "string",
136 "has",
137 "an",
138 "embedded",
139 "apostrophe",
140 ",",
141 "doesnt it?",
142 },
143 ErrNoClosingscip-go gomod github.com/anmitsu/go-shlex . `github.com/anmitsu/go-shlex`/ErrNoClosing.,
144 },
145 {"This string has embedded \"double quotes\" and 'single quotes' in it,\nand even \"a 'nested example'\".\n",
146 []string{
147 "This",
148 "string",
149 "has",
150 "embedded",
151 `double quotes`,
152 "and",
153 `single quotes`,
154 "in",
155 "it",
156 ",",
157 "and",
158 "even",
159 `a 'nested example'`,
160 ".",
161 },
162 nil,
163 },
164 {`Hello world!, こんにちは 世界!`,
165 []string{
166 "Hello",
167 "world",
168 "!",
169 ",",
170 "こんにちは",
171 "世界",
172 "!",
173 },
174 nil,
175 },
176 {`Do"Not"Separate`,
177 []string{`DoNotSeparate`},
178 nil,
179 },
180 {`"Do"Separate`,
181 []string{"DoSeparate"},
182 nil,
183 },
184 {`Escaped \e Character not in quotes`,
185 []string{
186 "Escaped",
187 "e",
188 "Character",
189 "not",
190 "in",
191 "quotes",
192 },
193 nil,
194 },
195 {`Escaped "\e" Character in double quotes`,
196 []string{
197 "Escaped",
198 `\e`,
199 "Character",
200 "in",
201 "double",
202 "quotes",
203 },
204 nil,
205 },
206 {`Escaped '\e' Character in single quotes`,
207 []string{
208 "Escaped",
209 `\e`,
210 "Character",
211 "in",
212 "single",
213 "quotes",
214 },
215 nil,
216 },
217 {`Escaped '\'' \"\'\" single quote`,
218 []string{
219 "Escaped",
220 `\ \"\"`,
221 "single",
222 "quote",
223 },
224 nil,
225 },
226 {`Escaped "\"" \'\"\' double quote`,
227 []string{
228 "Escaped",
229 `"`,
230 `'"'`,
231 "double",
232 "quote",
233 },
234 nil,
235 },
236 {`"'Strip extra layer of quotes'"`,
237 []string{`'Strip extra layer of quotes'`},
238 nil,
239 },
240 }
241
242 func TestSplitNonPOSIXscip-go gomod github.com/anmitsu/go-shlex . `github.com/anmitsu/go-shlex`/TestSplitNonPOSIX().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
243 testSplitscip-go gomod github.com/anmitsu/go-shlex . `github.com/anmitsu/go-shlex`/testSplit().(t, false)
244 }
245
246 func TestSplitPOSIXscip-go gomod github.com/anmitsu/go-shlex . `github.com/anmitsu/go-shlex`/TestSplitPOSIX().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
247 testSplitscip-go gomod github.com/anmitsu/go-shlex . `github.com/anmitsu/go-shlex`/testSplit().(t, true)
248 }
249
250 func testSplitscip-go gomod github.com/anmitsu/go-shlex . `github.com/anmitsu/go-shlex`/testSplit().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#, posix bool) {
251 var data []struct {
252 in string
253 out []string
254 err error
255 }
256 if posix {
257 data = dataposixscip-go gomod github.com/anmitsu/go-shlex . `github.com/anmitsu/go-shlex`/dataposix.
258 } else {
259 data = datanonposixscip-go gomod github.com/anmitsu/go-shlex . `github.com/anmitsu/go-shlex`/datanonposix.
260 }
261
262 for _, d := range data {
263 t.Logfscip-go gomod github.com/golang/go/src go1.13 testing/common#Logf().("Spliting: `%s'", d.in)
264
265 result, err := NewLexerStringscip-go gomod github.com/anmitsu/go-shlex . `github.com/anmitsu/go-shlex`/NewLexerString().(d.in, posix, false).Splitscip-go gomod github.com/anmitsu/go-shlex . `github.com/anmitsu/go-shlex`/Lexer#Split().()
266
267 // check closing and escaped error
268 if err != d.err {
269 printTokenscip-go gomod github.com/anmitsu/go-shlex . `github.com/anmitsu/go-shlex`/printToken().(result)
270 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Error expected: `%v', but result catched: `%v'",
271 d.err, err)
272 }
273
274 // check splited number
275 if len(result) != len(d.out) {
276 printTokenscip-go gomod github.com/anmitsu/go-shlex . `github.com/anmitsu/go-shlex`/printToken().(result)
277 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Split expeced: `%d', but result founds: `%d'",
278 len(d.out), len(result))
279 }
280
281 // check words
282 for j, out := range d.out {
283 if result[j] != out {
284 printTokenscip-go gomod github.com/anmitsu/go-shlex . `github.com/anmitsu/go-shlex`/printToken().(result)
285 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Word expeced: `%s', but result founds: `%s' in %d",
286 out, result[j], j)
287 }
288 }
289 t.Logscip-go gomod github.com/golang/go/src go1.13 testing/common#Log().("ok")
290 }
291 }
292
293 func printTokenscip-go gomod github.com/anmitsu/go-shlex . `github.com/anmitsu/go-shlex`/printToken().(s []string) {
294 for _, token := range s {
295 fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Printlnscip-go gomod github.com/golang/go/src go1.13 fmt/Println().(token)
296 }
297 }