1# Before `make install' is performed this script should be runnable with
2# `make test'. After `make install' it should work as `perl test.pl'
3
4#########################
5
6use Test::More tests => 208;
7#use diagnostics;
8use strict;
9use File::Spec;
10
11BEGIN { use_ok( 'Config::IniHash' ); }
12
13use Config::IniHash qw(ReadINI WriteINI AddDefaults);
14
15my %orig_data = (
16	sec1 => {
17		foo => 5,
18		BAR => 'Hello World!'
19	},
20	seC2 => {
21		What => 'sgfdfg=wtert',
22		other => 'fsdgfg;dfhfdghfg',
23	},
24);
25
26if (!exists $ENV{TEMP} or !-d $ENV{TEMP}) {
27	$ENV{TEMP} = File::Spec->tmpdir;
28}
29
30my $script_file = $0;
31if (! File::Spec->file_name_is_absolute($script_file)) {
32	$script_file = File::Spec->rel2abs($script_file);
33}
34
35{
36	(my $filename = $script_file) =~ s/\.pl$/-write.ini/;
37	ok( WriteINI( $filename, \%orig_data), "WriteINI => $filename");
38	END { unlink $filename }
39
40	{
41		my $read_data = ReadINI( $filename, {case => 'sensitive'});
42		ok( (defined($read_data) and ref($read_data)), "ReadINI '$filename'");
43
44		is_deeply( \%orig_data, $read_data, "Read data match the original");
45	}
46
47	{
48		my $read_data = ReadINI( $filename);
49		ok( (defined($read_data) and ref($read_data)), "ReadINI '$filename'");
50
51		my $read_data2 = ReadINI( $filename, {case => 'lower'});
52		ok( (defined($read_data2) and ref($read_data2)), "ReadINI '$filename', {case => 'lower'}");
53
54		is_deeply( $read_data, $read_data2, "case => 'lower' is the default");
55	}
56}
57
58(my $filename = $script_file) =~ s/\.pl$/.ini/;
59
60{
61	my $read_data = ReadINI( $filename);
62	ok( (defined($read_data) and ref($read_data)), "ReadINI '$filename' (different data)");
63
64	is( $read_data->{Two}{temp}, $ENV{TEMP}, "System variables are interpolated by default");
65}
66
67{
68	my $read_data = ReadINI( $filename, {systemvars => 0});
69	ok( (defined($read_data) and ref($read_data)), "ReadINI '$filename', {systemvars => 0}");
70
71	is( $read_data->{Two}{temp}, '%TEMP%', "System variables are not interpolated if not wanted");
72}
73
74{
75	my $read_data = ReadINI( $filename, {systemvars => 1});
76	ok( (defined($read_data) and ref($read_data)), "ReadINI '$filename', {systemvars => 1}");
77
78	is( $read_data->{Two}{temp}, $ENV{TEMP}, "System variables are interpolated if asked to");
79}
80
81{
82	my $read_data = ReadINI( $filename, {systemvars => {TEMP => 'subverted'}});
83	ok( (defined($read_data) and ref($read_data)), "ReadINI '$filename', {systemvars => {...}}");
84
85	is( $read_data->{Two}{TEMP}, 'subverted', "System variables are interpolated using a custom hash");
86}
87
88
89{
90	my $read_data = ReadINI( $filename, {allowmultiple => 0});
91	ok( (defined($read_data) and ref($read_data)), "ReadINI '$filename', {allowmultiple => 0}");
92
93	is( $read_data->{Four}{foo}, 3, "Multiple values overwrite each other");
94}
95{
96	my $read_data = ReadINI( $filename, {allowmultiple => 1});
97	ok( (defined($read_data) and ref($read_data)), "ReadINI '$filename', {allowmultiple => 1}");
98
99	is_deeply( $read_data->{Four}{foo}, [1,2,3], "Multiple values produce an array");
100	is_deeply( $read_data->{Four}{bar}, 'U Trech Sudu', "But single values still produce a scalar");
101}
102{
103	my $read_data = ReadINI( $filename, {allowmultiple => {Four => 'foo,bar'}});
104	ok( (defined($read_data) and ref($read_data)), "ReadINI '$filename', {allowmultiple => {Four => 'foo,bar'}}");
105
106	is_deeply( $read_data->{Four}{foo}, [1,2,3], "Specified multiple values produce an array");
107	is_deeply( $read_data->{Four}{bar}, ['U Trech Sudu'], "Single values as well if specified");
108	is_deeply( $read_data->{Two}{foo}, 'dva', "Multiple values that are not specified produce scalars");
109
110	my $read_data2 = ReadINI( $filename, {allowmultiple => {Four => [qw(foo bar)]}});
111	ok( (defined($read_data2) and ref($read_data2)), "ReadINI '$filename', {allowmultiple => {Four => [qw(foo bar)]}}");
112
113	is_deeply( $read_data, $read_data2, "Comma separated lists and arrayrefs both work");
114}
115
116
117{
118	my $read_data = ReadINI( $filename, {allowmultiple => {'*' => 'foo,bar'}});
119	ok( (defined($read_data) and ref($read_data)), "ReadINI '$filename', {allowmultiple => {'*' => 'foo,bar'}}");
120
121	is_deeply( $read_data->{Four}{foo}, [1,2,3], "Specified multiple values produce an array");
122	is_deeply( $read_data->{Two}{foo}, ['jedna','dva'], "Specified multiple values produce an array in all sections");
123}
124
125{
126	my $read_data = ReadINI( $filename, {});
127
128	is( $read_data->{Five}{'#com1'}, undef, "# is a comment char by default");
129	is( $read_data->{Five}{';com2'}, undef, "; is a comment char by default");
130	is( $read_data->{Five}{'\'com3'}, 'hu', "' is NOT a comment char by default");
131	is( $read_data->{Five}{'//com4'}, 'hy', "// is NOT a comment char by default");
132}
133
134{
135	my $read_data = ReadINI( $filename, {comment => ";'"});
136
137	is( $read_data->{Five}{'#com1'}, 'hi', "# is NOT a specified comment char");
138	is( $read_data->{Five}{';com2'}, undef, "; is a specified comment char");
139	is( $read_data->{Five}{'\'com3'}, undef, "' is a specified comment char");
140	is( $read_data->{Five}{'//com4'}, 'hy', "// is NOT a specified comment char");
141}
142
143{
144	my $read_data = ReadINI( $filename, {comment => qr{^\s*//}});
145
146	is( $read_data->{Five}{'#com1'}, 'hi', "# is NOT a specified comment char");
147	is( $read_data->{Five}{';com2'}, 'ho', "; is NOT a specified comment char");
148	is( $read_data->{Five}{'\'com3'}, 'hu', "' is NOT a specified comment char");
149	is( $read_data->{Five}{'//com4'}, undef, "// is the specified comment char");
150}
151
152{
153	my $read_data = ReadINI( $filename);
154
155	is( $read_data->{Six}{long}, "<<*END*", "heredocs are not allowed by default");
156	is( $read_data->{Six}{short}, "Hello", "short value is read fine");
157}
158{
159	my $read_data = ReadINI( $filename, {heredoc => 1});
160
161	is( $read_data->{Six}{long}, "blah\nblah blah\nblah", "heredoc works if allowed");
162	is( $read_data->{Six}{short}, "Hello", "short value is read fine");
163}
164
165{
166	use File::Copy qw(copy);
167	(my $filename2 = $filename) =~ s/\.ini/-2.ini/;
168	copy $filename => $filename2;
169	END {unlink $filename2};
170	open my $FH, '>>', $filename2 or die "Unable to append to $filename2: $^E\n";
171	print $FH <<'*EnD*';
172long2=<<"*END*"
173blah
174blah blah %TEMP%
175blah %NONSE_NS%
176*END*
177long3=<<'*END*'
178blah
179blah blah %TEMP%
180blah %NONSE_NS%
181*END*
182long4=<<*END*
183the temp directory is %TEMP%
184nonsense is %NONSE_NS%
185*END*
186*EnD*
187	close $FH;
188	{
189		my $read_data = eval {ReadINI( $filename2, {heredoc => 0})};
190		ok(ref($read_data), "Extended heredocs are ignored if heredoc => 0")
191	}
192
193	{
194		my $read_data = eval {ReadINI( $filename2, {heredoc => 1})};
195		ok(! defined ($read_data), "Extended heredocs cause errors if heredoc => 1");
196		ok(scalar($@ =~ /^\QHeredoc value for [Six]long2 not closed at end of file!\E/), "With the right error message (\$\@=$@)");
197	}
198
199	{
200		my $read_data = eval {ReadINI( $filename2, {heredoc => 'Perl'})};
201		ok(ref($read_data), "Extended heredocs are allowed if heredoc => 'Perl'");
202
203		is( $read_data->{Six}{long}, "blah\nblah blah\nblah", "heredoc works if allowed");
204		is( $read_data->{Six}{short}, "Hello", "short value is read fine");
205		is( $read_data->{Six}{long2}, "blah\nblah blah $ENV{TEMP}\nblah ", "heredoc works if allowed, <<\"*END*\" interpolates");
206		is( $read_data->{Six}{long3}, "blah\nblah blah %TEMP%\nblah %NONSE_NS%", "heredoc works if allowed, <<'*END*' doesn't interpolate");
207
208		is( $read_data->{Six}{long4}, "the temp directory is $ENV{TEMP}\nnonsense is %NONSE_NS%", "heredoc works if allowed, <<*END* does interpolate by default");
209	}
210
211	{
212		my $read_data = eval {ReadINI( $filename2, {heredoc => 'Perl', systemvars => 0})};
213		ok(ref($read_data), "Extended heredocs are allowed if heredoc => 'Perl', systemvars => 0: \$\@=$@");
214
215		is( $read_data->{Six}{long2}, "blah\nblah blah $ENV{TEMP}\nblah ", "heredoc works if allowed, <<\"*END*\" interpolates");
216		is( $read_data->{Six}{long3}, "blah\nblah blah %TEMP%\nblah %NONSE_NS%", "heredoc works if allowed, <<'*END*' doesn't interpolate");
217		is( $read_data->{Six}{long4}, "the temp directory is %TEMP%\nnonsense is %NONSE_NS%", "heredoc works if allowed, <<*END* doesn't interpolate by if systemvars => 0");
218	}
219}
220
221
222{
223	my $read_data = ReadINI( $filename, );
224
225	ok( ! defined $read_data->{'__SECTIONS__'}, "the sections order is not remembered by default");
226}
227
228{
229	my $read_data = ReadINI( $filename, {sectionorder => 1, case => 'sensitive'});
230
231	ok( defined $read_data->{'__SECTIONS__'}, "the sections order is remembered if sectionorder => 1");
232	is_deeply($read_data->{'__SECTIONS__'}, [qw(:default one Two Three Four Five Six)], "the sections order is remembered correctly");
233
234	my $missing=0;
235	foreach (@{$read_data->{'__SECTIONS__'}}) {
236		$missing++ unless exists ($read_data->{$_});
237	}
238	is ($missing, 0, "All sections in __SECTIONS__ are accessible");
239}
240
241{
242	my @sections;
243	my $read_data = ReadINI( $filename, {sectionorder => \@sections, case => 'sensitive'});
244
245	ok( ! defined $read_data->{'__SECTIONS__'}, "\$config->{'__SECTIONS__'} is not defined sectionorder => \\\@array");
246	is_deeply(\@sections, [qw(:default one Two Three Four Five Six)], "the sections order is remembered correctly");
247
248	my $missing=0;
249	foreach (@sections) {
250		$missing++ unless exists ($read_data->{$_});
251	}
252	is ($missing, 0, "All sections in \@sections are accessible");
253}
254
255{
256	my $read_data = ReadINI( $filename, {sectionorder => 1, case => 'sensitive'});
257
258	is($read_data->{Three}{aaaa}, 'asd', "case sensitive");
259	is($read_data->{three}{aaaa}, undef, "case sensitive");
260	is($read_data->{THREE}{aaaa}, undef, "case sensitive");
261
262	is($read_data->{Three}{aaaa}, 'asd', "case sensitive");
263	is($read_data->{Three}{Bbbb}, 'asd', "case sensitive");
264	is($read_data->{Three}{CCCC}, 'asd', "case sensitive");
265
266	is($read_data->{Three}{aaaa}, 'asd', "case sensitive");
267	is($read_data->{Three}{bbbb}, undef, "case sensitive");
268	is($read_data->{Three}{cccc}, undef, "case sensitive");
269
270	is($read_data->{Three}{AAAA}, undef, "case sensitive");
271	is($read_data->{Three}{BBBB}, undef, "case sensitive");
272	is($read_data->{Three}{CCCC}, 'asd', "case sensitive");
273
274	is_deeply($read_data->{'__SECTIONS__'}, [qw(:default one Two Three Four Five Six)], "the sections order is remembered with correct case");
275
276	my $missing=0;
277	foreach (@{$read_data->{'__SECTIONS__'}}) {
278		$missing++ unless exists ($read_data->{$_});
279	}
280	is ($missing, 0, "All sections in __SECTIONS__ are accessible");
281}
282
283{
284	my $read_data = ReadINI( $filename, {sectionorder => 1, case => 'tolower'});
285
286	is($read_data->{Three}{aaaa}, undef, "tolower");
287	is($read_data->{three}{aaaa}, 'asd', "tolower");
288	is($read_data->{THREE}{aaaa}, undef, "tolower");
289
290	is($read_data->{three}{aaaa}, 'asd', "tolower");
291	is($read_data->{three}{Bbbb}, undef, "tolower");
292	is($read_data->{three}{CCCC}, undef, "tolower");
293
294	is($read_data->{three}{aaaa}, 'asd', "tolower");
295	is($read_data->{three}{bbbb}, 'asd', "tolower");
296	is($read_data->{three}{cccc}, 'asd', "tolower");
297
298	is($read_data->{three}{AAAA}, undef, "tolower");
299	is($read_data->{three}{BBBB}, undef, "tolower");
300	is($read_data->{three}{CCCC}, undef, "tolower");
301
302	is_deeply($read_data->{'__SECTIONS__'}, [qw(:default one two three four five six)], "the sections order is remembered with correct case");
303
304	my $missing=0;
305	foreach (@{$read_data->{'__SECTIONS__'}}) {
306		$missing++ unless exists ($read_data->{$_});
307	}
308	is ($missing, 0, "All sections in __SECTIONS__ are accessible");
309}
310
311{
312	my $read_data = ReadINI( $filename, {sectionorder => 1, case => 'toupper'});
313
314	is($read_data->{Three}{AAAA}, undef, "toupper");
315	is($read_data->{three}{AAAA}, undef, "toupper");
316	is($read_data->{THREE}{AAAA}, 'asd', "toupper");
317
318	is($read_data->{THREE}{aaaa}, undef, "toupper");
319	is($read_data->{THREE}{Bbbb}, undef, "toupper");
320	is($read_data->{THREE}{CCCC}, 'asd', "toupper");
321
322	is($read_data->{THREE}{aaaa}, undef, "toupper");
323	is($read_data->{THREE}{bbbb}, undef, "toupper");
324	is($read_data->{THREE}{cccc}, undef, "toupper");
325
326	is($read_data->{THREE}{AAAA}, 'asd', "toupper");
327	is($read_data->{THREE}{BBBB}, 'asd', "toupper");
328	is($read_data->{THREE}{CCCC}, 'asd', "toupper");
329
330	is_deeply($read_data->{'__SECTIONS__'}, [qw(:DEFAULT ONE TWO THREE FOUR FIVE SIX)], "the sections order is remembered with correct case");
331
332	my $missing=0;
333	foreach (@{$read_data->{'__SECTIONS__'}}) {
334		$missing++ unless exists ($read_data->{$_});
335	}
336	is ($missing, 0, "All sections in __SECTIONS__ are accessible");
337}
338
339{
340	my $read_data = ReadINI( $filename, {sectionorder => 1, case => 'preserve'});
341
342	is($read_data->{Three}{AAAA}, 'asd', "preserve");
343	is($read_data->{three}{AAAA}, 'asd', "preserve");
344	is($read_data->{THREE}{AAAA}, 'asd', "preserve");
345
346	is($read_data->{THREE}{aaaa}, 'asd', "preserve");
347	is($read_data->{THREE}{Bbbb}, 'asd', "preserve");
348	is($read_data->{THREE}{CCCC}, 'asd', "preserve");
349
350	is($read_data->{THREE}{aaaa}, 'asd', "preserve");
351	is($read_data->{THREE}{bbbb}, 'asd', "preserve");
352	is($read_data->{THREE}{cccc}, 'asd', "preserve");
353
354	is($read_data->{THREE}{AAAA}, 'asd', "preserve");
355	is($read_data->{THREE}{BBBB}, 'asd', "preserve");
356	is($read_data->{THREE}{CCCC}, 'asd', "preserve");
357
358	is_deeply($read_data->{'__SECTIONS__'}, [qw(:default one Two Three Four Five Six)], "the sections order is remembered with correct case");
359
360	my $missing=0;
361	foreach (@{$read_data->{'__SECTIONS__'}}) {
362		$missing++ unless exists ($read_data->{$_});
363	}
364	is ($missing, 0, "All sections in __SECTIONS__ are accessible");
365}
366
367{
368	my $read_data = ReadINI( $filename, {sectionorder => 1, case => 'lower'});
369
370	is($read_data->{Three}{AAAA}, 'asd', "lower");
371	is($read_data->{three}{AAAA}, 'asd', "lower");
372	is($read_data->{THREE}{AAAA}, 'asd', "lower");
373
374	is($read_data->{THREE}{aaaa}, 'asd', "lower");
375	is($read_data->{THREE}{Bbbb}, 'asd', "lower");
376	is($read_data->{THREE}{CCCC}, 'asd', "lower");
377
378	is($read_data->{THREE}{aaaa}, 'asd', "lower");
379	is($read_data->{THREE}{bbbb}, 'asd', "lower");
380	is($read_data->{THREE}{cccc}, 'asd', "lower");
381
382	is($read_data->{THREE}{AAAA}, 'asd', "lower");
383	is($read_data->{THREE}{BBBB}, 'asd', "lower");
384	is($read_data->{THREE}{CCCC}, 'asd', "lower");
385
386	my %keys; @keys{keys %$read_data} = ();
387	is_deeply(\%keys, {map {$_ => undef} qw(:default one two three four five six __SECTIONS__)}, "the sections are remembered with correct case");
388
389	is_deeply($read_data->{'__SECTIONS__'}, [qw(:default one two three four five six)], "the sections order is remembered with correct case");
390
391	my $missing=0;
392	foreach (@{$read_data->{'__SECTIONS__'}}) {
393		$missing++ unless exists ($read_data->{$_});
394	}
395	is ($missing, 0, "All sections in __SECTIONS__ are accessible");
396}
397
398{
399	my $read_data = ReadINI( $filename, {sectionorder => 1, case => 'upper'});
400
401	is($read_data->{Three}{AAAA}, 'asd', "upper");
402	is($read_data->{three}{AAAA}, 'asd', "upper");
403	is($read_data->{THREE}{AAAA}, 'asd', "upper");
404
405	is($read_data->{THREE}{aaaa}, 'asd', "upper");
406	is($read_data->{THREE}{Bbbb}, 'asd', "upper");
407	is($read_data->{THREE}{CCCC}, 'asd', "upper");
408
409	is($read_data->{THREE}{aaaa}, 'asd', "upper");
410	is($read_data->{THREE}{bbbb}, 'asd', "upper");
411	is($read_data->{THREE}{cccc}, 'asd', "upper");
412
413	is($read_data->{THREE}{AAAA}, 'asd', "upper");
414	is($read_data->{THREE}{BBBB}, 'asd', "upper");
415	is($read_data->{THREE}{CCCC}, 'asd', "upper");
416
417	my %keys; @keys{keys %$read_data} = ();
418	is_deeply(\%keys, {map {$_ => undef} qw(:DEFAULT ONE TWO THREE FOUR FIVE SIX __SECTIONS__)}, "the sections are remembered with correct case");
419
420	is_deeply($read_data->{'__SECTIONS__'}, [qw(:DEFAULT ONE TWO THREE FOUR FIVE SIX)], "the sections order is remembered with correct case");
421
422	is_deeply($read_data->{'__SECTIONS__'}, [qw(:DEFAULT ONE TWO THREE FOUR FIVE SIX)], "the sections order is remembered with correct case");
423
424	my $missing=0;
425	foreach (@{$read_data->{'__SECTIONS__'}}) {
426		$missing++ unless exists ($read_data->{$_});
427	}
428	is ($missing, 0, "All sections in __SECTIONS__ are accessible");
429}
430
431# defaults
432{
433	my $read_data = ReadINI( $filename, {case => 'preserve', withdefaults => 1});
434	ok(ref($read_data), "withdefaults => 1, case => preserve");
435
436	AddDefaults($read_data, 'one', ':default');
437
438	is($read_data->{one}{int}, 1, "found the own value");
439	is($read_data->{one}{foo}, 'dz_difolt', "found a default value");
440	is($read_data->{one}{bar}, undef, "found a missing value");
441}
442
443{
444	my $read_data = ReadINI( $filename, {case => 'preserve', withdefaults => 1});
445	ok(ref($read_data), "withdefaults => 1, case => preserve with custom defaults");
446
447	AddDefaults($read_data, 'one',  {int => 99, foo => 'custom'});
448
449	is($read_data->{one}{int}, 1, "found the own value");
450	is($read_data->{one}{foo}, 'custom', "found a default value");
451	is($read_data->{one}{bar}, undef, "found a missing value");
452}
453
454{
455	my $read_data = ReadINI( $filename, {case => 'toupper', withdefaults => 1});
456	ok(ref($read_data), "withdefaults => 1, case => toupper");
457
458	AddDefaults($read_data, 'ONE', ':DEFAULT');
459
460	is($read_data->{ONE}{INT}, 1, "found the own value");
461	is($read_data->{ONE}{FOO}, 'dz_difolt', "found a default value");
462	is($read_data->{ONE}{BAR}, undef, "found a missing value");
463}
464
465{
466	my $read_data = ReadINI( $filename, {case => 'preserve', sectionorder => 1});
467
468	(my $filename2 = $filename) =~ s/\.ini$/-3.ini/;
469	ok(WriteINI( $filename2, $read_data), "Wrote the ini file with case => preserve, sectionorder => 1");
470	END {unlink $filename2};
471
472	my $read_data2 = ReadINI( $filename2, {case => 'preserve', sectionorder => 1});
473
474	is_deeply( $read_data2, $read_data, "Still have the same data")
475}
476
477{
478	my $read_data = ReadINI( $filename, {case => 'tolower', sectionorder => 1});
479
480	(my $filename2 = $filename) =~ s/\.ini$/-3.ini/;
481	ok(WriteINI( $filename2, $read_data), "Wrote the ini file with case => tolower, sectionorder => 1");
482
483	my $read_data2 = ReadINI( $filename2, {case => 'preserve', sectionorder => 1});
484
485	is_deeply( $read_data2, $read_data, "Still have the same data")
486}
487
488{
489	my $read_data = ReadINI( $filename, {case => 'toupper', sectionorder => 1});
490
491	(my $filename2 = $filename) =~ s/\.ini$/-3.ini/;
492	ok(WriteINI( $filename2, $read_data), "Wrote the ini file with case => toupper, sectionorder => 1");
493
494	my $read_data2 = ReadINI( $filename2, {case => 'preserve', sectionorder => 1});
495
496	is_deeply( $read_data2, $read_data, "Still have the same data")
497}
498
499{
500	my $read_data = ReadINI( $filename, {case => 'lower', sectionorder => 1});
501
502	(my $filename2 = $filename) =~ s/\.ini$/-3.ini/;
503	ok(WriteINI( $filename2, $read_data), "Wrote the ini file with case => lower, sectionorder => 1");
504
505	my $read_data2 = ReadINI( $filename2, {case => 'preserve', sectionorder => 1});
506
507	is_deeply( $read_data2, $read_data, "Still have the same data")
508}
509
510{
511	my $read_data = ReadINI( $filename, {case => 'upper', sectionorder => 1});
512
513	(my $filename2 = $filename) =~ s/\.ini$/-3.ini/;
514	ok(WriteINI( $filename2, $read_data), "Wrote the ini file with case => upper, sectionorder => 1");
515
516	my $read_data2 = ReadINI( $filename2, {case => 'preserve', sectionorder => 1});
517
518	is_deeply( $read_data2, $read_data, "Still have the same data")
519}
520
521{
522	my $read_data = ReadINI( $filename, {case => 'preserve', sectionorder => 1});
523
524	(my $filename2 = $filename) =~ s/\.ini$/-3.ini/;
525	ok(WriteINI( $filename2, $read_data), "Wrote the ini file with case => preserve, sectionorder => 1");
526
527	my $read_data2 = ReadINI( $filename2, {case => 'preserve', sectionorder => 1});
528
529	is_deeply( $read_data2, $read_data, "Still have the same data")
530}
531
532{
533	my $read_data = ReadINI( $filename, {case => 'preserve', sectionorder => 0});
534
535	(my $filename2 = $filename) =~ s/\.ini$/-3.ini/;
536	ok(WriteINI( $filename2, $read_data), "Wrote the ini file with case => preserve, sectionorder => 0");
537
538	my $read_data2 = ReadINI( $filename2, {case => 'preserve', sectionorder => 0});
539
540	is_deeply( $read_data2, $read_data, "Still have the same data")
541}
542
543{
544	my $read_data = ReadINI( $filename, {sectionorder => 1, case => 'lower', class => 'Hash::Case::Lower'});
545
546	is($read_data->{Three}{AAAA}, 'asd', "Hash::Case::Lower");
547	is($read_data->{three}{AAAA}, 'asd', "Hash::Case::Lower");
548	is($read_data->{THREE}{AAAA}, 'asd', "Hash::Case::Lower");
549
550	is($read_data->{THREE}{aaaa}, 'asd', "Hash::Case::Lower");
551	is($read_data->{THREE}{Bbbb}, 'asd', "Hash::Case::Lower");
552	is($read_data->{THREE}{CCCC}, 'asd', "Hash::Case::Lower");
553
554	is($read_data->{THREE}{aaaa}, 'asd', "Hash::Case::Lower");
555	is($read_data->{THREE}{bbbb}, 'asd', "Hash::Case::Lower");
556	is($read_data->{THREE}{cccc}, 'asd', "Hash::Case::Lower");
557
558	is($read_data->{THREE}{AAAA}, 'asd', "Hash::Case::Lower");
559	is($read_data->{THREE}{BBBB}, 'asd', "Hash::Case::Lower");
560	is($read_data->{THREE}{CCCC}, 'asd', "Hash::Case::Lower");
561
562	my %keys; @keys{keys %$read_data} = ();
563	is_deeply(\%keys, {map {$_ => undef} qw(:default one two three four five six __sections__)}, "the sections are remembered with correct case");
564
565	is_deeply($read_data->{'__SECTIONS__'}, [qw(:default one two three four five six)], "the sections order is remembered with correct case");
566
567	my $missing=0;
568	foreach (@{$read_data->{'__SECTIONS__'}}) {
569		$missing++ unless exists ($read_data->{$_});
570	}
571	is ($missing, 0, "All sections in __SECTIONS__ are accessible");
572}
573
574{
575	my $read_data = ReadINI( $filename, {sectionorder => 1, case => 'preserve', class => 'Hash::Case::Lower'});
576
577	is($read_data->{Three}{AAAA}, 'asd', "Hash::Case::Lower");
578	is($read_data->{three}{AAAA}, 'asd', "Hash::Case::Lower");
579	is($read_data->{THREE}{AAAA}, 'asd', "Hash::Case::Lower");
580
581	is($read_data->{THREE}{aaaa}, 'asd', "Hash::Case::Lower");
582	is($read_data->{THREE}{Bbbb}, 'asd', "Hash::Case::Lower");
583	is($read_data->{THREE}{CCCC}, 'asd', "Hash::Case::Lower");
584
585	is($read_data->{THREE}{aaaa}, 'asd', "Hash::Case::Lower");
586	is($read_data->{THREE}{bbbb}, 'asd', "Hash::Case::Lower");
587	is($read_data->{THREE}{cccc}, 'asd', "Hash::Case::Lower");
588
589	is($read_data->{THREE}{AAAA}, 'asd', "Hash::Case::Lower");
590	is($read_data->{THREE}{BBBB}, 'asd', "Hash::Case::Lower");
591	is($read_data->{THREE}{CCCC}, 'asd', "Hash::Case::Lower");
592
593	my %keys; @keys{keys %$read_data} = ();
594	is_deeply(\%keys, {map {$_ => undef} qw(:default one two three four five six __sections__)}, "the sections are remembered with correct case");
595
596	is_deeply($read_data->{'__SECTIONS__'}, [qw(:default one Two Three Four Five Six)], "the sections order is remembered with correct case");
597
598	my $missing=0;
599	foreach (@{$read_data->{'__SECTIONS__'}}) {
600		$missing++ unless exists ($read_data->{$_});
601	}
602	is ($missing, 0, "All sections in __SECTIONS__ are accessible");
603}
604