Data-Peek

 view release on metacpan or  search on metacpan

t/11_DDumper.t  view on Meta::CPAN

#!/usr/bin/perl

use strict;
use warnings;

use Test::More;
use Test::Warnings;

BEGIN {
    eval q{use Perl::Tidy};
    # Version is also checked in Peek.pm
    if ($@ || $Perl::Tidy::VERSION <= 20120714) {
	diag "A usable Perl::Tidy is not available";
	done_testing;
	exit 0;
	}
    use_ok ("Data::Peek", ":tidy");
    die "Cannot load Data::Peek\n" if $@;
    }

my ($dump, $var) = ("", "");
while (<DATA>) {
    chomp;
    my ($v, $exp, $re) = split m/\t+ */;

    if ($v eq "--") {
	ok (1, "** $exp");
	next;
	}

    $v =~ s/^S:([^:]*):// and DDsort ($1), $v =~ m/^()/; # And reset $1 for below

    unless ($v eq "") {
	eval "\$var = $v";
	ok ($dump = DDumper ($var),	"DDumper ($v)");
	$dump =~ s/\A\$VAR1 = //;
	$dump =~ s/;?\n\Z//;
	}
    if ($re) {
	like ($dump, qr{$exp}ms,	".. content $re");
	$1 and diag "# '$1' (", length ($1), ")\n";
	}
    else {
	is   ($dump,    $exp,		".. content");
	}
    }
unlink "perltidy.LOG", "perltidy.ERR";

done_testing;

1;

__END__
--	Basic values
undef				undef
1				1
""				''
"\xa8"				'¨'
1.24				'1.24'
\undef				\undef
\1				\1
\""				\''
\"\xa8"				\'¨'
(0, 1)				1
\(0, 1)				\1
--	Structures
[0]				\A\[\s*0\s*]\s*\Z			tidy array 1
[0, 1]				\A\[\s*0\s*,\s*1\s*]\s*\Z		tidy array 2
[0,1,2]				\A\[\s*0\s*,\s*1\s*,\s*2\s*]\s*\Z	tidy array 3
[[0],{foo=>1}]			\A\[\s*\[\s*0\s*]\s*,\s*\{\s*'foo'\s*=>\s*1\s*}\s*]\s*\Z	structure



( run in 0.948 second using v1.01-cache-2.11-cpan-71847e10f99 )