Bump to 1.14.1
[platform/upstream/augeas.git] / lenses / tests / test_inifile.aug
1 (*
2 Module: Test_IniFile
3   Provides unit tests and examples for the <IniFile> module.
4
5 About: Tests to run
6
7    The tests are run with all combinations of the following
8    three parameters:
9
10    > separator   :  (a) default (/[:=]/ "=") ;   (b) "=" "="
11    > comment     :  (c) default (/[;#]/ ";") ;   (d) ";" ";"
12    > empty lines :  (e) default              ;   (f) noempty
13
14 *)
15
16 module Test_IniFile =
17
18   (* ALL TESTS TO RUN *)
19
20
21   (* Group: TEST a/c/e *)
22   (* Variable: comment_ace *)
23   let comment_ace = IniFile.comment IniFile.comment_re IniFile.comment_default
24   (* Variable: sep_ace *)
25   let sep_ace     = IniFile.sep IniFile.sep_re IniFile.sep_default
26   (* Variable: entry_ace *)
27   let entry_ace   = IniFile.entry IniFile.entry_re sep_ace comment_ace
28   (* Variable: title_ace *)
29   let title_ace   = IniFile.title IniFile.record_re
30   (* Variable: record_ace *)
31   let record_ace  = IniFile.record title_ace entry_ace
32   (* Variable: lns_ace *)
33   let lns_ace     = IniFile.lns record_ace comment_ace
34   (* Variable: conf_ace *)
35   let conf_ace    = "# comment with sharp
36
37 [section1]
38 test_ace = value # end of line comment
39 test_ace =
40 test_ace = \"value with spaces\"
41 ; comment with colon
42
43 "
44   (* Test: lns_ace
45       Testing the a/c/e combination *)
46   test lns_ace get conf_ace =
47       { "#comment" = "comment with sharp" }
48       {}
49       { "section1"
50           { "test_ace" = "value"
51              { "#comment" = "end of line comment" } }
52           { "test_ace" }
53           { "test_ace" = "value with spaces" }
54           { "#comment"  = "comment with colon" }
55           {} }
56
57   test lns_ace put conf_ace after
58     set "section1/foo" "yes" = "# comment with sharp
59
60 [section1]
61 test_ace = value # end of line comment
62 test_ace =
63 test_ace = \"value with spaces\"
64 ; comment with colon
65
66 foo=yes
67 "
68
69   (* Test: lns_ace
70        Quotes can appear within bare values *)
71   test lns_ace get "[section]\ntest_ace = value \"with quotes\" inside\n" =
72   { "section" { "test_ace" = "value \"with quotes\" inside" } }
73
74   (* Group: TEST a/c/f *)
75   (* Variable: comment_acf *)
76   let comment_acf = IniFile.comment IniFile.comment_re IniFile.comment_default
77   (* Variable: sep_acf *)
78   let sep_acf     = IniFile.sep IniFile.sep_re IniFile.sep_default
79   (* Variable: entry_acf *)
80   let entry_acf   = IniFile.entry IniFile.entry_re sep_acf comment_acf
81   (* Variable: title_acf *)
82   let title_acf   = IniFile.title IniFile.record_re
83   (* Variable: record_acf *)
84   let record_acf  = IniFile.record_noempty title_acf entry_acf
85   (* Variable: lns_acf *)
86   let lns_acf     = IniFile.lns_noempty record_acf comment_acf
87   (* Variable: conf_acf *)
88   let conf_acf   = "# comment with sharp
89 [section1]
90 test_acf = value
91 test_acf =
92 test_acf : value2 # end of line comment
93 ; comment with colon
94 "
95   (* Test: lns_acf
96       Testing the a/c/f combination *)
97   test lns_acf get conf_acf =
98       { "#comment" = "comment with sharp" }
99       { "section1"
100          { "test_acf" = "value" }
101          { "test_acf" }
102          { "test_acf" = "value2"
103             { "#comment" = "end of line comment" } }
104          { "#comment"  = "comment with colon" } }
105
106
107   (* Group: TEST a/d/e *)
108   (* Variable: comment_ade *)
109   let comment_ade = IniFile.comment ";" ";"
110   (* Variable: sep_ade *)
111   let sep_ade     = IniFile.sep IniFile.sep_re IniFile.sep_default
112   (* Variable: entry_ade *)
113   let entry_ade   = IniFile.entry IniFile.entry_re sep_ade comment_ade
114   (* Variable: title_ade *)
115   let title_ade   = IniFile.title IniFile.record_re
116   (* Variable: record_ade *)
117   let record_ade  = IniFile.record title_ade entry_ade
118   (* Variable: lns_ade *)
119   let lns_ade     = IniFile.lns record_ade comment_ade
120   (* Variable: conf_ade *)
121   let conf_ade    = "; a first comment with colon
122 [section1]
123 test_ade = value
124 test_ade : value2 ; end of line comment
125 ; comment with colon
126
127 test_ade =
128 "
129   (* Test: lns_ade
130       Testing the a/d/e combination *)
131    test lns_ade get conf_ade =
132       { "#comment" = "a first comment with colon" }
133       { "section1"
134          { "test_ade" = "value" }
135          { "test_ade" = "value2"
136             { "#comment" = "end of line comment" } }
137          { "#comment"  = "comment with colon" }
138          {}
139          { "test_ade" } }
140
141
142   (* Group: TEST a/d/f *)
143   (* Variable: comment_adf *)
144   let comment_adf = IniFile.comment ";" ";"
145   (* Variable: sep_adf *)
146   let sep_adf     = IniFile.sep IniFile.sep_re IniFile.sep_default
147   (* Variable: entry_adf *)
148   let entry_adf   = IniFile.entry IniFile.entry_re sep_adf comment_adf
149   (* Variable: title_adf *)
150   let title_adf   = IniFile.title IniFile.record_re
151   (* Variable: record_adf *)
152   let record_adf  = IniFile.record_noempty title_adf entry_adf
153   (* Variable: lns_adf *)
154   let lns_adf     = IniFile.lns_noempty record_adf comment_adf
155   (* Variable: conf_adf *)
156   let conf_adf    = "; a first comment with colon
157 [section1]
158 test_adf = value
159 test_adf : value2 ; end of line comment
160 ; comment with colon
161 test_adf =
162 "
163   (* Test: lns_adf
164       Testing the a/d/f combination *)
165    test lns_adf get conf_adf =
166       { "#comment" = "a first comment with colon" }
167       { "section1"
168          { "test_adf" = "value" }
169          { "test_adf" = "value2"
170             { "#comment" = "end of line comment" } }
171          { "#comment"  = "comment with colon" }
172          { "test_adf" } }
173
174
175   (* Group: TEST b/c/e *)
176   (* Variable: comment_bce *)
177   let comment_bce = IniFile.comment IniFile.comment_re IniFile.comment_default
178   (* Variable: sep_bce *)
179   let sep_bce     = IniFile.sep "=" "="
180   (* Variable: entry_bce *)
181   let entry_bce   = IniFile.entry IniFile.entry_re sep_bce comment_bce
182   (* Variable: title_bce *)
183   let title_bce   = IniFile.title IniFile.record_re
184   (* Variable: record_bce *)
185   let record_bce  = IniFile.record title_bce entry_bce
186   (* Variable: lns_bce *)
187   let lns_bce     = IniFile.lns record_bce comment_bce
188   (* Variable: conf_bce *)
189   let conf_bce   = "# comment with sharp
190
191 [section1]
192 test_bce = value # end of line comment
193 ; comment with colon
194
195 test_bce =
196 "
197   (* Test: lns_bce
198       Testing the b/c/e combination *)
199   test lns_bce get conf_bce =
200       { "#comment" = "comment with sharp" }
201       {}
202       { "section1"
203           { "test_bce" = "value"
204              { "#comment" = "end of line comment" } }
205           { "#comment"  = "comment with colon" }
206           {}
207           { "test_bce" } }
208
209
210   (* Group: TEST b/c/f *)
211   (* Variable: comment_bcf *)
212   let comment_bcf = IniFile.comment IniFile.comment_re IniFile.comment_default
213   (* Variable: sep_bcf *)
214   let sep_bcf     = IniFile.sep "=" "="
215   (* Variable: entry_bcf *)
216   let entry_bcf   = IniFile.entry IniFile.entry_re sep_bcf comment_bcf
217   (* Variable: title_bcf *)
218   let title_bcf   = IniFile.title IniFile.record_re
219   (* Variable: record_bcf *)
220   let record_bcf  = IniFile.record_noempty title_bce entry_bcf
221   (* Variable: lns_bcf *)
222   let lns_bcf     = IniFile.lns_noempty record_bce comment_bcf
223   (* Variable: conf_bcf *)
224   let conf_bcf   = "# conf with sharp
225 [section1]
226 test_bcf = value # end of line comment
227 ; comment with colon
228 test_bcf =
229 "
230   (* Test: lns_bcf
231       Testing the b/c/f combination *)
232   test lns_bcf get conf_bcf =
233       { "#comment" = "conf with sharp" }
234       { "section1"
235           { "test_bcf" = "value"
236              { "#comment" = "end of line comment" } }
237           { "#comment"  = "comment with colon" }
238           { "test_bcf" } }
239
240
241   (* Group: TEST b/d/e *)
242   (* Variable: comment_bde *)
243   let comment_bde = IniFile.comment ";" ";"
244   (* Variable: sep_bde *)
245   let sep_bde     = IniFile.sep "=" "="
246   (* Variable: entry_bde *)
247   let entry_bde   = IniFile.entry IniFile.entry_re sep_bde comment_bde
248   (* Variable: title_bde *)
249   let title_bde   = IniFile.title IniFile.record_re
250   (* Variable: record_bde *)
251   let record_bde  = IniFile.record title_bde entry_bde
252   (* Variable: lns_bde *)
253   let lns_bde     = IniFile.lns record_bde comment_bde
254   (* Variable: conf_bde *)
255   let conf_bde    = "; first comment with colon
256
257 [section1]
258 test_bde = value ; end of line comment
259 ; comment with colon
260
261 test_bde =
262 "
263   (* Test: lns_bde
264       Testing the b/d/e combination *)
265   test lns_bde get conf_bde =
266       { "#comment" = "first comment with colon" }
267       {}
268       { "section1"
269           { "test_bde" = "value"
270              { "#comment" = "end of line comment" } }
271           { "#comment"  = "comment with colon" }
272           {}
273           { "test_bde" } }
274
275
276   (* Group: TEST b/d/f *)
277   (* Variable: comment_bdf *)
278   let comment_bdf = IniFile.comment ";" ";"
279   (* Variable: sep_bdf *)
280   let sep_bdf     = IniFile.sep "=" "="
281   (* Variable: entry_bdf *)
282   let entry_bdf   = IniFile.entry IniFile.entry_re sep_bdf comment_bdf
283   (* Variable: title_bdf *)
284   let title_bdf   = IniFile.title IniFile.record_re
285   (* Variable: record_bdf *)
286   let record_bdf  = IniFile.record_noempty title_bdf entry_bdf
287   (* Variable: lns_bdf *)
288   let lns_bdf     = IniFile.lns_noempty record_bdf comment_bdf
289   (* Variable: conf_bdf *)
290   let conf_bdf    = "; first comment with colon
291 [section1]
292 test_bdf = value ; end of line comment
293 ; comment with colon
294 test_bdf =
295 "
296   (* Test: lns_bdf
297       Testing the b/d/f combination *)
298   test lns_bdf get conf_bdf =
299       { "#comment" = "first comment with colon" }
300       { "section1"
301           { "test_bdf" = "value"
302              { "#comment" = "end of line comment" } }
303           { "#comment"  = "comment with colon" }
304           { "test_bdf" } }
305
306
307   (* Group: TEST multiline values *)
308   (* Variable: multiline_test *)
309   let multiline_test = "test_ace = val1\n  val2\n   val3\n"
310   (* Variable: multiline_nl *)
311   let multiline_nl = "test_ace =\n  val2\n   val3\n"
312   (* Variable: multiline_ace *)
313   let multiline_ace = IniFile.entry_multiline IniFile.entry_re sep_ace comment_ace
314   (* Test: multiline_ace
315        Testing the a/c/e combination with a multiline entry *)
316   test multiline_ace get multiline_test =
317       { "test_ace" = "val1\n  val2\n   val3" }
318   (* Test: multiline_nl
319        Multiline values can begin with a single newline *)
320   test multiline_ace get multiline_nl =
321       { "test_ace" = "\n  val2\n   val3" }
322
323   (* Test: lns_ace
324        Ticket #243 *)
325   test lns_ace get "[section1]
326 ticket_243 = \"value1;value2#value3\" # end of line comment
327 " =
328   { "section1"
329     { "ticket_243" = "value1;value2#value3"
330       { "#comment" = "end of line comment" }
331     }
332   }
333
334   (* Group: TEST list entries *)
335   (* Variable: list_test *)
336   let list_test = "test_ace = val1,val2,val3 # a comment\n"
337   (* Lens: list_ace *)
338   let list_ace = IniFile.entry_list IniFile.entry_re sep_ace RX.word Sep.comma comment_ace
339   (* Test: list_ace
340        Testing the a/c/e combination with a list entry *)
341   test list_ace get list_test =
342   { "test_ace"
343     { "1" = "val1" }
344     { "2" = "val2" }
345     { "3" = "val3" }
346     { "#comment" = "a comment" }
347   }
348
349   (* Variable: list_nocomment_test *)
350   let list_nocomment_test = "test_ace = val1,val2,val3 \n"
351   (* Lens: list_nocomment_ace *)
352   let list_nocomment_ace = IniFile.entry_list_nocomment IniFile.entry_re sep_ace RX.word Sep.comma
353   (* Test: list_nocomment_ace
354        Testing the a/c/e combination with a list entry without end-of-line comment *)
355   test list_nocomment_ace get list_nocomment_test =
356   { "test_ace"
357     { "1" = "val1" }
358     { "2" = "val2" }
359     { "3" = "val3" }
360   }
361
362   (* Test: IniFile.lns_loose *)
363   test IniFile.lns_loose get conf_ace =
364   { "section" = ".anon"
365     { "#comment" = "comment with sharp" }
366     {  }
367   }
368   { "section" = "section1"
369     { "test_ace" = "value"
370       { "#comment" = "end of line comment" }
371     }
372     { "test_ace" }
373     { "test_ace" = "value with spaces" }
374     { "#comment" = "comment with colon" }
375     {  }
376   }
377
378   (* Test: IniFile.lns_loose_multiline *)
379   test IniFile.lns_loose_multiline get conf_ace =
380   { "section" = ".anon"
381     { "#comment" = "comment with sharp" }
382     {  }
383   }
384   { "section" = "section1"
385     { "test_ace" = "value"
386       { "#comment" = "end of line comment" }
387     }
388     { "test_ace" }
389     { "test_ace" = "value with spaces" }
390     { "#comment" = "comment with colon" }
391     {  }
392   }
393   
394   test IniFile.lns_loose_multiline get multiline_test =
395       { "section" = ".anon" { "test_ace" = "val1\n  val2\n   val3" } }
396