HTML-Toc
view release on metacpan or search on metacpan
t/options.t view on Meta::CPAN
#--- options.t ----------------------------------------------------------------
# function: Test HTML::ToC. In particular test the available options.
use strict;
use Test::More tests => 5;
use Test::Differences;
use HTML::Toc;
use HTML::TocGenerator;
use HTML::TocInsertor;
use HTML::TocUpdator;
my ($filename);
BEGIN {
# Create test file
$filename = "file$$.htm";
die "$filename is already there" if -e $filename;
}
END {
# Remove test file
unlink($filename) or warn "Can't unlink $filename: $!";
}
#--- TestAttributeToExcludeToken() --------------------------------------------
# function: Test 'HTML::Toc' option 'attributeToExcludeToken'
sub TestAttributeToExcludeToken {
# Assemble test file
open(FILE, ">$filename") || die "Can't create $filename: $!";
print FILE <<'EOT'; close(FILE);
<body>
<h1>Chapter 1</h1>
<h1 class="appendix">Appendix</h1>
</body>
EOT
# Create objects
my $toc = HTML::Toc->new();
my $tocGenerator = HTML::TocGenerator->new();
$toc->setOptions({
'attributeToExcludeToken' => 'foo',
'tokenToToc' => [{
'tokenBegin' => '<h1 class="foodix">'
}]
});
# Generate ToC
$tocGenerator->generateFromFile($toc, $filename);
# Test ToC
eq_or_diff($toc->format(), <<EOT, "'HTML::Toc' option 'attributeToExcludeToken'", {max_width => 120});
<!-- Table of Contents generated by Perl - HTML::Toc -->
<ul>
<li><a href="#h-1">Chapter 1</a></li>
</ul>
<!-- End of generated Table of Contents -->
EOT
} # TestAttributeToExcludeToken()
#--- TestAttributeToTocToken() ------------------------------------------------
# function: Test 'HTML::Toc' option 'attributeToTocToken'
( run in 0.560 second using v1.01-cache-2.11-cpan-e1769b4cff6 )