| 1 |
#!perl |
| 2 |
|
| 3 |
BEGIN { chdir 't' if -d 't' } |
| 4 |
|
| 5 |
use strict; |
| 6 |
use warnings; |
| 7 |
|
| 8 |
use Test::More tests => 14; |
| 9 |
use Test::NoWarnings; |
| 10 |
|
| 11 |
use Text::MediawikiFormat as => 'wf', process_html => 0; |
| 12 |
|
| 13 |
my $wikitext = <<WIKI; |
| 14 |
|
| 15 |
* This should be a list. |
| 16 |
|
| 17 |
# This should be an ordered list. |
| 18 |
|
| 19 |
! This is like the default unordered list |
| 20 |
! But marked differently |
| 21 |
|
| 22 |
WIKI |
| 23 |
|
| 24 |
my $htmltext = wf($wikitext); |
| 25 |
like( $htmltext, qr!<li>This should be a list.</li>!m, 'unordered lists should be rendered correctly' ); |
| 26 |
like( $htmltext, qr!<li>This should be an ordered list.</li>!m, '...and ordered lists too' ); |
| 27 |
|
| 28 |
# Redefine all the list regexps to what they were to start with. |
| 29 |
my %tags = ( |
| 30 |
blocks => { |
| 31 |
ordered => qr/^#\s*/, |
| 32 |
unordered => qr/^\*\s*/, |
| 33 |
code => qr/^ /, |
| 34 |
}, |
| 35 |
); |
| 36 |
|
| 37 |
$htmltext = wf( $wikitext, \%tags ); |
| 38 |
like( |
| 39 |
$htmltext, |
| 40 |
qr!<li>This should be a list.</li>!m, |
| 41 |
'unordered should remain okay when we redefine all list regexps' |
| 42 |
); |
| 43 |
like( $htmltext, qr!<li>This should be an ordered list.</li>!m, '... and so should ordered' ); |
| 44 |
|
| 45 |
# Redefine again, set one of them to something different. |
| 46 |
%tags = ( |
| 47 |
blocks => { |
| 48 |
ordered => qr/^#\s*/, |
| 49 |
unordered => qr/^!\s*/, |
| 50 |
code => qr/^ /, |
| 51 |
}, |
| 52 |
); |
| 53 |
|
| 54 |
$htmltext = wf( $wikitext, \%tags ); |
| 55 |
like( $htmltext, qr!<li>But marked differently</li>!m, 'unordered should still work when redefined' ); |
| 56 |
like( $htmltext, qr!<li>This should be an ordered list.</li>!m, '...and ordered should be unaffected' ); |
| 57 |
|
| 58 |
# Now try redefining just one list type. |
| 59 |
%tags = ( blocks => { unordered => qr/^!\s*/ }, ); |
| 60 |
|
| 61 |
$htmltext = wf( $wikitext, \%tags ); |
| 62 |
like( |
| 63 |
$htmltext, |
| 64 |
qr!<li>This is like the default unordered list</li>!m, |
| 65 |
'redefining just one list type should work for that type' |
| 66 |
); |
| 67 |
like( $htmltext, qr!<li>This should be an ordered list.</li>!m, '...and should not affect other types too' ); |
| 68 |
|
| 69 |
# now test overriding strong and emphasized tags |
| 70 |
# don't use // to mark emphasized tags unless you /like/ this lookbehind |
| 71 |
%tags = ( |
| 72 |
strong_tag => qr/\*(.+?)\*/, |
| 73 |
emphasized_tag => qr|(?<!<)/(.+?)/|, |
| 74 |
); |
| 75 |
|
| 76 |
$wikitext = 'this is *strong*, /emphasized/, and */emphasized strong/*'; |
| 77 |
$htmltext = wf( $wikitext, \%tags ); |
| 78 |
|
| 79 |
like( $htmltext, qr!<strong>strong</strong>!, '... overriding strong tag' ); |
| 80 |
like( $htmltext, qr!<em>emphasized</em>!, '... overriding emphasized tag' ); |
| 81 |
like( $htmltext, qr!<strong><em>em.+ng</em></strong>!, '... and both at once' ); |
| 82 |
|
| 83 |
# Test redefining just one list type after using import with a list definition. |
| 84 |
package Bar; |
| 85 |
Text::MediawikiFormat->import( |
| 86 |
as => 'wf', |
| 87 |
blocks => { |
| 88 |
unordered => qr/^!\s*/ |
| 89 |
}, |
| 90 |
process_html => 0, |
| 91 |
); |
| 92 |
|
| 93 |
$htmltext = wf( "!1. Ordered list\n! Unordered list", { blocks => { ordered => qr/^\s*!([\d]+)\.\s*/ } }, {} ); |
| 94 |
::like( $htmltext, qr!<li>Ordered list</li>!m, 'redefining a single list type after import should work for that type' ); |
| 95 |
::like( $htmltext, qr!<li>Unordered list</li>!m, '...and also for a different type defined on import' ); |