t/tags.t: Test that XML processing instruction (<?xml ... ?>) works
[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
0f339458 28 sub fleem {
29 use XML::Tags qw(woo);
30 my $ent = "one&two";
31 <woo ent="$ent">;
32 }
33
dc7d4cf0 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 }
9935bd6c 40
943937da 41 sub PI {
42 use XML::Tags;
43 <?xml version="1.0" encoding="UTF-8"?>;
44 }
45
43a70ddb 46 sub globbery {
47 <t/globbery/*>;
48 }
afe60e53 49}
50
51is(
49a6c0b5 52 join(', ', XML::Tags::to_xml_string Foo::foo()),
afe60e53 53 '<one>, <two>, <three>',
54 'open tags ok'
55);
56
57ok(!eval { Foo::bar(); 1 }, 'Death on use of unimported tag');
58
59is(
49a6c0b5 60 join(', ', XML::Tags::to_xml_string Foo::baz()),
afe60e53 61 '</bar>',
62 'close tag ok'
63);
cb5717ef 64
65is(
49a6c0b5 66 join('', HTML::Tags::to_html_string Foo::quux),
cb5717ef 67 '<html><body id="spoon">YAY</body></html>',
68 'HTML tags ok'
69);
43a70ddb 70
71is(
0f339458 72 join('', XML::Tags::to_xml_string Foo::fleem),
73 '<woo ent="one&amp;two">',
74 'Escaping ok'
75);
76
77is(
9935bd6c 78 join('', XML::Tags::to_xml_string Foo::flaax),
79 '<woo>one&amp;two&lt;three&gt;four</woo><woo>one&two<three>four</woo>',
80 'Escaping user data ok'
81);
82
83is(
943937da 84 join('', XML::Tags::to_xml_string Foo::PI),
85 '<?xml version="1.0" encoding="UTF-8"?>',
86 'XML processing instruction'
87);
88
89is(
43a70ddb 90 join(', ', Foo::globbery),
91 't/globbery/one, t/globbery/two',
92 'real glob re-installed ok'
93);