t/tags.t: HTML comments ok
[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 xquux {
29     use HTML::Tags;
30     <link href="#self" rel="me" />,
31     <table>,<tr>,<td>,'x',<sub>,1,</sub>,</td>,</tr>,</table>;
32   }
33
34   sub fleem {
35     use XML::Tags qw(woo);
36     my $ent = 'one&two<three>"four';
37     <woo ent="$ent">;
38   }
39
40   sub flaax {
41     use XML::Tags qw(woo);
42     my $data = "one&two<three>four";
43     <woo>,  $data, </woo>,
44     <woo>, \$data, </woo>;
45   }
46
47   sub HTML_comment {
48     use HTML::Tags;
49     <!-- this is a comment -->;
50   }
51
52   sub PI {
53     use XML::Tags;
54     <?xml version="1.0" encoding="UTF-8"?>;
55   }
56
57   sub DTD {
58     use HTML::Tags;
59     <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
60   }
61
62   sub globbery {
63     <t/globbery/*>;
64   }
65 }
66
67 is(
68   join(', ', XML::Tags::to_xml_string Foo::foo()),
69   '<one>, <two>, <three>',
70   'open tags ok'
71 );
72
73 ok(!eval { Foo::bar(); 1 }, 'Death on use of unimported tag');
74
75 is(
76   join(', ', XML::Tags::to_xml_string Foo::baz()),
77   '</bar>',
78   'close tag ok'
79 );
80
81 is(
82   join('', HTML::Tags::to_html_string Foo::quux),
83   '<html><body id="spoon">YAY</body></html>',
84   'HTML tags ok'
85 );
86
87 is(
88   join('', HTML::Tags::to_html_string Foo::xquux),
89   '<link href="#self" rel="me" />' .
90   '<table><tr><td>x<sub>1</sub></td></tr></table>',
91   'Conflicting HTML tags ok'
92 );
93
94 is(
95   join('', XML::Tags::to_xml_string Foo::HTML_comment),
96   '<!-- this is a comment -->',
97   'HTML comment ok'
98 );
99
100 is(
101   join('', XML::Tags::to_xml_string Foo::fleem),
102   '<woo ent="one&amp;two&lt;three&gt;&quot;four">',
103   'Escaping ok'
104 );
105
106 is(
107   join('', XML::Tags::to_xml_string Foo::flaax),
108   '<woo>one&amp;two&lt;three&gt;four</woo><woo>one&two<three>four</woo>',
109   'Escaping user data ok'
110 );
111
112 is(
113   join('', XML::Tags::to_xml_string Foo::PI),
114   '<?xml version="1.0" encoding="UTF-8"?>',
115   'XML processing instruction'
116 );
117
118 is(
119   join('', HTML::Tags::to_html_string Foo::DTD),
120   '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">',
121   'DTD ok'
122 );
123
124 is(
125   join(', ', Foo::globbery),
126   't/globbery/one, t/globbery/two',
127   'real glob re-installed ok'
128 );