Data-Printer

 view release on metacpan or  search on metacpan

t/009-array.t  view on Meta::CPAN

use strict;
use warnings;
use Test::More tests => 18;
use Data::Printer::Object;
use Scalar::Util ();

my $ddp = Data::Printer::Object->new( colored => 0 );
my @array;

my $res = $ddp->parse(\@array);
is $res, '[]', 'empty array';
push @array, 3.14, 'test', undef;
$ddp = Data::Printer::Object->new( colored => 0 );
$res = $ddp->parse(\@array);
is $res,
'[
    [0] 3.14,
    [1] "test",
    [2] undef
]',
'array with elements';

push @array, \@array;
$ddp = Data::Printer::Object->new( colored => 0 );
$res = $ddp->parse(\@array);
is $res,
'[
    [0] 3.14,
    [1] "test",
    [2] undef,
    [3] var
]',
'array with elements and circular ref';

$ddp = Data::Printer::Object->new( colored => 0 );
Scalar::Util::weaken($array[3]);
$res = $ddp->parse(\@array);
is $res,
'[
    [0] 3.14,
    [1] "test",
    [2] undef,
    [3] var (weak)
]',
'array with elements and WEAK circular ref';

pop @array;

$ddp = Data::Printer::Object->new( colored => 0, indent => 3 );
$res = $ddp->parse(\@array);
is $res,
'[
   [0] 3.14,
   [1] "test",
   [2] undef
]',
'array with indent => 3';

$ddp = Data::Printer::Object->new( colored => 0, end_separator => 1 );
$res = $ddp->parse(\@array);
is $res,
'[
    [0] 3.14,
    [1] "test",
    [2] undef,
]',
'array with end separator';

$ddp = Data::Printer::Object->new( colored => 0, separator => '!!' );
$res = $ddp->parse(\@array);
is $res,
'[
    [0] 3.14!!
    [1] "test"!!
    [2] undef
]',
'array with !! as separator';

$ddp = Data::Printer::Object->new( colored => 0, separator => '!!', end_separator => 1 );
$res = $ddp->parse(\@array);
is $res,
'[
    [0] 3.14!!
    [1] "test"!!
    [2] undef!!
]',
'array with !! as separator and end separator';

$ddp = Data::Printer::Object->new( colored => 0, index => 0 );
$res = $ddp->parse(\@array);
is $res,
'[
    3.14,
    "test",
    undef
]',



( run in 0.825 second using v1.01-cache-2.11-cpan-39bf76dae61 )