Bump to 1.14.1
[platform/upstream/augeas.git] / lenses / tests / test_quote.aug
1 (*
2 Module: Test_Quote
3   Provides unit tests and examples for the <Quote> lens.
4 *)
5
6 module Test_Quote =
7
8 (* View: double *)
9 let double = [ label "double" . Quote.double ]
10
11 (* Test: double *)
12 test double get "\" this is a test\"" =
13   { "double" = " this is a test" }
14
15 (* View: double_opt *)
16 let double_opt = [ label "double_opt" . Quote.double_opt ]
17
18 (* Test: double_opt *)
19 test double_opt get "\"this is a test\"" =
20   { "double_opt" = "this is a test" }
21
22 (* Test: double_opt *)
23 test double_opt get "this is a test" =
24   { "double_opt" = "this is a test" }
25
26 (* Test: double_opt
27    Value cannot start with a space *)
28 test double_opt get " this is a test" = *
29
30 (* View: single *)
31 let single = [ label "single" . Quote.single ]
32
33 (* Test: single *)
34 test single get "' this is a test'" =
35   { "single" = " this is a test" }
36
37 (* View: single_opt *)
38 let single_opt = [ label "single_opt" . Quote.single_opt ]
39
40 (* Test: single_opt *)
41 test single_opt get "'this is a test'" =
42   { "single_opt" = "this is a test" }
43
44 (* Test: single_opt *)
45 test single_opt get "this is a test" =
46   { "single_opt" = "this is a test" }
47
48 (* Test: single_opt
49    Value cannot start with a space *)
50 test single_opt get " this is a test" = *
51
52 (* View: any *)
53 let any = [ label "any" . Quote.any ]
54
55 (* Test: any *)
56 test any get "\" this is a test\"" =
57   { "any" = " this is a test" }
58
59 (* Test: any *)
60 test any get "' this is a test'" =
61   { "any" = " this is a test" }
62
63 (* View: any_opt *)
64 let any_opt = [ label "any_opt" . Quote.any_opt ]
65
66 (* Test: any_opt *)
67 test any_opt get "\"this is a test\"" =
68   { "any_opt" = "this is a test" }
69
70 (* Test: any_opt *)
71 test any_opt get "'this is a test'" =
72   { "any_opt" = "this is a test" }
73
74 (* Test: any_opt *)
75 test any_opt get "this is a test" =
76   { "any_opt" = "this is a test" }
77
78 (* Test: any_opt
79    Value cannot start with a space *)
80 test any_opt get " this is a test" = *
81
82 (* View: double_opt_allow_spc *)
83 let double_opt_allow_spc =
84   let body = store /[^\n"]+/ in
85   [ label "double" . Quote.do_dquote_opt body ]
86
87 (* Test: double_opt_allow_spc *)
88 test double_opt_allow_spc get " test with spaces " =
89   { "double" = " test with spaces " }
90
91 (* Group: quote_spaces *)
92
93 (* View: quote_spaces *)
94 let quote_spaces =
95   Quote.quote_spaces (label "spc")
96
97 (* Test: quote_spaces
98      Unquoted value *)
99 test quote_spaces get "this" =
100   { "spc" = "this" }
101
102 (* Test: quote_spaces
103      double quoted value *)
104 test quote_spaces get "\"this\"" =
105   { "spc" = "this" }
106
107 (* Test: quote_spaces
108      single quoted value *)
109 test quote_spaces get "'this'" =
110   { "spc" = "this" }
111
112 (* Test: quote_spaces
113      unquoted value with spaces *)
114 test quote_spaces get "this that those" = *
115
116 (* Test: quote_spaces
117      double quoted value with spaces *)
118 test quote_spaces get "\"this that those\"" =
119   { "spc" = "this that those" }
120
121 (* Test: quote_spaces
122      single quoted value with spaces *)
123 test quote_spaces get "'this that those'" =
124   { "spc" = "this that those" }
125
126 (* Test: quote_spaces
127      remove spaces from double-quoted value *)
128 test quote_spaces put "\"this that those\""
129   after set "spc" "thisthat" =
130   "\"thisthat\""
131
132 (* Test: quote_spaces
133      remove spaces from single-quoted value *)
134 test quote_spaces put "'this that those'"
135   after set "spc" "thisthat" =
136   "'thisthat'"
137
138 (* Test: quote_spaces
139      add spaces to unquoted value *)
140 test quote_spaces put "this"
141   after set "spc" "this that those" =
142   "\"this that those\""
143
144 (* Test: quote_spaces
145      add spaces to double-quoted value *)
146 test quote_spaces put "\"this\""
147   after set "spc" "this that those" =
148   "\"this that those\""
149
150 (* Test: quote_spaces
151      add spaces to single-quoted value *)
152 test quote_spaces put "'this'"
153   after set "spc" "this that those" =
154   "'this that those'"
155
156 (* Group: dquote_spaces *)
157
158 (* View: dquote_spaces *)
159 let dquote_spaces =
160   Quote.dquote_spaces (label "spc")
161
162 (* Test: dquote_spaces
163      Unquoted value *)
164 test dquote_spaces get "this" =
165   { "spc" = "this" }
166
167 (* Test: dquote_spaces
168      double quoted value *)
169 test dquote_spaces get "\"this\"" =
170   { "spc" = "this" }
171
172 (* Test: dquote_spaces
173      single quoted value *)
174 test dquote_spaces get "'this'" =
175   { "spc" = "'this'" }
176
177 (* Test: dquote_spaces
178      unquoted value with spaces *)
179 test dquote_spaces get "this that those" = *
180
181 (* Test: dquote_spaces
182      double quoted value with spaces *)
183 test dquote_spaces get "\"this that those\"" =
184   { "spc" = "this that those" }
185
186 (* Test: dquote_spaces
187      single quoted value with spaces *)
188 test dquote_spaces get "'this that those'" = *
189
190 (* Test: dquote_spaces
191      remove spaces from double-quoted value *)
192 test dquote_spaces put "\"this that those\""
193   after set "spc" "thisthat" =
194   "\"thisthat\""
195
196 (* Test: dquote_spaces
197      add spaces to unquoted value *)
198 test dquote_spaces put "this"
199   after set "spc" "this that those" =
200   "\"this that those\""
201
202 (* Test: dquote_spaces
203      add spaces to double-quoted value *)
204 test dquote_spaces put "\"this\""
205   after set "spc" "this that those" =
206   "\"this that those\""
207
208 (* Test: dquote_spaces
209      add spaces to single-quoted value *)
210 test dquote_spaces put "'this'"
211   after set "spc" "this that those" =
212   "\"this that those\""
213
214 (* Group: squote_spaces *)
215
216 (* View: squote_spaces *)
217 let squote_spaces =
218   Quote.squote_spaces (label "spc")
219
220 (* Test: squote_spaces
221      Unquoted value *)
222 test squote_spaces get "this" =
223   { "spc" = "this" }
224
225 (* Test: squote_spaces
226      double quoted value *)
227 test squote_spaces get "\"this\"" =
228   { "spc" = "\"this\"" }
229
230 (* Test: squote_spaces
231      single quoted value *)
232 test squote_spaces get "'this'" =
233   { "spc" = "this" }
234
235 (* Test: squote_spaces
236      unquoted value with spaces *)
237 test squote_spaces get "this that those" = *
238
239 (* Test: squote_spaces
240      double quoted value with spaces *)
241 test squote_spaces get "\"this that those\"" = *
242
243 (* Test: squote_spaces
244      single quoted value with spaces *)
245 test squote_spaces get "'this that those'" =
246   { "spc" = "this that those" }
247
248 (* Test: squote_spaces
249      remove spaces from single-quoted value *)
250 test squote_spaces put "'this that those'"
251   after set "spc" "thisthat" =
252   "'thisthat'"
253
254 (* Test: squote_spaces
255      add spaces to unquoted value *)
256 test squote_spaces put "this"
257   after set "spc" "this that those" =
258   "'this that those'"
259
260 (* Test: squote_spaces
261      add spaces to double-quoted value *)
262 test squote_spaces put "\"this\""
263   after set "spc" "this that those" =
264   "'this that those'"
265
266 (* Test: squote_spaces
267      add spaces to single-quoted value *)
268 test squote_spaces put "'this'"
269   after set "spc" "this that those" =
270   "'this that those'"
271
272 (* Group: nil cases *)
273
274 (* View: dquote_opt_nil *)
275 let dquote_opt_nil =
276      let body = store Quote.double_opt_re
277   in [ label "dquote_opt_nil" . Quote.do_dquote_opt_nil body ]?
278
279 (* Test: dquote_opt_nil *)
280 test dquote_opt_nil get "this" =
281   { "dquote_opt_nil" = "this" }
282
283 (* Test: dquote_opt_nil *)
284 test dquote_opt_nil get "'this'" =
285   { "dquote_opt_nil" = "'this'" }
286
287 (* Test: dquote_opt_nil *)
288 test dquote_opt_nil get "\"this\"" =
289   { "dquote_opt_nil" = "this" }
290
291 (* Test: dquote_opt_nil *)
292 test dquote_opt_nil put ""
293   after set "dquote_opt_nil" "this" =
294   "this"
295
296 (* Test: dquote_opt_nil *)
297 test dquote_opt_nil put "\"this\""
298   after set "dquote_opt_nil" "this" =
299   "\"this\""
300
301 (* Test: dquote_opt_nil *)
302 test dquote_opt_nil put "'this'"
303   after set "dquote_opt_nil" "this" =
304   "this"
305
306 (* View: squote_opt_nil *)
307 let squote_opt_nil =
308      let body = store Quote.single_opt_re
309   in [ label "squote_opt_nil" . Quote.do_squote_opt_nil body ]?
310
311 (* Test: squote_opt_nil *)
312 test squote_opt_nil get "this" =
313   { "squote_opt_nil" = "this" }
314
315 (* Test: squote_opt_nil *)
316 test squote_opt_nil get "'this'" =
317   { "squote_opt_nil" = "this" }
318
319 (* Test: squote_opt_nil *)
320 test squote_opt_nil get "\"this\"" =
321   { "squote_opt_nil" = "\"this\"" }
322
323 (* Test: squote_opt_nil *)
324 test squote_opt_nil put ""
325   after set "squote_opt_nil" "this" =
326   "this"
327
328 (* Test: squote_opt_nil *)
329 test squote_opt_nil put "\"this\""
330   after set "squote_opt_nil" "this" =
331   "this"
332
333 (* Test: squote_opt_nil *)
334 test squote_opt_nil put "\"this\""
335   after set "squote_opt_nil" "this" =
336   "this"
337
338 (* View: quote_opt_nil *)
339 let quote_opt_nil =
340      let body = store Quote.any_opt_re
341   in [ label "quote_opt_nil" . Quote.do_quote_opt_nil body ]?
342
343 (* Test: quote_opt_nil *)
344 test quote_opt_nil get "this" =
345   { "quote_opt_nil" = "this" }
346
347 (* Test: quote_opt_nil *)
348 test quote_opt_nil get "'this'" =
349   { "quote_opt_nil" = "this" }
350
351 (* Test: quote_opt_nil *)
352 test quote_opt_nil get "\"this\"" =
353   { "quote_opt_nil" = "this" }
354
355 (* Test: quote_opt_nil *)
356 test quote_opt_nil put ""
357   after set "quote_opt_nil" "this" =
358   "this"
359
360 (* Test: quote_opt_nil *)
361 test quote_opt_nil put "\"this\""
362   after set "quote_opt_nil" "this" =
363   "\"this\""
364
365 (* Test: quote_opt_nil *)
366 test quote_opt_nil put "'this'"
367   after set "quote_opt_nil" "this" =
368   "'this'"
369