]> Dogcows Code - chaz/p5-CGI-Ex/blob - t/3_conf_00_base.t
31591c00d33cf26c1fb6a42b916b58ced1bb554c
[chaz/p5-CGI-Ex] / t / 3_conf_00_base.t
1 # -*- Mode: Perl; -*-
2
3 use Test;
4
5 BEGIN {plan tests => 24};
6
7 use CGI::Ex::Conf;
8 ok(1);
9
10 my $dir = $0;
11 $dir =~ tr|\\|/|; # should probably use File::Spec
12 $dir =~ s|/[^/]+$||;
13 $dir = '.' if ! length $dir;
14 $dir .= '/samples';
15 my $obj = CGI::Ex::Conf->new({
16 paths => ["$dir/conf_path_1", "$dir/conf_path_3"],
17 });
18
19 ### most test for the reading of files
20 ### are actually performed in the validation tests
21
22 ok($obj);
23
24 my $hash = $obj->read('apples.pl');
25 ok($hash);
26 ok($hash->{quantity});
27
28 $hash = $obj->read('apples.pl');
29 ok($hash);
30 ok($hash->{quantity});
31
32
33 local $CGI::Ex::Conf::DIRECTIVE = 'FIRST';
34 $hash = $obj->read('apples.pl');
35 ok($hash);
36 ok($hash->{quantity} == 20);
37 ok($hash->{foo} eq 'file1');
38
39 local $CGI::Ex::Conf::DIRECTIVE = 'LAST';
40 $hash = $obj->read('apples.pl');
41 ok($hash);
42 ok($hash->{quantity} == 30);
43 ok($hash->{foo} eq 'file2');
44
45 $hash = $obj->read('apples.pl', {directive => 'MERGE'});
46 ok($hash);
47 ok($hash->{quantity} == 30);
48 ok($hash->{foo} eq 'file1'); # has immutable value
49
50
51 local $obj->{directive} = 'FIRST';
52 $hash = $obj->read('oranges.pl');
53 ok($hash);
54 ok($hash->{quantity} == 20);
55 ok($hash->{foo} eq 'file1');
56
57 local $obj->{directive} = 'LAST';
58 $hash = $obj->read('oranges.pl');
59 ok($hash);
60 ok($hash->{quantity} == 30);
61 ok($hash->{foo} eq 'file2');
62
63 local $obj->{directive} = 'MERGE';
64 $hash = $obj->read('oranges.pl');
65 ok($hash);
66 ok($hash->{quantity} == 20); # has immutable key so all values are immutable
67 ok($hash->{foo} eq 'file1'); # has immutable key so all values are immutable
68
69
This page took 0.03085 seconds and 3 git commands to generate.