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
|
use strict;
use Test::More;
use XML::Struct qw(readXML simpleXML);
use Scalar::Util qw(reftype);
sub sample { return readXML('t/nested.xml', @_) }
my $simple = sample(simple => 1);
is_deeply sample( simple => 1, depth => -1 ),
$simple, 'simple, depth -1';
is_deeply sample( simple => 1, depth => undef ),
$simple, 'simple, depth undef';
is_deeply sample( simple => 1, depth => 1, deep => 'simple'),
$simple, 'simple, depth overridden by deep';
is_deeply sample( depth => 0, deep => 'simple'),
$simple, 'depth 0, deep simple implies simple';
is_deeply sample( depth => 0, deep => 'simple', root => 1 ),
sample( simple => 1, root => 1), 'depth 0, deep simple, root';
is_deeply sample( simple => 1, depth => 1 )->{foo},
[ [ foo => {}, [ [ 'bar' => {}, [] ] ] ] ],
'simple, depth 1';
is_deeply sample( simple => 1, depth => 2 )->{foo}->{bar},
[ [ bar => {}, [] ] ],
'simple, depth 2';
is_deeply sample( simple => 1, depth => 2, root => 1 )->{nested}->{foo},
[ [ foo => {}, [ [ bar => {}, [] ] ] ] ],
'simple, depth 2, root';
is_deeply sample( simple => 1, depth => 1, root => 1 )->{nested},
readXML('t/nested.xml'), 'simple 1, depth 1, root 1';
ok sample( depth => 0, deep => 'dom' )->isa('XML::LibXML::Element'),
'depth 0, deep dom';
like sample( depth => 0, deep => 'raw' ), qr{^<nested>.+</nested>$}sm,
'depth 0, deep raw';
done_testing;
|