reinstate the right glob in XML::Tags (RT#120071)
[catagits/Web-Simple.git] / t / tags.t
1 use strict; use warnings FATAL => 'all';
2 use Test::More qw(no_plan);
3
4 my $globbery;
5 BEGIN { $globbery = join(', ', <t/globbery/o* t/globbery/t*>) }
6 {
7
8   package Foo;
9
10   sub foo {
11     use XML::Tags qw(one two three);
12     <one>, <two>, <three>;
13   }
14
15   sub bar {
16     no warnings 'once'; # this is supposed to warn, it's broken
17     <one>
18   }
19
20   sub baz {
21     use XML::Tags qw(bar);
22     </bar>;
23   }
24
25   sub quux {
26     use HTML::Tags;
27     <html>, <body id="spoon">, "YAY", </body>, </html>;
28   }
29
30   sub xquux {
31     use HTML::Tags;
32     <link href="#self" rel="me" />,
33     <table>,<tr>,<td>,'x',<sub>,1,</sub>,</td>,</tr>,</table>;
34   }
35
36   sub fleem {
37     use XML::Tags qw(woo);
38     my $ent = 'one&two<three>"four';
39     <woo ent="$ent">;
40   }
41
42   sub flaax {
43     use XML::Tags qw(woo);
44     my $data = "one&two<three>four";
45     <woo>,  $data, </woo>,
46     <woo>, \$data, </woo>;
47   }
48
49   sub HTML_comment {
50     use HTML::Tags;
51     <!-- this is a comment -->;
52   }
53
54   sub PI {
55     use XML::Tags;
56     <?xml version="1.0" encoding="UTF-8"?>;
57   }
58
59   sub DTD {
60     use HTML::Tags;
61     <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
62   }
63
64   sub globbery {
65     <t/globbery/o* t/globbery/t*>;
66   }
67 }
68
69 is(
70   join(', ', XML::Tags::to_xml_string Foo::foo()),
71   '<one>, <two>, <three>',
72   'open tags ok'
73 );
74
75 ok(!eval { Foo::bar(); 1 }, 'Death on use of unimported tag');
76
77 is(
78   join(', ', XML::Tags::to_xml_string Foo::baz()),
79   '</bar>',
80   'close tag ok'
81 );
82
83 is(
84   join('', HTML::Tags::to_html_string Foo::quux),
85   '<html><body id="spoon">YAY</body></html>',
86   'HTML tags ok'
87 );
88
89 is(
90   join('', HTML::Tags::to_html_string Foo::xquux),
91   '<link href="#self" rel="me" />' .
92   '<table><tr><td>x<sub>1</sub></td></tr></table>',
93   'Conflicting HTML tags ok'
94 );
95
96 is(
97   join('', XML::Tags::to_xml_string Foo::HTML_comment),
98   '<!-- this is a comment -->',
99   'HTML comment ok'
100 );
101
102 is(
103   join('', XML::Tags::to_xml_string Foo::fleem),
104   '<woo ent="one&amp;two&lt;three&gt;&quot;four">',
105   'Escaping ok'
106 );
107
108 is(
109   join('', XML::Tags::to_xml_string Foo::flaax),
110   '<woo>one&amp;two&lt;three&gt;four</woo><woo>one&two<three>four</woo>',
111   'Escaping user data ok'
112 );
113
114 is(
115   join('', XML::Tags::to_xml_string Foo::PI),
116   '<?xml version="1.0" encoding="UTF-8"?>',
117   'XML processing instruction'
118 );
119
120 is(
121   join('', HTML::Tags::to_html_string Foo::DTD),
122   '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">',
123   'DTD ok'
124 );
125
126 is(
127   join(', ', Foo::globbery),
128   $globbery,
129   'real glob re-installed ok'
130 );