]> git.imager.perl.org - bse.git/blob - t/010-modules/050-format.t
the index parameter wasn't used and isn't required
[bse.git] / t / 010-modules / 050-format.t
1 #!perl -w
2 use strict;
3 use Test::More tests => 153;
4
5 sub format_test($$$;$);
6 sub noformat_test($$$;$);
7
8 my $gotmodule = require_ok('DevHelp::Formatter');
9
10 ++$|;
11
12 SKIP: {
13   skip "couldn't load module", 146 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>=&quot;1&quot;</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';
39 blockquote[hello]
40
41 blockquote[
42
43 hello]
44 IN
45 <blockquote>hello</blockquote>
46 <blockquote>
47 <p>hello</p>
48 </blockquote>
49 OUT
50   format_test <<IN, <<OUT, 'blockquote with empty class', 'both';
51 blockquote[|hello]
52
53 blockquote[|
54
55 hello
56
57 ]
58 IN
59 <blockquote>hello</blockquote>
60 <blockquote>
61 <p>hello</p>
62 </blockquote>
63 OUT
64   format_test <<IN, <<OUT, 'blockquote with class', 'both';
65 blockquote[foo|hello]
66
67 blockquote[foo|hello
68 world]
69
70 blockquote[foo|
71 hello
72 world]
73 IN
74 <blockquote class="foo">hello</blockquote>
75 <blockquote class="foo">hello<br />
76 world</blockquote>
77 <blockquote class="foo">
78 <p>hello<br />
79 world</p>
80 </blockquote>
81 OUT
82   format_test <<IN, <<OUT, 'article', 'both';
83 article[hello]
84
85 article[
86
87 hello]
88 IN
89 <article>hello</article>
90 <article>
91 <p>hello</p>
92 </article>
93 OUT
94   format_test <<IN, <<OUT, 'article with empty class', 'both';
95 article[|hello]
96
97 article[|
98
99 hello
100
101 ]
102 IN
103 <article>hello</article>
104 <article>
105 <p>hello</p>
106 </article>
107 OUT
108   format_test <<IN, <<OUT, 'article with id and class', 'both';
109 article[#id foo|hello]
110
111 article[#id foo|
112
113 hello]
114 IN
115 <article id="id" class="foo">hello</article>
116 <article id="id" class="foo">
117 <p>hello</p>
118 </article>
119 OUT
120   format_test <<IN, <<OUT, 'section', 'both';
121 section[
122 hello
123 ]
124 IN
125 <section>
126 <p>hello</p>
127 </section>
128 OUT
129   format_test <<IN, <<OUT, 'section with empty class', 'both';
130 section[|
131 hello]
132 IN
133 <section>
134 <p>hello</p>
135 </section>
136 OUT
137   format_test <<IN, <<OUT, 'section with id and class', 'both';
138 section[#id foo|hello
139
140 ]
141 IN
142 <section id="id" class="foo">
143 <p>hello</p>
144 </section>
145 OUT
146   format_test <<IN, <<OUT, 'header', 'both';
147 header[
148
149 hello]
150 IN
151 <header>
152 <p>hello</p>
153 </header>
154 OUT
155   format_test <<IN, <<OUT, 'header with empty class', 'both';
156 header[|hello
157
158 ]
159 IN
160 <header>
161 <p>hello</p>
162 </header>
163 OUT
164   format_test <<IN, <<OUT, 'header with id and class', 'both';
165 header[#id foo|
166 hello
167 ]
168 IN
169 <header id="id" class="foo">
170 <p>hello</p>
171 </header>
172 OUT
173   format_test <<IN, <<OUT, 'footer', 'both';
174 footer[hello
175 world]
176 IN
177 <footer>hello<br />
178 world</footer>
179 OUT
180   format_test <<IN, <<OUT, 'footer with empty class', 'both';
181 footer[|
182
183 hello
184
185 ]
186 IN
187 <footer>
188 <p>hello</p>
189 </footer>
190 OUT
191   format_test <<IN, <<OUT, 'footer with id and class', 'both';
192 footer[#id foo|hello
193
194 ]
195 IN
196 <footer id="id" class="foo">
197 <p>hello</p>
198 </footer>
199 OUT
200   format_test <<IN, <<OUT, 'aside', 'both';
201 aside[hello]
202 IN
203 <aside>hello</aside>
204 OUT
205   format_test <<IN, <<OUT, 'aside with empty class', 'both';
206 aside[|hello]
207 IN
208 <aside>hello</aside>
209 OUT
210   format_test <<IN, <<OUT, 'aside with id and class', 'both';
211 aside[#id foo|hello]
212 IN
213 <aside id="id" class="foo">hello</aside>
214 OUT
215   format_test <<IN, <<OUT, 'nav', 'both';
216 nav[hello]
217 IN
218 <nav>hello</nav>
219 OUT
220   format_test <<IN, <<OUT, 'nav with empty class', 'both';
221 nav[|
222
223 hello
224
225 ]
226 IN
227 <nav>
228 <p>hello</p>
229 </nav>
230 OUT
231   format_test <<IN, <<OUT, 'nav with id and class', 'both';
232 nav[#id foo|hello]
233 IN
234 <nav id="id" class="foo">hello</nav>
235 OUT
236   format_test <<IN, <<OUT, 'figure', 'both';
237 figure[hello]
238 IN
239 <figure>hello</figure>
240 OUT
241   format_test <<IN, <<OUT, 'figure with empty class', 'both';
242 figure[|hello]
243 IN
244 <figure>hello</figure>
245 OUT
246   format_test <<IN, <<OUT, 'figure with id and class', 'both';
247 figure[#id foo|hello]
248 IN
249 <figure id="id" class="foo">hello</figure>
250 OUT
251   format_test <<IN, <<OUT, 'figcaption', 'both';
252 figcaption[hello]
253 IN
254 <figcaption>hello</figcaption>
255 OUT
256   format_test <<IN, <<OUT, 'figcaption with empty class', 'both';
257 figcaption[|hello]
258 IN
259 <figcaption>hello</figcaption>
260 OUT
261   format_test <<IN, <<OUT, 'figcaption with id and class', 'both';
262 figcaption[#id foo|hello]
263 IN
264 <figcaption id="id" class="foo">hello</figcaption>
265 OUT
266   format_test <<IN, <<OUT, 'strong over paras', 'both';
267 strong[foo|hello
268
269 foo]
270 IN
271 <p><strong class="foo">hello</strong></p>
272 <p><strong class="foo">foo</strong></p>
273 OUT
274   format_test <<IN, <<OUT, 'blockquote list h1 var', 'both';
275 blockquote[
276 ** one
277 ** two
278 h1[quux]var[hello
279 there]
280
281 foo]
282 IN
283 <blockquote>
284 <ul>
285 <li>one</li>
286 <li>two</li>
287 </ul>
288 <h1>quux</h1>
289 <p><var>hello<br />
290 there</var></p>
291 <p>foo</p>
292 </blockquote>
293 OUT
294   format_test <<IN, <<OUT, 'address class h1 abbr over paras', 'both';
295 address[foo|h1[bar
296
297 quux]abbr[my abbr|hello]
298
299 class[foo|b[bold|E=MCsup[2]]]
300
301 foo]
302 IN
303 <address class="foo">
304 <h1>bar</h1>
305 <h1>quux</h1>
306 <p><abbr title="my abbr">hello</abbr></p>
307 <p class="foo"><b class="bold">E=MC<sup>2</sup></b></p>
308 <p>foo</p>
309 </address>
310 OUT
311   format_test <<IN, <<OUT, 'div blockquote h1 class over paras', 'both';
312 div[quux|blockquote[foo|h1[bar]
313 b[hello]
314 class[foo|b[bold|E=MCsup[2
315
316 kbd[xxx|super]]]]
317
318 foo]]
319 IN
320 <div class="quux">
321 <blockquote class="foo">
322 <h1>bar</h1>
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>
326 <p>foo</p>
327 </blockquote>
328 </div>
329 OUT
330   format_test <<IN, <<OUT, 'bold', 'both';
331 b[hello]
332 IN
333 <p><b>hello</b></p>
334 OUT
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';
338 b[hello
339 foo]
340 IN
341 <p><b>hello<br />
342 foo</b></p>
343 OUT
344   format_test <<IN, <<OUT, 'bold over paras', 'both';
345 b[hello
346
347 foo]
348 IN
349 <p><b>hello</b></p>
350 <p><b>foo</b></p>
351 OUT
352   format_test <<IN, <<OUT, 'combo over paras', 'both';
353 i[b[hello
354
355 foo
356
357 bar]]
358 IN
359 <p><i><b>hello</b></i></p>
360 <p><i><b>foo</b></i></p>
361 <p><i><b>bar</b></i></p>
362 OUT
363   format_test <<IN, <<OUT, 'link', 'both';
364 link[http://foo/|bar
365
366 quux]
367 IN
368 <a href="http://foo/">
369 <p>bar</p>
370 <p>quux</p>
371 </a>
372 OUT
373   format_test <<IN, <<OUT, "multi-p link followed by normal text", 'both';
374 link[#foo|
375 one
376
377 two
378 ]
379
380 normal text
381 IN
382 <a href="#foo">
383 <p>one</p>
384 <p>two</p>
385 </a>
386 <p>normal text</p>
387 OUT
388   format_test 'tt[hello]', '<p><tt>hello</tt></p>', 'tt';
389   format_test 'font[-1|text]', '<p><font size="-1">text</font></p>', 'fontsize';
390   format_test 'fontcolor[-1|black|text]', '<p><font size="-1" color="black">text</font></p>', 'fontsizecolor';
391   format_test 'anchor[somename]', '<p><a name="somename"></a></p>', 'anchor';
392   format_test <<IN, <<OUT, 'pre', 'both';
393
394
395 pre[hello there
396 Joe]
397 IN
398 <pre>hello there
399 Joe</pre>
400 OUT
401   format_test <<IN, <<OUT, 'pre with bold', 'both';
402 pre[b[hello there
403
404 Joe]]
405 IN
406 <pre><b>hello there</b>
407
408 <b>Joe</b></pre>
409 OUT
410   format_test <<IN, <<OUT, 'html', 'both';
411 html[<object foo="bar" />]
412 IN
413 <object foo="bar" />
414 OUT
415
416   format_test 'embed[foo]', '', 'embed1';
417   format_test 'embed[foo,bar]', '', 'embed2';
418   format_test 'embed[foo,bar,quux]', '', 'embed3';
419   format_test 'h1[|text]', '<h1>text</h1>', 'h1';
420   format_test 'h1[someclass|text]', '<h1 class="someclass">text</h1>', 'h1class';
421   format_test 'h6[|te>xt]', '<h6>te&gt;xt</h6>', 'h6';
422   format_test 'h1[|foo]h2[|bar]', "<h1>foo</h1>\n<h2>bar</h2>", 'h1h2';
423   format_test 'h1[|foo]texth2[|bar]', 
424     "<h1>foo</h1>\n<p>text</p>\n<h2>bar</h2>", 'h1texth2';
425   format_test <<IN, <<OUT, 'align', 'both';
426 align[left|some text]
427 IN
428 <div align="left">
429 <p>some text</p>
430 </div>
431 OUT
432   format_test 'hr[]', '<hr />', 'hr0';
433   format_test 'hr[80%]', '<hr width="80%" />', 'hr1';
434   format_test 'hr[80%|10]', '<hr width="80%" size="10" />', 'hr2';
435   format_test <<'IN', <<'OUT', 'hr with other text', 'both';
436 testhr[]test
437 hr[80%]
438 test
439 IN
440 <p>test</p>
441 <hr />
442 <p>test</p>
443 <hr width="80%" />
444 <p>test</p>
445 OUT
446   format_test <<IN, <<OUT, 'table1', 'both';
447 table[80%
448 bgcolor="black"|quux|blarg
449 |hello|there
450 ]
451 IN
452 <table width="80%"><tr bgcolor="black"><td>quux</td><td>blarg</td></tr><tr><td>hello</td><td>there</td></tr></table>
453 OUT
454   format_test <<IN, <<OUT, 'table2', 'both';
455 table[80%|#808080|2|2|Arial
456 bgcolor="black"|quux|blarg
457 |hello|there
458 ]
459 IN
460 <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>
461 OUT
462   format_test <<IN, <<OUT, 'table3', 'both';
463 table[80%|foo]
464 IN
465 <table width="80%"><tr><td>foo</td></tr></table>
466 OUT
467   format_test <<IN, <<OUT, 'ol1', 'both';
468 ## one
469 ## two
470 IN
471 <ol>
472 <li>one</li>
473 <li>two</li>
474 </ol>
475 OUT
476   format_test <<IN, <<OUT, 'ol2', 'both';
477 ## one
478
479 ## two
480 IN
481 <ol>
482 <li>
483 <p>one</p>
484 </li>
485 <li>two</li>
486 </ol>
487 OUT
488   format_test <<IN, <<OUT, 'ol1 alpha', 'both';
489 %% one
490 %% two
491 IN
492 <ol type="a">
493 <li>one</li>
494 <li>two</li>
495 </ol>
496 OUT
497   format_test <<IN, <<OUT, 'ol2 alpha', 'both';
498 %% one
499
500 %% two
501 IN
502 <ol type="a">
503 <li>
504 <p>one</p>
505 </li>
506 <li>two</li>
507 </ol>
508 OUT
509   format_test <<IN, <<OUT, 'ul1', 'both';
510 ** one
511 ** two
512 IN
513 <ul>
514 <li>one</li>
515 <li>two</li>
516 </ul>
517 OUT
518   format_test <<IN, <<OUT, 'ul2', 'both';
519 ** one
520
521 ** two
522 IN
523 <ul>
524 <li>
525 <p>one</p>
526 </li>
527 <li>two</li>
528 </ul>
529 OUT
530
531   format_test <<IN, <<OUT, 'ul indented', 'both';
532   ** one
533 **two
534 IN
535 <ul>
536 <li>one</li>
537 <li>two</li>
538 </ul>
539 OUT
540
541   format_test <<IN, <<OUT, "don't ul at end of line", 'both';
542 this shouldn't be a bullet ** some text
543
544 ** this should be a bullet
545 ** so should this
546 IN
547 <p>this shouldn't be a bullet ** some text</p>
548 <ul>
549 <li>this should be a bullet</li>
550 <li>so should this</li>
551 </ul>
552 OUT
553
554   format_test <<IN, <<OUT, 'mixed', 'both';
555 ** joe
556 ** bob
557 ## one
558 ## two
559 IN
560 <ul>
561 <li>joe</li>
562 <li>bob</li>
563 </ul>
564 <ol>
565 <li>one</li>
566 <li>two</li>
567 </ol>
568 OUT
569
570   format_test <<IN, <<OUT, 'spaces between', 'both';
571 ** joe
572  
573 ** bob
574
575 ** jane
576 IN
577 <ul>
578 <li>
579 <p>joe</p>
580 </li>
581 <li>
582 <p>bob</p>
583 </li>
584 <li>jane</li>
585 </ul>
586 OUT
587
588   format_test <<IN, <<OUT, "list[] no attrs", 'both';
589 list[|
590 ## one
591 ## two
592 ]
593 IN
594 <ol>
595 <li>one</li>
596 <li>two</li>
597 </ol>
598 OUT
599
600   format_test <<IN, <<OUT, "list[] id and class", 'both';
601 list[#test someclass|
602 ## one
603 ## two
604 ]
605 IN
606 <ol id="test" class="someclass">
607 <li>one</li>
608 <li>two</li>
609 </ol>
610 OUT
611
612   format_test <<IN, <<OUT, "list[] %% id and class", 'both';
613 list[#test someclass|
614 %% one
615 %% two
616 ]
617 IN
618 <ol id="test" class="someclass" type="a">
619 <li>one</li>
620 <li>two</li>
621 </ol>
622 OUT
623
624   format_test 'indent[text]', '<div class="indent">text</div>', 'indent';
625   format_test 'center[text]', '<center>text</center>', 'center';
626   format_test 'hrcolor[80|10|#FF0000]', <<OUT, 'hrcolor', 'out';
627 <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>
628 OUT
629   format_test 'image[foo]', '<p></p>', 'image';
630
631   format_test 'class[xxx|yyy]', '<p class="xxx">yyy</p>', 'class';
632   format_test "class[xxx|yy\n\nzz]", <<EOS, 'class2', 'out';
633 <p class="xxx">yy</p>
634 <p class="xxx">zz</p>
635 EOS
636   format_test "class[xxx|class[yyy|text]]",
637     '<p class="xxx"><span class="yyy">text</span></p>', "more class";
638   format_test "style[font-size: 18px|class[yyy|text]]",
639     '<p style="font-size: 18px"><span class="yyy">text</span></p>', "more class";
640   format_test 'div[someclass|h1[|foo]barh2[|quux]]', <<EOS, 'divblock', 'out';
641 <div class="someclass">
642 <h1>foo</h1>
643 <p>bar</p>
644 <h2>quux</h2>
645 </div>
646 EOS
647
648   format_test "h1[#foo|test]", q!<h1 id="foo">test</h1>!, 'h1#id';
649   format_test "h1[#foo bar|test]", q!<h1 id="foo" class="bar">test</h1>!, 'h1#id class';
650   format_test "h1[#foo bar quux|test]", q!<h1 id="foo" class="bar quux">test</h1>!, 'h1#id class class';
651   format_test "h1[text-align: center;|test]", q!<h1 style="text-align: center;">test</h1>!, 'h1 styled';
652   format_test "h1[#foo text-align: center;|test]", q!<h1 id="foo" style="text-align: center;">test</h1>!, 'h1 styled, id';
653
654   format_test "div[text-align: center;|test\n\ntest2]", <<EOS, 'div styled', 'out';
655 <div style="text-align: center;">
656 <p>test</p>
657 <p>test2</p>
658 </div>
659 EOS
660
661   format_test "div[#foo|test\n\ntest2]", <<EOS, 'div #id', 'out';
662 <div id="foo">
663 <p>test</p>
664 <p>test2</p>
665 </div>
666 EOS
667
668   format_test "abc comment[foo] def", "<p>abc  def</p>", "comment";
669   format_test <<IN, <<OUT, 'link over paras following an hr', 'both';
670 hr[100%]
671
672 link[#foo|hello
673
674 world]
675
676 link[#foo|
677 hello
678
679 world]
680 IN
681 <hr width="100%" />
682 <a href="#foo">
683 <p>hello</p>
684 <p>world</p>
685 </a>
686 <a href="#foo">
687 <p>hello</p>
688 <p>world</p>
689 </a>
690 OUT
691
692 format_test <<IN, <<OUT, 'link over div block containing paras', 'both';
693 link[#foo|
694
695 div[#id class background-color: red;|
696
697 hello
698
699 world
700
701 ]
702 ]
703 IN
704 <a href="#foo">
705 <div id="id" style="background-color: red;" class="class">
706 <p>hello</p>
707 <p>world</p>
708 </div>
709 </a>
710 OUT
711
712 format_test <<IN, <<OUT, 'poplink over div block containing paras', 'both';
713
714 poplink[http://www.example.com/|
715
716 div[#id class background-color: red;|
717
718 hello
719
720 world
721
722 ]
723 ]
724 IN
725 <a href="http://www.example.com/" target="_blank">
726 <div id="id" style="background-color: red;" class="class">
727 <p>hello</p>
728 <p>world</p>
729 </div>
730 </a>
731 OUT
732
733 format_test <<IN, <<OUT, 'link over complex nested block structure', 'both';
734
735 link[http://www.example.com/|
736
737 section[#id class background-color: red;|
738
739 header[h1[headline
740
741 more]
742
743 ]
744
745 article[foo|
746
747 b[bar|hello
748
749 i[world
750
751 today]]
752
753 div[i[tomorrow]
754
755 class[quux|yesterday]]
756
757 ]
758
759 footer[#id|footer]
760
761 ]
762 ]
763 IN
764 <a href="http://www.example.com/">
765 <section id="id" style="background-color: red;" class="class">
766 <header>
767 <h1>headline</h1>
768 <h1>more</h1>
769 </header>
770 <article class="foo">
771 <p><b class="bar">hello</b></p>
772 <p><b class="bar"><i>world</i></b></p>
773 <p><b class="bar"><i>today</i></b></p>
774 <div>
775 <p><i>tomorrow</i></p>
776 <p class="quux">yesterday</p>
777 </div>
778 </article>
779 <footer id="id">footer</footer>
780 </section>
781 </a>
782 OUT
783
784 format_test <<IN, <<OUT, 'list inside a block', 'both';
785 div[#id|
786 ** item
787 ** item
788 ]
789 IN
790 <div id="id">
791 <ul>
792 <li>item</li>
793 <li>item</li>
794 </ul>
795 </div>
796 OUT
797
798 format_test <<IN, <<OUT, 'link starting inline containing a block with paras', 'both';
799 inline text link[http://www.example.com/|div[#id class background-color: red;|hello
800
801 world]]
802 IN
803 <p>inline text</p>
804 <a href="http://www.example.com/">
805 <div id="id" style="background-color: red;" class="class">
806 <p>hello</p>
807 <p>world</p>
808 </div>
809 </a>
810 OUT
811
812 format_test <<IN, <<OUT, 'poplink starting inline containing a block with paras', 'both';
813 inline text poplink[http://www.example.com/|div[#id class background-color: red;|hello
814
815 world]]
816 IN
817 <p>inline text</p>
818 <a href="http://www.example.com/" target="_blank">
819 <div id="id" style="background-color: red;" class="class">
820 <p>hello</p>
821 <p>world</p>
822 </div>
823 </a>
824 OUT
825
826 format_test <<IN, <<OUT, 'link starting inline containing a block', 'both';
827 inline text link[http://www.example.com/|div[#id class background-color: red;|hello world]]
828 IN
829 <p>inline text</p>
830 <a href="http://www.example.com/">
831 <div id="id" style="background-color: red;" class="class">hello world</div>
832 </a>
833 OUT
834
835 format_test <<IN, <<OUT, 'poplink starting inline containing a block', 'both';
836 inline text poplink[http://www.example.com/|div[#id class background-color: red;|hello world]]
837 IN
838 <p>inline text</p>
839 <a href="http://www.example.com/" target="_blank">
840 <div id="id" style="background-color: red;" class="class">hello world</div>
841 </a>
842 OUT
843
844   # remove_format() tests
845   noformat_test 'image[foo]', '', 'image';
846   noformat_test 'code[something [bar]]', 'something [bar]', 'nested []';
847
848   noformat_test "abc comment[foo] def", "abc  def", "comment";
849
850   noformat_test 'class[foo|image[bar]]', '', 'class with image content';
851   noformat_test 'abbr[image[bar]]', '', 'abbr[] with image content';
852   noformat_test 'abbr[foo|image[bar]]', '', 'abbr[x|x] with image content';
853   noformat_test 'abbr[|image[bar]]', '', 'abbr[|x] with image content';
854   noformat_test 'strong[image[bar]]', '', 'strong[x] with image content';
855   noformat_test 'strong[|image[bar]]', '', 'strong[|x] with image content';
856   noformat_test 'strong[foo|image[bar]]', '', 'strong[x|x] with image content';
857
858   noformat_test 'div[foo|image[bar]]', '', 'div[x|x] with image content';
859   noformat_test 'comment[image[bar]]', '', 'comment[image[xx]] with image content';
860   noformat_test 'h1[foo|image[bar]]', '', 'h1[x|x] with image content';
861   noformat_test 'h1[|image[bar]]', '', 'h1[|x] with image content';
862   noformat_test 'h1[image[bar]]', '', 'h1[x] with image content';
863   
864   noformat_test 'poplink[xxx|image[bar]]', '', 'poplink[x|x] with image content';
865   noformat_test 'poplink[image[bar]]', '', 'poplink[x] with image content';
866   noformat_test 'link[xxx|image[bar]]', '', 'link[x|x] with image content';
867   noformat_test 'link[image[bar]]', '', 'link[x] with image content';
868   noformat_test 'align[xxx|image[bar]]', '', 'align[x|x] with image content';
869   noformat_test 'font[xxx|image[bar]]', '', 'font[x|x] with image content';
870   noformat_test 'hr[xxx|image[bar]]', '', 'hr[x|x] with image content';
871   noformat_test 'anchor[image[bar]]', '', 'anchor[x] with image content';
872   noformat_test '**image[bar]', '', '** list with image content';
873   noformat_test '%%image[bar]', '', '%% list with image content';
874   noformat_test '##image[bar]', '', '## list with image content';
875   noformat_test <<IN, <<OUT, "list[] no attr", "both";
876 list[|
877 ## one
878 ## two
879 ]
880 IN
881  one
882  two
883
884 OUT
885 }
886
887 sub format_test ($$$;$) {
888   my ($in, $out, $desc, $stripnl) = @_;
889
890   $stripnl ||= 'none';
891   $in =~ s/\n$// if $stripnl eq 'in' || $stripnl eq 'both';
892   $out =~ s/\n$// if $stripnl eq 'out' || $stripnl eq 'both';
893
894   my $formatter = DevHelp::Formatter->new;
895
896   my $result = $formatter->format($in);
897
898   is($result, $out, $desc);
899 }
900
901 sub noformat_test($$$;$) {
902   my ($in, $out, $desc, $stripnl) = @_;
903
904   $stripnl ||= 'none';
905   $in =~ s/\n$// if $stripnl eq 'in' || $stripnl eq 'both';
906   $out =~ s/\n$// if $stripnl eq 'out' || $stripnl eq 'both';
907
908   my $formatter = DevHelp::Formatter->new;
909
910   my $result = $formatter->remove_format($in);
911
912   is($result, $out, $desc);
913 }