MojoMojo
view release on metacpan or search on metacpan
t/formatter_toc.t view on Meta::CPAN
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
eval 'use HTML::Toc';
if ($@) {
plan skip_all => "need HTML::Toc to run this test\n";
}
use MojoMojo::Formatter::TOC;
use Test::Differences;
#--- Basic functionality --------------------------------------------
my $content = <<HTML;
{{toc}}
<h1>Chapter 1</h1>
Some text here
<h1>Chapter 2</h1>
Second chapter
HTML
MojoMojo::Formatter::TOC->format_content(\$content);
eq_or_diff($content, <<'EOT', 'basic functionality') or BAIL_OUT("Basic functionality failure");
<div class="toc">
<ul>
<li><a href="#Chapter_1">Chapter 1</a></li>
<li><a href="#Chapter_2">Chapter 2</a></li>
</ul>
</div>
<h1><a name="Chapter_1"></a>Chapter 1</h1>
Some text here
<h1><a name="Chapter_2"></a>Chapter 2</h1>
Second chapter
EOT
# ------------------------------------------------------------------------------
# --- Sanity check for replacing text around {{toc}} http://rt.cpan.org/Ticket/Display.html?id=43797
# ------------------------------------------------------------------------------
$content = "The toc should go {{toc}} here.<h1>Chapter 1</h1>\n";
MojoMojo::Formatter::TOC->format_content(\$content);
eq_or_diff($content, <<'HTML', 'the insertionPoint token must not obliterate the text around it - RT # 43797');
The toc should go <div class="toc">
<ul>
<li><a href="#Chapter_1">Chapter 1</a></li>
</ul>
</div> here.<h1><a name="Chapter_1"></a>Chapter 1</h1>
HTML
# ------------------------------------------------------------------------------
# --- Short test of character set in anchor names - must be [A-Za-z0-9_:.-] only
# ------------------------------------------------------------------------------
$content = <<'HTML';
{{toc}}
<h1>行政区域</h1>
Per http://www.w3.org/TR/REC-html40/struct/links.html#h-12.2.1,
“Anchor names should be restricted to ASCII characters.”,
and MediaWiki does that too (see http://zh.wikipedia.org/wiki/刚果民主共和国)
HTML
MojoMojo::Formatter::TOC->format_content(\$content);
eq_or_diff($content, <<'HTML', 'short test of character set in anchor names', {max_width => 120});
<div class="toc">
<ul>
<li><a href="#L.E8.A1.8C.E6.94.BF.E5.8C.BA.E5.9F.9F">行政区域</a></li>
</ul>
</div>
<h1><a name="L.E8.A1.8C.E6.94.BF.E5.8C.BA.E5.9F.9F"></a>行政区域</h1>
( run in 0.957 second using v1.01-cache-2.11-cpan-437f7b0c052 )