File: parent.t

package info (click to toggle)
libhtml-treebuilder-libxml-perl 0.28-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 264 kB
  • sloc: perl: 533; makefile: 2; sh: 1
file content (42 lines) | stat: -rw-r--r-- 1,135 bytes parent folder | download | duplicates (5)
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
use strict;
use warnings;
use Test::More;
use Test::Exception;
use HTML::TreeBuilder::LibXML;
use HTML::TreeBuilder::LibXML::Node;
use Data::Dumper;

my $tree = HTML::TreeBuilder::LibXML->new_from_content('<div>foo</div>');
my ($div) = $tree->guts;


# get parent
isa_ok $div->parent, 'HTML::TreeBuilder::LibXML::Node', 'parent()';
is $div->parent->as_HTML, '<body><div>foo</div></body>', 'parent()->as_HTML';

# unset parent
$div->parent(undef);
is $div->parent, undef;

# set parent
dies_ok { $div->parent($div) } "can't set itself as parent";

# set a doc as parent
my $doc = HTML::TreeBuilder::LibXML::Node->new(XML::LibXML->createDocument);
$tree = HTML::TreeBuilder::LibXML->new_from_content('<div>foo</div>');
($div) = $tree->guts;

$div->parent($doc);
is $doc->as_HTML, "<div>foo</div>\n", 'set a doc as parent';

# set a doc with child as parent
$tree = HTML::TreeBuilder::LibXML->new_from_content('<div>foo</div><div>bar</div>');
my ($div_foo, $div_bar) = $tree->guts(1);
$div_foo->parent($div_bar->parent);
is $div_foo->parent->as_HTML, "<div>bar</div><div>foo</div>\n", 'set a doc with child as parent';





done_testing;