File: 01basic.t

package info (click to toggle)
libhtml-html5-writer-perl 0.201-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 364 kB
  • sloc: perl: 3,777; makefile: 2; sh: 1
file content (71 lines) | stat: -rw-r--r-- 1,713 bytes parent folder | download | duplicates (6)
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
64
65
66
67
68
69
70
71
use utf8;

use Test::More tests => 3;
BEGIN { use_ok('HTML::HTML5::Writer') };
use XML::LibXML;

my $input = <<INPUT;
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>foo</title>
<style type="text/css"><![CDATA[
p { foo: "€"; }
]]></style>
</head><body><br foo="nar" />
<!-- ffooo-->
<p quux="xyzzy" bim='"' bum="/bat/" hidden="">foo &amp; €</p><p>foo</p>
<table>
<thead>
<tr><th></th><th>
</th></tr></thead>
<tbody><tr><th></th><td>
</td></tr></tbody><tbody><tr><th></th><td>
</td></tr></tbody></table>
</body></html>
INPUT

my $parser = XML::LibXML->new;
my $dom    = $parser->parse_string($input);

my $hwriter = HTML::HTML5::Writer->new(
	markup   => 'html',
);
my $xwriter = HTML::HTML5::Writer->new(
	markup   => 'xhtml',
	polyglot => 0,
	doctype  => HTML::HTML5::Writer::DOCTYPE_XHTML1,
);

is($hwriter->document($dom), <<HTML, 'HTML output');
<!DOCTYPE html><title>foo</title>
<style type="text/css">
p { foo: "€"; }
</style>
<br foo=nar>
<!-- ffooo-->
<p bim='"' bum="/bat/" hidden quux=xyzzy>foo &amp; €<p>foo</p>
<table>
<thead>
<tr><th><th>
</thead>
<tbody><tr><th><td>
<tr><th><td>
</table>
HTML

is($xwriter->document($dom)."\n", <<XHTML, 'XHTML output');
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>foo</title>
<style type="text/css"><![CDATA[
p { foo: "€"; }
]]></style>
</head><body><br foo="nar" />
<!-- ffooo-->
<p bim='"' bum="/bat/" hidden="" quux="xyzzy">foo &amp; €</p><p>foo</p>
<table>
<thead>
<tr><th></th><th>
</th></tr></thead>
<tbody><tr><th></th><td>
</td></tr></tbody><tbody><tr><th></th><td>
</td></tr></tbody></table>
</body></html>
XHTML