File: 020_strings.t

package info (click to toggle)
libhtml-gentoc-perl 3.20-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 436 kB
  • ctags: 60
  • sloc: perl: 1,173; php: 51; makefile: 2
file content (200 lines) | stat: -rw-r--r-- 4,047 bytes parent folder | download | duplicates (4)
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
use Test::More tests => 7;
use HTML::GenToc;

# Insert your test code below
#===================================================

$toc = new HTML::GenToc(debug=>0,
	quiet=>1);

#----------------------------------------------------------
# string input and output
$html1 ="<h1>Cool header</h1>
<p>This is a paragraph.</p>
<h2>Getting Cooler</h2>
<p>Another paragraph.</p>
";

$html2 ="<h1><a name=\"Cool_header\">Cool header</a></h1>
<p>This is a paragraph.</p>
<h2><a name=\"Getting_Cooler\">Getting Cooler</a></h2>
<p>Another paragraph.</p>
";

$out_str = $toc->generate_toc(
    make_anchors=>1,
    make_toc=>0,
    to_string=>1,
    filenames=>["fred.html"],
    input=>$html1,
    toc_entry=>{
	'H1' =>1,
	'H2' =>2,
    },
    toc_end=>{
	'H1' =>'/H1',
	'H2' =>'/H2',
    },
);

is($out_str, $html2, "(1) generate_anchors matches strings");

$out_str = $toc->generate_toc(
    make_anchors=>0,
    make_toc=>1,
    to_string=>1,
    filenames=>["fred.html"],
    input=>$html2,
);

$ok_toc_str1='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML//EN">
<html>
<head>
<title>Table of Contents</title>
</head>
<body>
<h1>Table of Contents</h1>
<ul><li><a href="fred.html#Cool_header">Cool header</a>
<ul><li><a href="fred.html#Getting_Cooler">Getting Cooler</a></li>
</ul></li>
</ul>
</body>
</html>
';

is($out_str, $ok_toc_str1, "(2) generate_toc matches toc string");

$out_str = $toc->generate_toc(
    make_anchors=>0,
    make_toc=>1,
    to_string=>1,
    filenames=>["fred.html"],
    input=>$html2,
    inline=>1,
    toc_tag=>'/H1',
    toc_tag_replace=>0,
    toclabel=>'',
);

$ok_toc_str2='<h1><a name="Cool_header">Cool header</a></h1>
<ul><li><a href="#Cool_header">Cool header</a>
<ul><li><a href="#Getting_Cooler">Getting Cooler</a></li>
</ul></li>
</ul>

<p>This is a paragraph.</p>
<h2><a name="Getting_Cooler">Getting Cooler</a></h2>
<p>Another paragraph.</p>
';

is($out_str, $ok_toc_str2, "(3) generate_toc matches inline toc string");

#
# Reset
undef $toc;
$toc = new HTML::GenToc(debug=>0,
	quiet=>1);

$html1 ="<h1>Cool header</h1>
<p>This is a paragraph.</p>
<h2>Getting Cooler</h2>
<p>Another paragraph.</p>
";

$html2 ="<h1 id='Cool_header'>Cool header</h1>
<p>This is a paragraph.</p>
<h2 id='Getting_Cooler'>Getting Cooler</h2>
<p>Another paragraph.</p>
";

$out_str = $toc->generate_toc(
    make_anchors=>1,
    make_toc=>0,
    to_string=>1,
    use_id=>1,
    filenames=>["fred.html"],
    input=>$html1,
    toc_entry=>{
	'H1' =>1,
	'H2' =>2,
    },
    toc_end=>{
	'H1' =>'/H1',
	'H2' =>'/H2',
    },
);

is($out_str, $html2, "(4) generate_anchors (id) matches strings");

$out_str = $toc->generate_toc(
    make_anchors=>0,
    make_toc=>1,
    to_string=>1,
    filenames=>["fred.html"],
    input=>$html2,
);

$ok_toc_str1='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML//EN">
<html>
<head>
<title>Table of Contents</title>
</head>
<body>
<h1>Table of Contents</h1>
<ul><li><a href="fred.html#Cool_header">Cool header</a>
<ul><li><a href="fred.html#Getting_Cooler">Getting Cooler</a></li>
</ul></li>
</ul>
</body>
</html>
';

is($out_str, $ok_toc_str1, "(5) generate_toc (id) matches toc string");

# ignore sole first
$out_str = $toc->generate_toc(
    make_anchors=>0,
    make_toc=>1,
    to_string=>1,
    filenames=>["fred.html"],
    ignore_sole_first=>1,
    input=>$html2,
);

$ok_toc_str1='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML//EN">
<html>
<head>
<title>Table of Contents</title>
</head>
<body>
<h1>Table of Contents</h1>
<ul><li><a href="fred.html#Getting_Cooler">Getting Cooler</a></li>
</ul>
</body>
</html>
';

is($out_str, $ok_toc_str1, "(6) generate_toc (ignore_sole_first) matches toc string");

# ignore_only_one
$html1 =<<EOT;
<h1>Cool header</h1>
<p>This is a paragraph.</p>
EOT

$out_str = $toc->generate_toc(
    to_string=>1,
    use_id=>1,
    inline=>1,
    ignore_only_one=>1,
    toc_tag=>'/h1',
    input=>$html1,
);

$ok_toc_str1 =<<EOT;
<h1 id='Cool_header'>Cool header</h1>

<p>This is a paragraph.</p>
EOT

is($out_str, $ok_toc_str1, "(7) generate_toc (ignore_only_one) matches string");