#--- update.t -----------------------------------------------------------------
# function: Test ToC updating.
use strict;
use Test;
BEGIN { plan tests => 6; }
use HTML::Toc;
use HTML::TocUpdator;
my ($output, $output2, $content, $filename);
my $toc = HTML::Toc->new;
my $tocUpdator = HTML::TocUpdator->new;
$toc->setOptions({
'doLinkToToken' => 1,
'doNumberToken' => 1,
'levelIndent' => 0,
'insertionPoint' => 'before
',
'header' => '',
'footer' => '',
});
BEGIN {
# Create test file
$filename = "file$$.htm";
die "$filename is already there" if -e $filename;
open(FILE, ">$filename") || die "Can't create $filename: $!";
print FILE <<'EOT'; close(FILE);
Header
EOT
}
END {
# Remove test file
unlink($filename) or warn "Can't unlink $filename: $!";
}
#--- 1. update ----------------------------------------------------------------
$tocUpdator->update($toc, "Header
", {'output' => \$output});
ok("$output\n", <<'EOT');
1 Header
EOT
#--- 2. updateFile ------------------------------------------------------------
$tocUpdator->updateFile($toc, $filename, {'output' => \$output});
open(FILE, ">a.out1") || die "Can't create a.out1: $!";
print FILE $output; close(FILE);
$output2 = <<'EOT';
1 Header
EOT
open(FILE, ">a.out2") || die "Can't create a.out2: $!";
print FILE $output2; close(FILE);
ok($output, $output2);
#--- 3. insert ----------------------------------------------------------------
$tocUpdator->insert($toc, "Header
", {'output' => \$output});
ok("$output\n", <<'EOT');
1 Header
EOT
#--- 4. insertIntoFile --------------------------------------------------------
$tocUpdator->insertIntoFile($toc, $filename, {'output' => \$output});
ok($output, <<'EOT');
1 Header
EOT
#--- 5. update twice ----------------------------------------------------------
$tocUpdator->update($toc, "Header
", {'output' => \$output});
$tocUpdator->update($toc, $output, {'output' => \$output2});
ok("$output\n", <<'EOT');
1 Header
EOT
#--- 6. tokens update begin & end ---------------------------------------------
$toc->setOptions({
'tokenUpdateBeginOfAnchorNameBegin' => '',
'tokenUpdateEndOfAnchorNameBegin' => '',
'tokenUpdateBeginOfAnchorNameEnd' => '',
'tokenUpdateEndOfAnchorNameEnd' => '',
'tokenUpdateBeginNumber' => '',
'tokenUpdateEndNumber' => '',
'tokenUpdateBeginToc' => '',
'tokenUpdateEndToc', => ''
});
$tocUpdator->update($toc, "Header
", {'output' => \$output});
ok("$output\n", <<'EOT');
1 Header
EOT