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