#--- podExamples.t ------------------------------------------------------------
# function: Test HTML::ToC. In particular test the examples as described in
# the POD documentation.
use strict;
use Test;
BEGIN { plan tests => 13; }
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);
Chapter of document 1
EOT
# Assemble test file 2
open(FILE, ">$filename2") || die "Can't create $filename2: $!";
print FILE <<'EOT'; close(FILE);
Chapter of document 2
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
ok($toc->format(), <
EOT
} # TestExtendFromFile()
#--- TestGenerateFromFiles() --------------------------------------------------
# function: Test 'HTML::TocGenerator->generateFromFile()
sub TestGenerateFromFiles {
# Assemble test file
open(FILE, ">$filename") || die "Can't create $filename: $!";
print FILE <<'EOT'; close(FILE);
Chapter of document 1
EOT
# Assemble test file 2
open(FILE, ">$filename2") || die "Can't create $filename2: $!";
print FILE <<'EOT'; close(FILE);
Chapter of document 2
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, $filename2]);
# Test ToC
ok($toc->format(), <
EOT
} # TestGenerateFromFiles()
#--- TestGenerateFromFiles() --------------------------------------------------
# function: Test 'HTML::TocGenerator->generateFromFile() using multiple files.
sub TestGenerateFromFile {
# Assemble test file 1
open(FILE, ">$filename") || die "Can't create $filename: $!";
print FILE <<'EOT'; close(FILE);
Chapter
EOT
# Create objects
my $toc = HTML::Toc->new();
my $tocGenerator = HTML::TocGenerator->new();
# Generate ToC
$tocGenerator->generateFromFile($toc, $filename);
# Test ToC
ok($toc->format(), <
EOT
} # TestGenerateFromFile()
#--- TestInsertIntoFile() -----------------------------------------------------
# function: Test 'HTML::TocInsertor->insertIntoFile()
sub TestInsertIntoFile {
# Assemble test file
open(FILE, ">$filename") || die "Can't create $filename: $!";
print FILE <<'EOT'; close(FILE);
Chapter
EOT
# Create objects
my $toc = HTML::Toc->new();
my $tocInsertor = HTML::TocInsertor->new();
my $output;
# Generate ToC
$tocInsertor->insertIntoFile($toc, $filename, {'output' => \$output});
# Test ToC
ok($output, <
Chapter