| 1 |
#!perl |
| 2 |
|
| 3 |
BEGIN { chdir 't' if -d 't' } |
| 4 |
|
| 5 |
use strict; |
| 6 |
use warnings; |
| 7 |
|
| 8 |
use Test::More tests => 9; |
| 9 |
use Test::NoWarnings; |
| 10 |
|
| 11 |
use_ok 'Text::MediawikiFormat', as => 'wf', process_html => 0 or exit; |
| 12 |
|
| 13 |
my $wikitext = <<END_HERE; |
| 14 |
* start of list |
| 15 |
* second line |
| 16 |
** indented list |
| 17 |
* now back to the first |
| 18 |
END_HERE |
| 19 |
|
| 20 |
my $htmltext = wf($wikitext); |
| 21 |
like $htmltext, qr|second line<ul>.*?<li>indented|s, 'nested lists should start correctly'; |
| 22 |
like $htmltext, qr|indented list.*?</li>.*?</ul>|s, '... and end correctly'; |
| 23 |
|
| 24 |
$wikitext = <<END_HERE; |
| 25 |
* 1 |
| 26 |
* 2 |
| 27 |
** 2.1 |
| 28 |
*** 2.1.1 |
| 29 |
* 3 |
| 30 |
|
| 31 |
* 4 |
| 32 |
** 4.1 |
| 33 |
*** 4.1.1 |
| 34 |
*** 4.1.2 |
| 35 |
* 5 |
| 36 |
END_HERE |
| 37 |
|
| 38 |
$htmltext = wf($wikitext); |
| 39 |
|
| 40 |
like $htmltext, qr|<ul>\s* |
| 41 |
<li>1</li>\s* |
| 42 |
<li>2<ul>\s* |
| 43 |
<li>2\.1<ul>\s* |
| 44 |
<li>2\.1\.1</li>\s* |
| 45 |
</ul>\s* |
| 46 |
</li>\s* |
| 47 |
</ul>\s* |
| 48 |
</li>\s* |
| 49 |
<li>3</li>\s* |
| 50 |
</ul>\s* |
| 51 |
<ul>\s* |
| 52 |
<li>4<ul>\s* |
| 53 |
<li>4\.1<ul>\s* |
| 54 |
<li>4\.1\.1</li>\s* |
| 55 |
<li>4\.1\.2</li>\s* |
| 56 |
</ul>\s* |
| 57 |
</li>\s* |
| 58 |
</ul>\s* |
| 59 |
</li>\s* |
| 60 |
<li>5</li>\s* |
| 61 |
</ul>|sx, 'nesting should be correct for multiple levels'; |
| 62 |
like $htmltext, qr|<li>4<|s, 'spaces should work instead of tabs'; |
| 63 |
like $htmltext, qr|<li>4<ul>\s*<li>4.1<ul>\s*<li>4.1.1</li>\s*<li>4.1.2</li>\s*</ul> |
| 64 |
\s*</li>|sx, 'nesting should be correct for spaces too'; |
| 65 |
|
| 66 |
TODO: { |
| 67 |
local $TODO = 'Dictionary lists not nesting correctly.'; |
| 68 |
|
| 69 |
### |
| 70 |
### Dictionary Lists |
| 71 |
### |
| 72 |
$wikitext = <<END_HERE; |
| 73 |
; Term 1 |
| 74 |
: Def 1.1 |
| 75 |
:; Term 1.1.1 : Def 1.1.1.1 |
| 76 |
:; Term 1.1.2 : Def 1.1.2.1 |
| 77 |
:: Def 1.1.2.2 |
| 78 |
:; Term 1.1.3 |
| 79 |
:: Def 1.1.3.1 |
| 80 |
::; Term 1.1.3.1.1 : Def 1.1.3.1.1.1 |
| 81 |
; Term 2 |
| 82 |
: Def 2.1 |
| 83 |
: Def 2.2 |
| 84 |
:; Term 2.2.1 : Def 2.2.1.1 |
| 85 |
; Term 3 : Def 3.1 |
| 86 |
END_HERE |
| 87 |
|
| 88 |
$htmltext = wf($wikitext); |
| 89 |
|
| 90 |
is $htmltext, '', 'dictionary lists nest correctly'; |
| 91 |
|
| 92 |
$wikitext = <<END_HERE; |
| 93 |
; A |
| 94 |
: A.a |
| 95 |
:# A.a.1 |
| 96 |
:## A.a.1.1 |
| 97 |
:# A.a.2 |
| 98 |
:#* A.a.2.* |
| 99 |
:#* A.a.2.* |
| 100 |
:#*# A.a.2.*.1 |
| 101 |
: A.b |
| 102 |
END_HERE |
| 103 |
|
| 104 |
$htmltext = wf($wikitext); |
| 105 |
|
| 106 |
is $htmltext, '<dl> |
| 107 |
<dt>A</dt> |
| 108 |
<dd>A.a</dd> |
| 109 |
<ol> |
| 110 |
<li>A.a.1<ol> |
| 111 |
<li>A.a.1.1</li> |
| 112 |
</ol> |
| 113 |
</li> |
| 114 |
<li>A.a.2<ul> |
| 115 |
<li>A.a.2.*</li> |
| 116 |
<li>A.a.2.*<ol> |
| 117 |
<li>A.a.2.*.1</li> |
| 118 |
</ol> |
| 119 |
</li> |
| 120 |
</ul> |
| 121 |
</li> |
| 122 |
</ol> |
| 123 |
<dd>A.b</dd> |
| 124 |
</dl> |
| 125 |
', 'lists nest correctly within dictionary lists'; |
| 126 |
} |