3 use Test::More tests => 142;
5 sub format_test($$$;$);
6 sub noformat_test($$$;$);
8 my $gotmodule = require_ok('DevHelp::Formatter');
13 skip "couldn't load module", 63 unless $gotmodule;
14 format_test 'acronym[hello]', '<p><acronym>hello</acronym></p>', 'acronym';
15 format_test 'acronym[|hello]', '<p><acronym>hello</acronym></p>', 'acronym with empty title';
16 format_test 'acronym[foo|hello]', '<p><acronym title="foo">hello</acronym></p>', 'acronym with title';
17 format_test 'acronym[foo|bar|hello]', '<p><acronym class="bar" title="foo">hello</acronym></p>', 'acronym with class and title';
18 format_test 'bdo[ltr|hello]', '<p><bdo dir="ltr">hello</bdo></p>', 'bdo with dir';
19 format_test 'code[hello]', '<p><code>hello</code></p>', 'code';
20 format_test 'code[|hello]', '<p><code>hello</code></p>', 'code empty class';
21 format_test 'code[foo|hello]', '<p><code class="foo">hello</code></p>', 'code with class';
22 format_test 'code[var[x]="1"]', '<p><code><var>x</var>="1"</code></p>', 'code with var';
23 format_test 'cite[hello]', '<p><cite>hello</cite></p>', 'cite';
24 format_test 'cite[|hello]', '<p><cite>hello</cite></p>', 'cite with empty title';
25 format_test 'cite[foo|hello]', '<p><cite title="foo">hello</cite></p>', 'cite with title';
26 format_test 'cite[foo|bar|hello]', '<p><cite class="bar" title="foo">hello</cite></p>', 'cite with class and title';
27 format_test 'small[hello]', '<p><small>hello</small></p>', 'small';
28 format_test 'small[|hello]', '<p><small>hello</small></p>', 'small empty class';
29 format_test 'small[foo|hello]', '<p><small class="foo">hello</small></p>', 'small with class';
30 format_test 'large[hello]', '<p><large>hello</large></p>', 'large';
31 format_test 'large[|hello]', '<p><large>hello</large></p>', 'large empty class';
32 format_test 'large[foo|hello]', '<p><large class="foo">hello</large></p>', 'large with class';
33 format_test 'mark[hello]', '<p><mark>hello</mark></p>', 'mark';
34 format_test 'mark[|hello]', '<p><mark>hello</mark></p>', 'mark empty class';
35 format_test 'mark[foo|hello]', '<p><mark class="foo">hello</mark></p>', 'mark with class';
36 format_test 'link[foo|hello]', '<p><a href="foo">hello</a></p>', 'anchor';
37 format_test 'poplink[foo|hello]', '<p><a href="foo" target="_blank">hello</a></p>', 'anchor with popup';
38 format_test <<IN, <<OUT, 'blockquote', 'both';
45 <blockquote>hello</blockquote>
50 format_test <<IN, <<OUT, 'blockquote with empty class', 'both';
59 <blockquote>hello</blockquote>
64 format_test <<IN, <<OUT, 'blockquote with class', 'both';
74 <blockquote class="foo">hello</blockquote>
75 <blockquote class="foo">hello<br />
77 <blockquote class="foo">
82 format_test <<IN, <<OUT, 'article', 'both';
89 <article>hello</article>
94 format_test <<IN, <<OUT, 'article with empty class', 'both';
103 <article>hello</article>
108 format_test <<IN, <<OUT, 'article with id and class', 'both';
109 article[#id foo|hello]
115 <article id="id" class="foo">hello</article>
116 <article id="id" class="foo">
120 format_test <<IN, <<OUT, 'section', 'both';
129 format_test <<IN, <<OUT, 'section with empty class', 'both';
137 format_test <<IN, <<OUT, 'section with id and class', 'both';
138 section[#id foo|hello
142 <section id="id" class="foo">
146 format_test <<IN, <<OUT, 'header', 'both';
155 format_test <<IN, <<OUT, 'header with empty class', 'both';
164 format_test <<IN, <<OUT, 'header with id and class', 'both';
169 <header id="id" class="foo">
173 format_test <<IN, <<OUT, 'footer', 'both';
180 format_test <<IN, <<OUT, 'footer with empty class', 'both';
191 format_test <<IN, <<OUT, 'footer with id and class', 'both';
196 <footer id="id" class="foo">
200 format_test <<IN, <<OUT, 'aside', 'both';
205 format_test <<IN, <<OUT, 'aside with empty class', 'both';
210 format_test <<IN, <<OUT, 'aside with id and class', 'both';
213 <aside id="id" class="foo">hello</aside>
215 format_test <<IN, <<OUT, 'nav', 'both';
220 format_test <<IN, <<OUT, 'nav with empty class', 'both';
231 format_test <<IN, <<OUT, 'nav with id and class', 'both';
234 <nav id="id" class="foo">hello</nav>
236 format_test <<IN, <<OUT, 'figure', 'both';
239 <figure>hello</figure>
241 format_test <<IN, <<OUT, 'figure with empty class', 'both';
244 <figure>hello</figure>
246 format_test <<IN, <<OUT, 'figure with id and class', 'both';
247 figure[#id foo|hello]
249 <figure id="id" class="foo">hello</figure>
251 format_test <<IN, <<OUT, 'figcaption', 'both';
254 <figcaption>hello</figcaption>
256 format_test <<IN, <<OUT, 'figcaption with empty class', 'both';
259 <figcaption>hello</figcaption>
261 format_test <<IN, <<OUT, 'figcaption with id and class', 'both';
262 figcaption[#id foo|hello]
264 <figcaption id="id" class="foo">hello</figcaption>
266 format_test <<IN, <<OUT, 'strong over paras', 'both';
271 <p><strong class="foo">hello</strong></p>
272 <p><strong class="foo">foo</strong></p>
274 format_test <<IN, <<OUT, 'blockquote list h1 var', 'both';
294 format_test <<IN, <<OUT, 'address class h1 abbr over paras', 'both';
297 quux]abbr[my abbr|hello]
299 class[foo|b[bold|E=MCsup[2]]]
303 <address class="foo">
306 <p><abbr title="my abbr">hello</abbr></p>
307 <p class="foo"><b class="bold">E=MC<sup>2</sup></b></p>
311 format_test <<IN, <<OUT, 'div blockquote h1 class over paras', 'both';
312 div[quux|blockquote[foo|h1[bar]
314 class[foo|b[bold|E=MCsup[2
321 <blockquote class="foo">
323 <p><b>hello</b><br />
324 <span class="foo"><b class="bold">E=MC<sup>2</sup></b></span></p>
325 <p class="foo"><b class="bold"><sup><kbd class="xxx">super</kbd></sup></b></p>
330 format_test <<IN, <<OUT, 'bold', 'both';
335 format_test 'i[hello]', '<p><i>hello</i></p>', 'italic';
336 format_test 'b[i[hello]]', '<p><b><i>hello</i></b></p>', 'bold/italic';
337 format_test <<IN, <<OUT, 'bold over lines', 'both';
344 format_test <<IN, <<OUT, 'bold over paras', 'both';
352 format_test <<IN, <<OUT, 'combo over paras', 'both';
359 <p><i><b>hello</b></i></p>
360 <p><i><b>foo</b></i></p>
361 <p><i><b>bar</b></i></p>
363 format_test <<IN, <<OUT, 'link', 'both';
368 <a href="http://foo/">
373 format_test 'tt[hello]', '<p><tt>hello</tt></p>', 'tt';
374 format_test 'font[-1|text]', '<p><font size="-1">text</font></p>', 'fontsize';
375 format_test 'fontcolor[-1|black|text]', '<p><font size="-1" color="black">text</font></p>', 'fontsizecolor';
376 format_test 'anchor[somename]', '<p><a name="somename"></a></p>', 'anchor';
377 format_test <<IN, <<OUT, 'pre', 'both';
386 format_test <<IN, <<OUT, 'pre with bold', 'both';
391 <pre><b>hello there</b>
395 format_test <<IN, <<OUT, 'html', 'both';
396 html[<object foo="bar" />]
401 format_test 'embed[foo]', '', 'embed1';
402 format_test 'embed[foo,bar]', '', 'embed2';
403 format_test 'embed[foo,bar,quux]', '', 'embed3';
404 format_test 'h1[|text]', '<h1>text</h1>', 'h1';
405 format_test 'h1[someclass|text]', '<h1 class="someclass">text</h1>', 'h1class';
406 format_test 'h6[|te>xt]', '<h6>te>xt</h6>', 'h6';
407 format_test 'h1[|foo]h2[|bar]', "<h1>foo</h1>\n<h2>bar</h2>", 'h1h2';
408 format_test 'h1[|foo]texth2[|bar]',
409 "<h1>foo</h1>\n<p>text</p>\n<h2>bar</h2>", 'h1texth2';
410 format_test <<IN, <<OUT, 'align', 'both';
411 align[left|some text]
417 format_test 'hr[]', '<hr />', 'hr0';
418 format_test 'hr[80%]', '<hr width="80%" />', 'hr1';
419 format_test 'hr[80%|10]', '<hr width="80%" size="10" />', 'hr2';
420 format_test <<'IN', <<'OUT', 'hr with other text', 'both';
431 format_test <<IN, <<OUT, 'table1', 'both';
433 bgcolor="black"|quux|blarg
437 <table width="80%"><tr bgcolor="black"><td>quux</td><td>blarg</td></tr><tr><td>hello</td><td>there</td></tr></table>
439 format_test <<IN, <<OUT, 'table2', 'both';
440 table[80%|#808080|2|2|Arial
441 bgcolor="black"|quux|blarg
445 <table width="80%" bgcolor="#808080" cellpadding="2"><tr bgcolor="black"><td><font size="2" face="Arial">quux</font></td><td><font size="2" face="Arial">blarg</font></td></tr><tr><td><font size="2" face="Arial">hello</font></td><td><font size="2" face="Arial">there</font></td></tr></table>
447 format_test <<IN, <<OUT, 'table3', 'both';
450 <table width="80%"><tr><td>foo</td></tr></table>
452 format_test <<IN, <<OUT, 'ol1', 'both';
461 format_test <<IN, <<OUT, 'ol2', 'both';
473 format_test <<IN, <<OUT, 'ol1 alpha', 'both';
482 format_test <<IN, <<OUT, 'ol2 alpha', 'both';
494 format_test <<IN, <<OUT, 'ul1', 'both';
503 format_test <<IN, <<OUT, 'ul2', 'both';
516 format_test <<IN, <<OUT, 'ul indented', 'both';
526 format_test <<IN, <<OUT, "don't ul at end of line", 'both';
527 this shouldn't be a bullet ** some text
529 ** this should be a bullet
532 <p>this shouldn't be a bullet ** some text</p>
534 <li>this should be a bullet</li>
535 <li>so should this</li>
539 format_test <<IN, <<OUT, 'mixed', 'both';
555 format_test <<IN, <<OUT, 'spaces between', 'both';
573 format_test 'indent[text]', '<div class="indent">text</div>', 'indent';
574 format_test 'center[text]', '<center>text</center>', 'center';
575 format_test 'hrcolor[80|10|#FF0000]', <<OUT, 'hrcolor', 'out';
576 <table width="80" height="10" border="0" bgcolor="#FF0000" cellpadding="0" cellspacing="0"><tr><td><img src="/images/trans_pixel.gif" width="1" height="1" alt="" /></td></tr></table>
578 format_test 'image[foo]', '<p></p>', 'image';
580 format_test 'class[xxx|yyy]', '<p class="xxx">yyy</p>', 'class';
581 format_test "class[xxx|yy\n\nzz]", <<EOS, 'class2', 'out';
582 <p class="xxx">yy</p>
583 <p class="xxx">zz</p>
585 format_test 'div[someclass|h1[|foo]barh2[|quux]]', <<EOS, 'divblock', 'out';
586 <div class="someclass">
593 format_test "h1[#foo|test]", q!<h1 id="foo">test</h1>!, 'h1#id';
594 format_test "h1[#foo bar|test]", q!<h1 id="foo" class="bar">test</h1>!, 'h1#id class';
595 format_test "h1[#foo bar quux|test]", q!<h1 id="foo" class="bar quux">test</h1>!, 'h1#id class class';
596 format_test "h1[text-align: center;|test]", q!<h1 style="text-align: center;">test</h1>!, 'h1 styled';
597 format_test "h1[#foo text-align: center;|test]", q!<h1 id="foo" style="text-align: center;">test</h1>!, 'h1 styled, id';
599 format_test "div[text-align: center;|test\n\ntest2]", <<EOS, 'div styled', 'out';
600 <div style="text-align: center;">
606 format_test "div[#foo|test\n\ntest2]", <<EOS, 'div #id', 'out';
613 format_test "abc comment[foo] def", "<p>abc def</p>", "comment";
614 format_test <<IN, <<OUT, 'link over paras following an hr', 'both';
637 format_test <<IN, <<OUT, 'link over div block containing paras', 'both';
640 div[#id class background-color: red;|
650 <div id="id" style="background-color: red;" class="class">
657 format_test <<IN, <<OUT, 'poplink over div block containing paras', 'both';
659 poplink[http://www.example.com/|
661 div[#id class background-color: red;|
670 <a href="http://www.example.com/" target="_blank">
671 <div id="id" style="background-color: red;" class="class">
678 format_test <<IN, <<OUT, 'link over complex nested block structure', 'both';
680 link[http://www.example.com/|
682 section[#id class background-color: red;|
700 class[quux|yesterday]]
709 <a href="http://www.example.com/">
710 <section id="id" style="background-color: red;" class="class">
715 <article class="foo">
716 <p><b class="bar">hello</b></p>
717 <p><b class="bar"><i>world</i></b></p>
718 <p><b class="bar"><i>today</i></b></p>
720 <p><i>tomorrow</i></p>
721 <p class="quux">yesterday</p>
724 <footer id="id">footer</footer>
729 format_test <<IN, <<OUT, 'list inside a block', 'both';
743 # remove_format() tests
744 noformat_test 'image[foo]', '', 'image';
745 noformat_test 'code[something [bar]]', 'something [bar]', 'nested []';
747 noformat_test "abc comment[foo] def", "abc def", "comment";
749 noformat_test 'class[foo|image[bar]]', '', 'class with image content';
750 noformat_test 'abbr[image[bar]]', '', 'abbr[] with image content';
751 noformat_test 'abbr[foo|image[bar]]', '', 'abbr[x|x] with image content';
752 noformat_test 'abbr[|image[bar]]', '', 'abbr[|x] with image content';
753 noformat_test 'strong[image[bar]]', '', 'strong[x] with image content';
754 noformat_test 'strong[|image[bar]]', '', 'strong[|x] with image content';
755 noformat_test 'strong[foo|image[bar]]', '', 'strong[x|x] with image content';
757 noformat_test 'div[foo|image[bar]]', '', 'div[x|x] with image content';
758 noformat_test 'comment[image[bar]]', '', 'comment[image[xx]] with image content';
759 noformat_test 'h1[foo|image[bar]]', '', 'h1[x|x] with image content';
760 noformat_test 'h1[|image[bar]]', '', 'h1[|x] with image content';
761 noformat_test 'h1[image[bar]]', '', 'h1[x] with image content';
763 noformat_test 'poplink[xxx|image[bar]]', '', 'poplink[x|x] with image content';
764 noformat_test 'poplink[image[bar]]', '', 'poplink[x] with image content';
765 noformat_test 'link[xxx|image[bar]]', '', 'link[x|x] with image content';
766 noformat_test 'link[image[bar]]', '', 'link[x] with image content';
767 noformat_test 'align[xxx|image[bar]]', '', 'align[x|x] with image content';
768 noformat_test 'font[xxx|image[bar]]', '', 'font[x|x] with image content';
769 noformat_test 'hr[xxx|image[bar]]', '', 'hr[x|x] with image content';
770 noformat_test 'anchor[image[bar]]', '', 'anchor[x] with image content';
771 noformat_test '**image[bar]', '', '** list with image content';
772 noformat_test '%%image[bar]', '', '%% list with image content';
773 noformat_test '##image[bar]', '', '## list with image content';
776 sub format_test ($$$;$) {
777 my ($in, $out, $desc, $stripnl) = @_;
780 $in =~ s/\n$// if $stripnl eq 'in' || $stripnl eq 'both';
781 $out =~ s/\n$// if $stripnl eq 'out' || $stripnl eq 'both';
783 my $formatter = DevHelp::Formatter->new;
785 my $result = $formatter->format($in);
787 is($result, $out, $desc);
790 sub noformat_test($$$;$) {
791 my ($in, $out, $desc, $stripnl) = @_;
794 $in =~ s/\n$// if $stripnl eq 'in' || $stripnl eq 'both';
795 $out =~ s/\n$// if $stripnl eq 'out' || $stripnl eq 'both';
797 my $formatter = DevHelp::Formatter->new;
799 my $result = $formatter->remove_format($in);
801 is($result, $out, $desc);