File: tags.t

package info (click to toggle)
libweb-simple-perl 0.033-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 380 kB
  • sloc: perl: 1,622; makefile: 7
file content (130 lines) | stat: -rw-r--r-- 2,540 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
use strict; use warnings FATAL => 'all';
use Test::More qw(no_plan);

my $globbery;
BEGIN { $globbery = join(', ', <t/globbery/o* t/globbery/t*>) }
{

  package Foo;

  sub foo {
    use XML::Tags qw(one two three);
    <one>, <two>, <three>;
  }

  sub bar {
    no warnings 'once'; # this is supposed to warn, it's broken
    <one>
  }

  sub baz {
    use XML::Tags qw(bar);
    </bar>;
  }

  sub quux {
    use HTML::Tags;
    <html>, <body id="spoon">, "YAY", </body>, </html>;
  }

  sub xquux {
    use HTML::Tags;
    <link href="#self" rel="me" />,
    <table>,<tr>,<td>,'x',<sub>,1,</sub>,</td>,</tr>,</table>;
  }

  sub fleem {
    use XML::Tags qw(woo);
    my $ent = 'one&two<three>"four';
    <woo ent="$ent">;
  }

  sub flaax {
    use XML::Tags qw(woo);
    my $data = "one&two<three>four";
    <woo>,  $data, </woo>,
    <woo>, \$data, </woo>;
  }

  sub HTML_comment {
    use HTML::Tags;
    <!-- this is a comment -->;
  }

  sub PI {
    use XML::Tags;
    <?xml version="1.0" encoding="UTF-8"?>;
  }

  sub DTD {
    use HTML::Tags;
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  }

  sub globbery {
    <t/globbery/o* t/globbery/t*>;
  }
}

is(
  join(', ', XML::Tags::to_xml_string Foo::foo()),
  '<one>, <two>, <three>',
  'open tags ok'
);

ok(!eval { Foo::bar(); 1 }, 'Death on use of unimported tag');

is(
  join(', ', XML::Tags::to_xml_string Foo::baz()),
  '</bar>',
  'close tag ok'
);

is(
  join('', HTML::Tags::to_html_string Foo::quux),
  '<html><body id="spoon">YAY</body></html>',
  'HTML tags ok'
);

is(
  join('', HTML::Tags::to_html_string Foo::xquux),
  '<link href="#self" rel="me" />' .
  '<table><tr><td>x<sub>1</sub></td></tr></table>',
  'Conflicting HTML tags ok'
);

is(
  join('', XML::Tags::to_xml_string Foo::HTML_comment),
  '<!-- this is a comment -->',
  'HTML comment ok'
);

is(
  join('', XML::Tags::to_xml_string Foo::fleem),
  '<woo ent="one&amp;two&lt;three&gt;&quot;four">',
  'Escaping ok'
);

is(
  join('', XML::Tags::to_xml_string Foo::flaax),
  '<woo>one&amp;two&lt;three&gt;four</woo><woo>one&two<three>four</woo>',
  'Escaping user data ok'
);

is(
  join('', XML::Tags::to_xml_string Foo::PI),
  '<?xml version="1.0" encoding="UTF-8"?>',
  'XML processing instruction'
);

is(
  join('', HTML::Tags::to_html_string Foo::DTD),
  '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">',
  'DTD ok'
);

is(
  join(', ', Foo::globbery),
  $globbery,
  'real glob re-installed ok'
);