throw error on failed new in run_if_script
[catagits/Web-Simple.git] / t / tags.t
CommitLineData
afe60e53 1use strict; use warnings FATAL => 'all';
2use 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 }
cb5717ef 22
23 sub quux {
24 use HTML::Tags;
cc050137 25 <html>, <body id="spoon">, "YAY", </body>, </html>;
cb5717ef 26 }
43a70ddb 27
318343ca 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
0f339458 34 sub fleem {
35 use XML::Tags qw(woo);
be64ff24 36 my $ent = 'one&two<three>"four';
0f339458 37 <woo ent="$ent">;
38 }
39
dc7d4cf0 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 }
9935bd6c 46
9d031ab2 47 sub HTML_comment {
48 use HTML::Tags;
49 <!-- this is a comment -->;
50 }
51
943937da 52 sub PI {
53 use XML::Tags;
54 <?xml version="1.0" encoding="UTF-8"?>;
55 }
56
4882e90f 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
43a70ddb 62 sub globbery {
63 <t/globbery/*>;
64 }
afe60e53 65}
66
67is(
49a6c0b5 68 join(', ', XML::Tags::to_xml_string Foo::foo()),
afe60e53 69 '<one>, <two>, <three>',
70 'open tags ok'
71);
72
73ok(!eval { Foo::bar(); 1 }, 'Death on use of unimported tag');
74
75is(
49a6c0b5 76 join(', ', XML::Tags::to_xml_string Foo::baz()),
afe60e53 77 '</bar>',
78 'close tag ok'
79);
cb5717ef 80
81is(
49a6c0b5 82 join('', HTML::Tags::to_html_string Foo::quux),
cb5717ef 83 '<html><body id="spoon">YAY</body></html>',
84 'HTML tags ok'
85);
43a70ddb 86
87is(
318343ca 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
94is(
9d031ab2 95 join('', XML::Tags::to_xml_string Foo::HTML_comment),
96 '<!-- this is a comment -->',
97 'HTML comment ok'
98);
99
100is(
0f339458 101 join('', XML::Tags::to_xml_string Foo::fleem),
be64ff24 102 '<woo ent="one&amp;two&lt;three&gt;&quot;four">',
0f339458 103 'Escaping ok'
104);
105
106is(
9935bd6c 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
112is(
943937da 113 join('', XML::Tags::to_xml_string Foo::PI),
114 '<?xml version="1.0" encoding="UTF-8"?>',
115 'XML processing instruction'
116);
117
118is(
4882e90f 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
124is(
43a70ddb 125 join(', ', Foo::globbery),
126 't/globbery/one, t/globbery/two',
127 'real glob re-installed ok'
128);