1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
#!./perl -w
#
# test for $Data::Dumper::Pair AKA Data::Dumper->new([ ... ])->Pair('...')
#
BEGIN {
if ($ENV{PERL_CORE}){
require Config; import Config;
no warnings 'once';
if ($Config{'extensions'} !~ /\bData\/Dumper\b/) {
print "1..0 # Skip: Data::Dumper was not built\n";
exit 0;
}
}
}
use strict;
our ($want_colon, $want_comma);
use Test::More tests => 9;
no warnings qw(once);
require_ok 'Data::Dumper';
my $HASH = { alpha => 'beta', gamma => 'vlissides' };
my $WANT = q({'alpha' => 'beta','gamma' => 'vlissides'});
$Data::Dumper::Useperl = 1;
$Data::Dumper::Indent = 0;
$Data::Dumper::Terse = 1;
$Data::Dumper::Sortkeys = 1;
$want_colon = $want_comma = $WANT;
$want_colon =~ s/=>/:/g;
$want_comma =~ s/ => /,/g;
####################### XS Tests #####################
SKIP: {
skip 'XS extension not loaded', 3 unless (defined &Data::Dumper::Dumpxs);
is (Data::Dumper::DumperX($HASH), $WANT,
'XS: Default hash key/value separator: " => "');
local $Data::Dumper::Pair = ' : ';
is (Data::Dumper::DumperX($HASH), $want_colon, 'XS: $Data::Dumper::Pair = " : "');
my $dd = Data::Dumper->new([ $HASH ])->Pair(',');
is ($dd->Dumpxs(), $want_comma,
'XS: Data::Dumper->new([ $HASH ])->Pair(",")->Dumpxs()');
};
###################### Perl Tests ####################
{
is ($Data::Dumper::Pair, ' => ', 'Perl: $Data::Dumper::Pair eq " => "');
is (Data::Dumper::Dumper($HASH), $WANT,
'Perl: Default hash key/value separator: " => "');
local $Data::Dumper::Pair = ' : ';
is (Data::Dumper::Dumper($HASH), $want_colon, 'Perl: $Data::Dumper::Pair = " : "');
my $dd = Data::Dumper->new([ $HASH ])->Pair(',');
is ($dd->Pair(), ',',
'Perl: Data::Dumper->new([ $HASH ])->Pair(",")->Pair() eq ","');
is ($dd->Dump(), $want_comma, 'Perl: Data::Dumper->new([ $HASH ])->Pair(",")->Dump()');
}
|