Commit | Line | Data |
---|---|---|
3bd791fa JK |
1 | #!./perl -w |
2 | # t/quotekeys.t - Test Quotekeys() | |
3 | ||
4 | BEGIN { | |
5 | if ($ENV{PERL_CORE}){ | |
6 | require Config; import Config; | |
7 | no warnings 'once'; | |
8 | if ($Config{'extensions'} !~ /\bData\/Dumper\b/) { | |
9 | print "1..0 # Skip: Data::Dumper was not built\n"; | |
10 | exit 0; | |
11 | } | |
12 | } | |
13 | } | |
14 | ||
15 | use strict; | |
16 | ||
17 | use Data::Dumper; | |
18 | use Test::More tests => 10; | |
19 | use lib qw( ./t/lib ); | |
20 | use Testing qw( _dumptostr ); | |
21 | ||
22 | my %d = ( | |
23 | delta => 'd', | |
24 | beta => 'b', | |
25 | gamma => 'c', | |
26 | alpha => 'a', | |
27 | ); | |
28 | ||
29 | { | |
30 | my ($obj, %dumps, $quotekeys, $starting); | |
31 | ||
32 | note("\$Data::Dumper::Quotekeys and Quotekeys() set to true value"); | |
33 | note("XS implementation"); | |
34 | $Data::Dumper::Useperl = 0; | |
35 | ||
36 | $obj = Data::Dumper->new( [ \%d ] ); | |
37 | $dumps{'ddqkdefault'} = _dumptostr($obj); | |
38 | ||
39 | $starting = $Data::Dumper::Quotekeys; | |
40 | $quotekeys = 1; | |
41 | local $Data::Dumper::Quotekeys = $quotekeys; | |
42 | $obj = Data::Dumper->new( [ \%d ] ); | |
43 | $dumps{'ddqkone'} = _dumptostr($obj); | |
44 | local $Data::Dumper::Quotekeys = $starting; | |
45 | ||
46 | $obj = Data::Dumper->new( [ \%d ] ); | |
47 | $obj->Quotekeys($quotekeys); | |
48 | $dumps{'objqkone'} = _dumptostr($obj); | |
49 | ||
50 | is($dumps{'ddqkdefault'}, $dumps{'ddqkone'}, | |
51 | "\$Data::Dumper::Quotekeys = 1 is default"); | |
52 | is($dumps{'ddqkone'}, $dumps{'objqkone'}, | |
53 | "\$Data::Dumper::Quotekeys = 1 and Quotekeys(1) are equivalent"); | |
54 | %dumps = (); | |
55 | ||
56 | $quotekeys = 0; | |
57 | local $Data::Dumper::Quotekeys = $quotekeys; | |
58 | $obj = Data::Dumper->new( [ \%d ] ); | |
59 | $dumps{'ddqkzero'} = _dumptostr($obj); | |
60 | local $Data::Dumper::Quotekeys = $starting; | |
61 | ||
62 | $obj = Data::Dumper->new( [ \%d ] ); | |
63 | $obj->Quotekeys($quotekeys); | |
64 | $dumps{'objqkzero'} = _dumptostr($obj); | |
65 | ||
66 | is($dumps{'ddqkzero'}, $dumps{'objqkzero'}, | |
67 | "\$Data::Dumper::Quotekeys = 0 and Quotekeys(0) are equivalent"); | |
68 | ||
69 | $quotekeys = undef; | |
70 | local $Data::Dumper::Quotekeys = $quotekeys; | |
71 | $obj = Data::Dumper->new( [ \%d ] ); | |
72 | $dumps{'ddqkundef'} = _dumptostr($obj); | |
73 | local $Data::Dumper::Quotekeys = $starting; | |
74 | ||
75 | $obj = Data::Dumper->new( [ \%d ] ); | |
76 | $obj->Quotekeys($quotekeys); | |
77 | $dumps{'objqkundef'} = _dumptostr($obj); | |
78 | ||
79 | note("Quotekeys(undef) will fall back to the default value\nfor \$Data::Dumper::Quotekeys, which is a true value."); | |
80 | isnt($dumps{'ddqkundef'}, $dumps{'objqkundef'}, | |
81 | "\$Data::Dumper::Quotekeys = undef and Quotekeys(undef) are equivalent"); | |
82 | isnt($dumps{'ddqkzero'}, $dumps{'objqkundef'}, | |
83 | "\$Data::Dumper::Quotekeys = undef and = 0 are equivalent"); | |
84 | %dumps = (); | |
85 | ||
86 | note("Perl implementation"); | |
87 | $Data::Dumper::Useperl = 1; | |
88 | ||
89 | $obj = Data::Dumper->new( [ \%d ] ); | |
90 | $dumps{'ddqkdefault'} = _dumptostr($obj); | |
91 | ||
92 | $starting = $Data::Dumper::Quotekeys; | |
93 | $quotekeys = 1; | |
94 | local $Data::Dumper::Quotekeys = $quotekeys; | |
95 | $obj = Data::Dumper->new( [ \%d ] ); | |
96 | $dumps{'ddqkone'} = _dumptostr($obj); | |
97 | local $Data::Dumper::Quotekeys = $starting; | |
98 | ||
99 | $obj = Data::Dumper->new( [ \%d ] ); | |
100 | $obj->Quotekeys($quotekeys); | |
101 | $dumps{'objqkone'} = _dumptostr($obj); | |
102 | ||
103 | is($dumps{'ddqkundef'}, $dumps{'objqkundef'}, | |
104 | "\$Data::Dumper::Quotekeys = undef and Quotekeys(undef) are equivalent"); | |
105 | is($dumps{'ddqkone'}, $dumps{'objqkone'}, | |
106 | "\$Data::Dumper::Quotekeys = 1 and Quotekeys(1) are equivalent"); | |
107 | %dumps = (); | |
108 | ||
109 | $quotekeys = 0; | |
110 | local $Data::Dumper::Quotekeys = $quotekeys; | |
111 | $obj = Data::Dumper->new( [ \%d ] ); | |
112 | $dumps{'ddqkzero'} = _dumptostr($obj); | |
113 | local $Data::Dumper::Quotekeys = $starting; | |
114 | ||
115 | $obj = Data::Dumper->new( [ \%d ] ); | |
116 | $obj->Quotekeys($quotekeys); | |
117 | $dumps{'objqkzero'} = _dumptostr($obj); | |
118 | ||
119 | is($dumps{'ddqkzero'}, $dumps{'objqkzero'}, | |
120 | "\$Data::Dumper::Quotekeys = 0 and Quotekeys(0) are equivalent"); | |
121 | ||
122 | $quotekeys = undef; | |
123 | local $Data::Dumper::Quotekeys = $quotekeys; | |
124 | $obj = Data::Dumper->new( [ \%d ] ); | |
125 | $dumps{'ddqkundef'} = _dumptostr($obj); | |
126 | local $Data::Dumper::Quotekeys = $starting; | |
127 | ||
128 | $obj = Data::Dumper->new( [ \%d ] ); | |
129 | $obj->Quotekeys($quotekeys); | |
130 | $dumps{'objqkundef'} = _dumptostr($obj); | |
131 | ||
132 | note("Quotekeys(undef) will fall back to the default value\nfor \$Data::Dumper::Quotekeys, which is a true value."); | |
133 | isnt($dumps{'ddqkundef'}, $dumps{'objqkundef'}, | |
134 | "\$Data::Dumper::Quotekeys = undef and Quotekeys(undef) are equivalent"); | |
135 | isnt($dumps{'ddqkzero'}, $dumps{'objqkundef'}, | |
136 | "\$Data::Dumper::Quotekeys = undef and = 0 are equivalent"); | |
137 | %dumps = (); | |
138 | } | |
139 |