| 1 |
#!perl |
| 2 |
|
| 3 |
BEGIN { chdir 't' if -d 't' } |
| 4 |
|
| 5 |
use strict; |
| 6 |
use warnings; |
| 7 |
|
| 8 |
use Test::More tests => 8; |
| 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 not indented |
| 21 |
|
| 22 |
! This is like the default unordered list |
| 23 |
! But marked differently |
| 24 |
|
| 25 |
## This is like the default ordered list |
| 26 |
## But not indented |
| 27 |
|
| 28 |
WIKI |
| 29 |
|
| 30 |
my $htmltext = wf($wikitext); |
| 31 |
like $htmltext, qr!<li>This should be a list.</li>!m, 'unordered lists should render correctly'; |
| 32 |
like $htmltext, qr!<li>This should be an ordered list.</li>!m, '...ordered lists too'; |
| 33 |
|
| 34 |
# Redefine all the list regexps to what they were to start with. |
| 35 |
my %tags = ( |
| 36 |
lists => { |
| 37 |
ordered => qr/^#\s*/, |
| 38 |
unordered => qr/^\*\s*/, |
| 39 |
code => qr/^ /, |
| 40 |
}, |
| 41 |
); |
| 42 |
|
| 43 |
$htmltext = wf( $wikitext, \%tags ); |
| 44 |
like $htmltext, qr!<li>This should be a list.</li>!m, 'unordered should remain okay when we redefine all list regexps'; |
| 45 |
like $htmltext, qr!<li>This should be an ordered list.</li>!m, '...ordered lists too'; |
| 46 |
|
| 47 |
# Redefine again, set one of them to something different. |
| 48 |
%tags = ( |
| 49 |
blocks => { |
| 50 |
ordered => qr/^#\s*/, |
| 51 |
unordered => qr/^!\s*/, |
| 52 |
code => qr/^ /, |
| 53 |
}, |
| 54 |
); |
| 55 |
|
| 56 |
$htmltext = wf( $wikitext, \%tags ); |
| 57 |
like $htmltext, qr!<li>But marked differently</li>!m, 'unordered should still work when redefined'; |
| 58 |
like $htmltext, qr!<li>This should be an ordered list.</li>!m, '...ordered should be unaffected'; |
| 59 |
|
| 60 |
# Now try it without requiring an indent. |
| 61 |
%tags = ( |
| 62 |
indent => qr/^\s*/, |
| 63 |
blocks => { |
| 64 |
ordered => qr/^#\s*/, |
| 65 |
unordered => qr/^\*\s*/, |
| 66 |
code => qr/^ /, |
| 67 |
}, |
| 68 |
indented => { unordered => 0 }, |
| 69 |
); |
| 70 |
|
| 71 |
$htmltext = wf( $wikitext, \%tags ); |
| 72 |
like $htmltext, qr!<li># But not indented!m, 'redefining a list type to require no indent should work'; |