t/tags.t: Test that Document Type Declaration (DTD or doctype) works
[catagits/Web-Simple.git] / t / tags.t
1 use strict; use warnings FATAL => 'all';
2 use Test::More qw(no_plan);
3
4 {
5
6   package Foo;
7
8   sub foo {
9     use XML::Tags qw(one two three);
10     <one>, <two>, <three>;
11   }
12
13   sub bar {
14     no warnings 'once'; # this is supposed to warn, it's broken
15     <one>
16   }
17
18   sub baz {
19     use XML::Tags qw(bar);
20     </bar>;
21   }
22
23   sub quux {
24     use HTML::Tags;
25     <html>, <body id="spoon">, "YAY", </body>, </html>;
26   }
27
28   sub fleem {
29     use XML::Tags qw(woo);
30     my $ent = "one&two";
31     <woo ent="$ent">;
32   }
33
34   sub flaax {
35     use XML::Tags qw(woo);
36     my $data = "one&two<three>four";
37     <woo>,  $data, </woo>,
38     <woo>, \$data, </woo>;
39   }
40
41   sub PI {
42     use XML::Tags;
43     <?xml version="1.0" encoding="UTF-8"?>;
44   }
45
46   sub DTD {
47     use HTML::Tags;
48     <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
49   }
50
51   sub globbery {
52     <t/globbery/*>;
53   }
54 }
55
56 is(
57   join(', ', XML::Tags::to_xml_string Foo::foo()),
58   '<one>, <two>, <three>',
59   'open tags ok'
60 );
61
62 ok(!eval { Foo::bar(); 1 }, 'Death on use of unimported tag');
63
64 is(
65   join(', ', XML::Tags::to_xml_string Foo::baz()),
66   '</bar>',
67   'close tag ok'
68 );
69
70 is(
71   join('', HTML::Tags::to_html_string Foo::quux),
72   '<html><body id="spoon">YAY</body></html>',
73   'HTML tags ok'
74 );
75
76 is(
77   join('', XML::Tags::to_xml_string Foo::fleem),
78   '<woo ent="one&amp;two">',
79   'Escaping ok'
80 );
81
82 is(
83   join('', XML::Tags::to_xml_string Foo::flaax),
84   '<woo>one&amp;two&lt;three&gt;four</woo><woo>one&two<three>four</woo>',
85   'Escaping user data ok'
86 );
87
88 is(
89   join('', XML::Tags::to_xml_string Foo::PI),
90   '<?xml version="1.0" encoding="UTF-8"?>',
91   'XML processing instruction'
92 );
93
94 is(
95   join('', HTML::Tags::to_html_string Foo::DTD),
96   '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">',
97   'DTD ok'
98 );
99
100 is(
101   join(', ', Foo::globbery),
102   't/globbery/one, t/globbery/two',
103   'real glob re-installed ok'
104 );