This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #120635] don't leak semaphores
[perl5.git] / dist / Data-Dumper / t / quotekeys.t
CommitLineData
3bd791fa
JK
1#!./perl -w
2# t/quotekeys.t - Test Quotekeys()
3
4BEGIN {
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
15use strict;
16
17use Data::Dumper;
18use Test::More tests => 10;
19use lib qw( ./t/lib );
20use Testing qw( _dumptostr );
21
22my %d = (
23 delta => 'd',
24 beta => 'b',
25 gamma => 'c',
26 alpha => 'a',
27);
28
ed960e77
S
29run_tests_for_quotekeys();
30SKIP: {
31 skip "XS version was unavailable, so we already ran with pure Perl", 5
32 if $Data::Dumper::Useperl;
33 local $Data::Dumper::Useperl = 1;
34 run_tests_for_quotekeys();
35}
36
37sub run_tests_for_quotekeys {
38 note("\$Data::Dumper::Useperl = $Data::Dumper::Useperl");
39
3bd791fa
JK
40 my ($obj, %dumps, $quotekeys, $starting);
41
42 note("\$Data::Dumper::Quotekeys and Quotekeys() set to true value");
3bd791fa
JK
43
44 $obj = Data::Dumper->new( [ \%d ] );
45 $dumps{'ddqkdefault'} = _dumptostr($obj);
46
47 $starting = $Data::Dumper::Quotekeys;
48 $quotekeys = 1;
49 local $Data::Dumper::Quotekeys = $quotekeys;
50 $obj = Data::Dumper->new( [ \%d ] );
51 $dumps{'ddqkone'} = _dumptostr($obj);
52 local $Data::Dumper::Quotekeys = $starting;
53
54 $obj = Data::Dumper->new( [ \%d ] );
55 $obj->Quotekeys($quotekeys);
56 $dumps{'objqkone'} = _dumptostr($obj);
57
58 is($dumps{'ddqkdefault'}, $dumps{'ddqkone'},
59 "\$Data::Dumper::Quotekeys = 1 is default");
60 is($dumps{'ddqkone'}, $dumps{'objqkone'},
61 "\$Data::Dumper::Quotekeys = 1 and Quotekeys(1) are equivalent");
62 %dumps = ();
63
64 $quotekeys = 0;
65 local $Data::Dumper::Quotekeys = $quotekeys;
66 $obj = Data::Dumper->new( [ \%d ] );
67 $dumps{'ddqkzero'} = _dumptostr($obj);
3bd791fa
JK
68 local $Data::Dumper::Quotekeys = $starting;
69
70 $obj = Data::Dumper->new( [ \%d ] );
71 $obj->Quotekeys($quotekeys);
72 $dumps{'objqkzero'} = _dumptostr($obj);
73
74 is($dumps{'ddqkzero'}, $dumps{'objqkzero'},
75 "\$Data::Dumper::Quotekeys = 0 and Quotekeys(0) are equivalent");
76
77 $quotekeys = undef;
78 local $Data::Dumper::Quotekeys = $quotekeys;
79 $obj = Data::Dumper->new( [ \%d ] );
80 $dumps{'ddqkundef'} = _dumptostr($obj);
81 local $Data::Dumper::Quotekeys = $starting;
82
83 $obj = Data::Dumper->new( [ \%d ] );
84 $obj->Quotekeys($quotekeys);
85 $dumps{'objqkundef'} = _dumptostr($obj);
86
87 note("Quotekeys(undef) will fall back to the default value\nfor \$Data::Dumper::Quotekeys, which is a true value.");
88 isnt($dumps{'ddqkundef'}, $dumps{'objqkundef'},
89 "\$Data::Dumper::Quotekeys = undef and Quotekeys(undef) are equivalent");
90 isnt($dumps{'ddqkzero'}, $dumps{'objqkundef'},
91 "\$Data::Dumper::Quotekeys = undef and = 0 are equivalent");
92 %dumps = ();
93}
94