Debian Codegraph @

t/guts.t

raw symbols SCIP
1 use strict;
2 use warnings;
3 use Test::More;
4 use HTML::TreeBuilder::LibXML;
5 use Data::Dumper;
6
7
8 # list context
9 my $tree = HTML::TreeBuilder::LibXML->new_from_content('<header>foo</header><footer>bar</footer>');
10
11 my @guts = $tree->guts;
12 is join('|', map {$_->as_HTML} @guts), '<header>foo</header>|<footer>bar</footer>', 'guts - list context';
13
14
15 # scalar context
16 my $guts = $tree->guts;
17
18 isa_ok $guts->{node}->ownerDocument, 'XML::LibXML::Document';
19 is $guts->as_HTML, '<div><header>foo</header><footer>bar</footer></div>', 'guts - scalar context';
20
21
22 # guts() must return tags from implicit <head> as well
23 my @nodes = HTML::TreeBuilder::LibXML->new_from_content('<title>head tag</title><div>body tag</div>')->guts;
24 is join('|', map {$_->as_HTML} @nodes), '<title>head tag</title>|<div>body tag</div>';
25
26
27 # guts must include text and comments
28 @nodes = HTML::TreeBuilder::LibXML->new_from_content('<title>head tag</title><!-- foo --><div>body tag</div><!-- bar --> some text')->guts;
29 is join('|', map {$_->as_HTML} @nodes), "<title>head tag</title>|<!-- foo -->\n|<div>body tag</div>|<!-- bar -->\n| some text";
30
31 # guts must include DOCTYPE if its not implicit
32 my $html_with_dtd = "<!DOCTYPE html>\n<html><body><header>html5</header></body></html>\n";
33 $guts = HTML::TreeBuilder::LibXML->new_from_content($html_with_dtd)->guts;
34 isa_ok $guts->{node}->ownerDocument->internalSubset, 'XML::LibXML::Dtd', "doctype";
35 is $guts->parent->as_HTML, $html_with_dtd, "document with doctype";
36
37
38
39
40 done_testing;