File: lists-nested.t

package info (click to toggle)
libtext-mediawikiformat-perl 1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze, wheezy
  • size: 236 kB
  • ctags: 46
  • sloc: perl: 1,848; makefile: 2
file content (134 lines) | stat: -rw-r--r-- 2,082 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!perl

BEGIN { chdir 't' if -d 't' }

use strict;
use warnings;

use Test::More tests => 9;
use Test::NoWarnings;

use_ok 'Text::MediawikiFormat', as => 'wf', process_html => 0 or exit;

my $wikitext =<<END_HERE;
* start of list
* second line
** indented list
* now back to the first
END_HERE

my $htmltext = wf ($wikitext);
like $htmltext, qr|second line<ul>.*?<li>indented|s,
     'nested lists should start correctly';
like $htmltext, qr|indented list.*?</li>.*?</ul>|s,
     '... and end correctly';

$wikitext =<<END_HERE;
* 1
* 2
** 2.1
*** 2.1.1
* 3

* 4
** 4.1
*** 4.1.1
*** 4.1.2
* 5
END_HERE

$htmltext = wf ($wikitext);

like $htmltext,
     qr|<ul>\s*
	<li>1</li>\s*
	<li>2<ul>\s*
	<li>2\.1<ul>\s*
	<li>2\.1\.1</li>\s*
	</ul>\s*
	</li>\s*
	</ul>\s*
	</li>\s*
	<li>3</li>\s*
	</ul>\s*
	<ul>\s*
	<li>4<ul>\s*
	<li>4\.1<ul>\s*
	<li>4\.1\.1</li>\s*
	<li>4\.1\.2</li>\s*
	</ul>\s*
	</li>\s*
	</ul>\s*
	</li>\s*
	<li>5</li>\s*
	</ul>|sx,
     'nesting should be correct for multiple levels';
like $htmltext, qr|<li>4<|s,
     'spaces should work instead of tabs';
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>
	\s*</li>|sx,
     'nesting should be correct for spaces too';


TODO: {
     local $TODO = 'Dictionary lists not nesting correctly.';

###
### Dictionary Lists
###
$wikitext =<<END_HERE;
; Term 1
: Def 1.1
:; Term 1.1.1 : Def 1.1.1.1
:; Term 1.1.2 : Def 1.1.2.1
:: Def 1.1.2.2
:; Term 1.1.3
:: Def 1.1.3.1
::; Term 1.1.3.1.1 : Def 1.1.3.1.1.1
; Term 2
: Def 2.1
: Def 2.2
:; Term 2.2.1 : Def 2.2.1.1
; Term 3 : Def 3.1
END_HERE

$htmltext = wf ($wikitext);

is $htmltext, '', 'dictionary lists nest correctly';

$wikitext =<<END_HERE;
; A
: A.a
:# A.a.1
:## A.a.1.1
:# A.a.2
:#* A.a.2.*
:#* A.a.2.*
:#*# A.a.2.*.1
: A.b
END_HERE

$htmltext = wf ($wikitext);

is $htmltext, '<dl>
<dt>A</dt>
<dd>A.a</dd>
<ol>
<li>A.a.1<ol>
<li>A.a.1.1</li>
</ol>
</li>
<li>A.a.2<ul>
<li>A.a.2.*</li>
<li>A.a.2.*<ol>
<li>A.a.2.*.1</li>
</ol>
</li>
</ul>
</li>
</ol>
<dd>A.b</dd>
</dl>
', 'lists nest correctly within dictionary lists';
};