HTML-Toc
view release on metacpan or search on metacpan
t/podExamples.t view on Meta::CPAN
#--- podExamples.t ------------------------------------------------------------
# function: Test HTML::ToC. In particular test the examples as described in
# the POD documentation.
use strict;
use Test::More tests => 16;
use Test::Differences;
use HTML::Toc;
use HTML::TocGenerator;
use HTML::TocInsertor;
use HTML::TocUpdator;
my ($filename, $filename2);
BEGIN {
# Create test file
$filename = "tmp.htm";
die "$filename is already there" if -e $filename;
# Create test file 2
$filename2 = "tmp2.htm";
die "$filename2 is already there" if -e $filename2;
}
END {
# Remove test file
unlink($filename) or warn "Can't unlink $filename: $!";
# Remove test file 2
unlink($filename2) or warn "Can't unlink $filename2: $!";
}
#--- TestExtendFromFile() --------------------------------------------------
# function: Test HTML::TocGenerator->extendFromFile()
sub TestExtendFromFile {
# Assemble test file
open(FILE, ">$filename") || die "Can't create $filename: $!";
print FILE <<'EOT'; close(FILE);
<body>
<h1>Chapter of document 1</h1>
</body>
EOT
# Assemble test file 2
open(FILE, ">$filename2") || die "Can't create $filename2: $!";
print FILE <<'EOT'; close(FILE);
<body>
<h1>Chapter of document 2</h1>
</body>
EOT
# Create objects
my $toc = HTML::Toc->new();
my $tocGenerator = HTML::TocGenerator->new();
# Set ToC options
$toc->setOptions({'doLinkToFile' => 1});
# Generate ToC
$tocGenerator->generateFromFile($toc, $filename);
$tocGenerator->extendFromFile($toc, $filename2);
# Test ToC
eq_or_diff($toc->format(), <<EOT, 'Test HTML::TocGenerator->extendFromFile()', {max_width=>120});
<!-- Table of Contents generated by Perl - HTML::Toc -->
( run in 0.709 second using v1.01-cache-2.11-cpan-e1769b4cff6 )