t/tags.t: HTML tags which conflict with Perl built-ins 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 PI {
48     use XML::Tags;
49     <?xml version="1.0" encoding="UTF-8"?>;
50   }
51
52   sub DTD {
53     use HTML::Tags;
54     <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
55   }
56
57   sub globbery {
58     <t/globbery/*>;
59   }
60 }
61
62 is(
63   join(', ', XML::Tags::to_xml_string Foo::foo()),
64   '<one>, <two>, <three>',
65   'open tags ok'
66 );
67
68 ok(!eval { Foo::bar(); 1 }, 'Death on use of unimported tag');
69
70 is(
71   join(', ', XML::Tags::to_xml_string Foo::baz()),
72   '</bar>',
73   'close tag ok'
74 );
75
76 is(
77   join('', HTML::Tags::to_html_string Foo::quux),
78   '<html><body id="spoon">YAY</body></html>',
79   'HTML tags ok'
80 );
81
82 is(
83   join('', HTML::Tags::to_html_string Foo::xquux),
84   '<link href="#self" rel="me" />' .
85   '<table><tr><td>x<sub>1</sub></td></tr></table>',
86   'Conflicting HTML tags ok'
87 );
88
89 is(
90   join('', XML::Tags::to_xml_string Foo::fleem),
91   '<woo ent="one&amp;two&lt;three&gt;&quot;four">',
92   'Escaping ok'
93 );
94
95 is(
96   join('', XML::Tags::to_xml_string Foo::flaax),
97   '<woo>one&amp;two&lt;three&gt;four</woo><woo>one&two<three>four</woo>',
98   'Escaping user data ok'
99 );
100
101 is(
102   join('', XML::Tags::to_xml_string Foo::PI),
103   '<?xml version="1.0" encoding="UTF-8"?>',
104   'XML processing instruction'
105 );
106
107 is(
108   join('', HTML::Tags::to_html_string Foo::DTD),
109   '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">',
110   'DTD ok'
111 );
112
113 is(
114   join(', ', Foo::globbery),
115   't/globbery/one, t/globbery/two',
116   'real glob re-installed ok'
117 );