#--- options.t ---------------------------------------------------------------- # function: Test HTML::ToC. In particular test the available options. use strict; use Test; BEGIN { plan tests => 5; } 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);

Chapter 1

Appendix

EOT # Create objects my $toc = HTML::Toc->new(); my $tocGenerator = HTML::TocGenerator->new(); $toc->setOptions({ 'attributeToExcludeToken' => 'foo', 'tokenToToc' => [{ 'tokenBegin' => '

' }] }); # Generate ToC $tocGenerator->generateFromFile($toc, $filename); # Test ToC ok($toc->format(), < EOT } # TestAttributeToExcludeToken() #--- TestAttributeToTocToken() ------------------------------------------------ # function: Test 'HTML::Toc' option 'attributeToTocToken' sub TestAttributeToTocToken { # Assemble test file open(FILE, ">$filename") || die "Can't create $filename: $!"; print FILE <<'EOT'; close(FILE); Picture EOT # Create objects my $toc = HTML::Toc->new(); my $tocGenerator = HTML::TocGenerator->new(); $toc->setOptions({ 'attributeToTocToken' => 'foo', 'tokenToToc' => [{ 'groupId' => 'image', 'tokenBegin' => 'foo' }], }); # Generate ToC $tocGenerator->generateFromFile($toc, $filename); # Test ToC ok($toc->format(), < EOT } # TestAttributeToTocToken() #--- TestNumberingStyleDecimal ------------------------------------------------ # function: Test 'decimal' numbering style. sub TestNumberingStyleDecimal { # Local variables my $output; # Create objects my $toc = HTML::Toc->new(); my $tocInsertor = HTML::TocInsertor->new(); $toc->setOptions({ 'doNumberToken' => 1, 'tokenToToc' => [{ 'level' => 1, 'tokenBegin' => '

', 'numberingStyle' => 'decimal' }], }); # Generate ToC $tocInsertor->insert($toc, "

Header

", {'output' => \$output}); # Test ToC ok("$output\n", <

1  Header

EOT } # TestNumberingStyleDecimal() #--- TestNumberingStyleLowerAlpha --------------------------------------------- # function: Test 'lower-alpha' numbering style. sub TestNumberingStyleLowerAlpha { # Local variables my $output; # Create objects my $toc = HTML::Toc->new(); my $tocInsertor = HTML::TocInsertor->new(); $toc->setOptions({ 'doNumberToken' => 1, 'tokenToToc' => [{ 'level' => 1, 'tokenBegin' => '

', 'numberingStyle' => 'lower-alpha' }], }); # Generate ToC $tocInsertor->insert($toc, "

Header

", {'output' => \$output}); # Test ToC ok("$output\n", <

a  Header

EOT } # TestNumberingStyleLowerAlpha() #--- TestNumberingStyleUpperAlpha --------------------------------------------- # function: Test 'upper-alpha' numbering style. sub TestNumberingStyleUpperAlpha { # Local variables my $output; # Create objects my $toc = HTML::Toc->new(); my $tocInsertor = HTML::TocInsertor->new(); $toc->setOptions({ 'doNumberToken' => 1, 'tokenToToc' => [{ 'level' => 1, 'tokenBegin' => '

', 'numberingStyle' => 'upper-alpha' }], }); # Generate ToC $tocInsertor->insert($toc, "

Header

", {'output' => \$output}); # Test ToC ok("$output\n", <

A  Header

EOT } # TestNumberingStyleUpperAlpha() # Test 'attributeToTocToken' TestAttributeToTocToken(); # Test 'attributeToExcludeToken' TestAttributeToExcludeToken(); # Test 'numberingStyleDecimal' TestNumberingStyleDecimal(); # Test 'numberingStyleLowerAlpha' TestNumberingStyleLowerAlpha(); # Test 'numberingStyleUpperAlpha' TestNumberingStyleUpperAlpha();