3 Provides unit tests and examples for the <IniFile> module.
7 The tests are run with all combinations of the following
10 > separator : (a) default (/[:=]/ "=") ; (b) "=" "="
11 > comment : (c) default (/[;#]/ ";") ; (d) ";" ";"
12 > empty lines : (e) default ; (f) noempty
18 (* ALL TESTS TO RUN *)
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
38 test_ace = value # end of line comment
40 test_ace = \"value with spaces\"
45 Testing the a/c/e combination *)
46 test lns_ace get conf_ace =
47 { "#comment" = "comment with sharp" }
50 { "test_ace" = "value"
51 { "#comment" = "end of line comment" } }
53 { "test_ace" = "value with spaces" }
54 { "#comment" = "comment with colon" }
57 test lns_ace put conf_ace after
58 set "section1/foo" "yes" = "# comment with sharp
61 test_ace = value # end of line comment
63 test_ace = \"value with spaces\"
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" } }
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
92 test_acf : value2 # end of line comment
96 Testing the a/c/f combination *)
97 test lns_acf get conf_acf =
98 { "#comment" = "comment with sharp" }
100 { "test_acf" = "value" }
102 { "test_acf" = "value2"
103 { "#comment" = "end of line comment" } }
104 { "#comment" = "comment with colon" } }
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
124 test_ade : value2 ; end of line comment
130 Testing the a/d/e combination *)
131 test lns_ade get conf_ade =
132 { "#comment" = "a first comment with colon" }
134 { "test_ade" = "value" }
135 { "test_ade" = "value2"
136 { "#comment" = "end of line comment" } }
137 { "#comment" = "comment with colon" }
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
159 test_adf : value2 ; end of line comment
164 Testing the a/d/f combination *)
165 test lns_adf get conf_adf =
166 { "#comment" = "a first comment with colon" }
168 { "test_adf" = "value" }
169 { "test_adf" = "value2"
170 { "#comment" = "end of line comment" } }
171 { "#comment" = "comment with colon" }
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
192 test_bce = value # end of line comment
198 Testing the b/c/e combination *)
199 test lns_bce get conf_bce =
200 { "#comment" = "comment with sharp" }
203 { "test_bce" = "value"
204 { "#comment" = "end of line comment" } }
205 { "#comment" = "comment with colon" }
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
226 test_bcf = value # end of line comment
231 Testing the b/c/f combination *)
232 test lns_bcf get conf_bcf =
233 { "#comment" = "conf with sharp" }
235 { "test_bcf" = "value"
236 { "#comment" = "end of line comment" } }
237 { "#comment" = "comment with colon" }
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
258 test_bde = value ; end of line comment
264 Testing the b/d/e combination *)
265 test lns_bde get conf_bde =
266 { "#comment" = "first comment with colon" }
269 { "test_bde" = "value"
270 { "#comment" = "end of line comment" } }
271 { "#comment" = "comment with colon" }
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
292 test_bdf = value ; end of line comment
297 Testing the b/d/f combination *)
298 test lns_bdf get conf_bdf =
299 { "#comment" = "first comment with colon" }
301 { "test_bdf" = "value"
302 { "#comment" = "end of line comment" } }
303 { "#comment" = "comment with colon" }
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" }
325 test lns_ace get "[section1]
326 ticket_243 = \"value1;value2#value3\" # end of line comment
329 { "ticket_243" = "value1;value2#value3"
330 { "#comment" = "end of line comment" }
334 (* Group: TEST list entries *)
335 (* Variable: list_test *)
336 let list_test = "test_ace = val1,val2,val3 # a comment\n"
338 let list_ace = IniFile.entry_list IniFile.entry_re sep_ace RX.word Sep.comma comment_ace
340 Testing the a/c/e combination with a list entry *)
341 test list_ace get list_test =
346 { "#comment" = "a comment" }
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 =
362 (* Test: IniFile.lns_loose *)
363 test IniFile.lns_loose get conf_ace =
364 { "section" = ".anon"
365 { "#comment" = "comment with sharp" }
368 { "section" = "section1"
369 { "test_ace" = "value"
370 { "#comment" = "end of line comment" }
373 { "test_ace" = "value with spaces" }
374 { "#comment" = "comment with colon" }
378 (* Test: IniFile.lns_loose_multiline *)
379 test IniFile.lns_loose_multiline get conf_ace =
380 { "section" = ".anon"
381 { "#comment" = "comment with sharp" }
384 { "section" = "section1"
385 { "test_ace" = "value"
386 { "#comment" = "end of line comment" }
389 { "test_ace" = "value with spaces" }
390 { "#comment" = "comment with colon" }
394 test IniFile.lns_loose_multiline get multiline_test =
395 { "section" = ".anon" { "test_ace" = "val1\n val2\n val3" } }