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 63
|
use strict;
use Test::More 0.96;
use Pandoc::Elements;
use Scalar::Util qw[ blessed reftype ];
my $document = do {
local (@ARGV, $/) = ('t/documents/meta.json');
pandoc_json(<>);
};
isa_ok $document, 'Pandoc::Document', "it's a document" or note ref $document;
my $unblessed_counts = bless_check_loop($document->meta);
ok !keys(%$unblessed_counts), 'no unblessed metadata objects'
or note "There were some unblessed metadata objects:\n", explain $unblessed_counts;
my $undef_count = undef_check_loop( $document->meta );
ok !$undef_count, 'no undef values' or note "There were $undef_count undefined values";
sub bless_check_loop {
my @data = @_;
my %counts;
LOOP:
for ( my $i = 0; $i <= @data; $i++ ) {
my $item = $data[$i];
next LOOP unless reftype $item;
if ( 'ARRAY' eq reftype $item ) {
push @data, grep { reftype $_ } @$item;
}
elsif ( 'HASH' eq reftype $item ) {
if ( $item->{t} ) {
++$counts{$item->{t}} unless blessed $item;
}
push @data, grep { reftype $_ } values %$item;
}
}
return \%counts;
}
sub undef_check_loop {
my @data = @_;
my $count;
LOOP:
for ( my $i = 0; $i <= @data; $i++ ) {
my $item = $data[$i];
next LOOP unless reftype $item;
if ( 'ARRAY' eq reftype $item ) {
$count += grep { !defined($_) } @$item;
push @data, grep { reftype $_ } @$item;
}
elsif ( 'HASH' eq reftype $item ) {
$count += grep { !defined($_) } values %$item;
push @data, grep { reftype $_ } values %$item;
}
}
return $count;
}
done_testing;
__DATA__
|