This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Upgrade to CGI.pm-3.48
[perl5.git] / cpan / CGI / t / pretty.t
1 #!/bin/perl -w
2
3 use strict;
4 use Test::More tests => 17;
5 use CGI::Pretty ':all';
6
7 is(h1(), '<h1 />
8 ',"single tag");
9
10 is(ol(li('fred'),li('ethel')), <<HTML,   "basic indentation");
11 <ol>
12         <li>
13                 fred
14         </li>
15         <li>
16                 ethel
17         </li>
18 </ol>
19 HTML
20
21
22 is(p('hi',pre('there'),'frog'), <<HTML, "<pre> tags");
23 <p>
24         hi <pre>there</pre> frog
25 </p>
26 HTML
27
28 is(h1({-align=>'CENTER'},'fred'), <<HTML, "open/close tag with attribute");
29 <h1 align="CENTER">
30         fred
31 </h1>
32 HTML
33
34 is(h1({-align=>undef},'fred'), <<HTML,"open/close tag with orphan attribute");
35 <h1 align>
36         fred
37 </h1>
38 HTML
39
40 is(h1({-align=>'CENTER'},['fred','agnes']), <<HTML, "distributive tag with attribute");
41 <h1 align="CENTER">
42         fred
43 </h1>
44 <h1 align="CENTER">
45         agnes
46 </h1>
47 HTML
48
49 is(p('hi',a({-href=>'frog'},'there'),'frog'), <<HTML,   "as-is");
50 <p>
51         hi <a href="frog">there</a> frog
52 </p>
53 HTML
54
55 is(p([ qw( hi there frog ) ] ), <<HTML,   "array-reference");
56 <p>
57         hi
58 </p>
59 <p>
60         there
61 </p>
62 <p>
63         frog
64 </p>
65 HTML
66
67 is(p(p(p('hi'), 'there' ), 'frog'), <<HTML,   "nested tags");
68 <p>
69         <p>
70                 <p>
71                         hi
72                 </p>
73                 there
74         </p>
75         frog
76 </p>
77 HTML
78
79 is(table(TR(td(table(TR(td('hi', 'there', 'frog')))))), <<HTML,   "nested as-is tags");
80 <table>
81         <tr>
82                 <td><table>
83                         <tr>
84                                 <td>hi there frog</td>
85                         </tr>
86                 </table></td>
87         </tr>
88 </table>
89 HTML
90
91 is(table(TR(td(table(TR(td( [ qw( hi there frog ) ])))))), <<HTML,   "nested as-is array-reference");
92 <table>
93         <tr>
94                 <td><table>
95                         <tr>
96                                 <td>hi</td><td>there</td><td>frog</td>
97                         </tr>
98                 </table></td>
99         </tr>
100 </table>
101 HTML
102
103 $CGI::Pretty::INDENT = $CGI::Pretty::LINEBREAK = ""; 
104
105 is(h1(), '<h1 />',"single tag (pretty turned off)");
106 is(h1('fred'), '<h1>fred</h1>',"open/close tag (pretty turned off)");
107 is(h1('fred','agnes','maura'), '<h1>fred agnes maura</h1>',"open/close tag multiple (pretty turned off)");
108 is(h1({-align=>'CENTER'},'fred'), '<h1 align="CENTER">fred</h1>',"open/close tag with attribute (pretty turned off)");
109 is(h1({-align=>undef},'fred'), '<h1 align>fred</h1>',"open/close tag with orphan attribute (pretty turned off)");
110 is(h1({-align=>'CENTER'},['fred','agnes']), '<h1 align="CENTER">fred</h1> <h1 align="CENTER">agnes</h1>',
111    "distributive tag with attribute (pretty turned off)");
112