File: 003-ref.t

package info (click to toggle)
libdata-printer-perl 1.002001-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 748 kB
  • sloc: perl: 4,364; makefile: 7; sh: 1
file content (36 lines) | stat: -rw-r--r-- 1,040 bytes parent folder | download | duplicates (3)
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
use strict;
use warnings;
use Test::More tests => 7;
use Data::Printer::Object;

my $ddp = Data::Printer::Object->new( colored => 0, show_readonly => 0 );
my $data = "test";
my $ref  = \$data;
my $ref2ref = \$ref;
my $res = $ddp->parse(\$ref2ref);
is $res, q(\\ \\ "test"), 'reference to reference to scalar';

my $doublecheck = $ddp->parse(\$ref2ref);
is $doublecheck, $res, 'checking again gives the same result (previously seen addresses)';

$ddp = Data::Printer::Object->new( colored => 0, show_readonly => 0 );
$res = $ddp->parse(\\$ref2ref);
is $res, q(\\ \\ \\ "test"), 'ref2ref2ref2scalar';

my $x = [];
my $y = $x;
Scalar::Util::weaken($y);
is $ddp->parse($x), '[]', 'regular array ref';
is $ddp->parse($y), '[] (weak)', 'weak array ref';
$x->[0] = $x;
Scalar::Util::weaken($x->[0]);
is $ddp->parse($x), '[
    [0] var (weak)
]', 'circular array';

my $array_of_refs = [\1, \2];
$res = $ddp->parse($array_of_refs);
is $res, '[
    [0] \ 1,
    [1] \ 2
]', 'proper results when 2 references present on the same array (regression)';