#--- 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

EOT } # TestInsertIntoFile() #--- TestInsertIntoFileUsingTocUpdator() -------------------------------------- # function: Test 'HTML::TocUpdator->insertIntoFile() sub TestInsertIntoFileUsingTocUpdator { # 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 $tocUpdator = HTML::TocUpdator->new(); my $output; # Generate ToC $tocUpdator->insertIntoFile($toc, $filename, {'output' => \$output}); # Test ToC ok($output, <

Chapter

EOT } # TestInsertIntoFileUsingTocUpdator() #--- TestGlobalGroups0() ------------------------------------------------------ # function: Test 'HTML::TocGenerator' option 'doUseGroupsGlobal = 0'. sub TestGlobalGroups0 { # Assemble test file open(FILE, ">$filename") || die "Can't create $filename: $!"; print FILE <<'EOT'; close(FILE);

Chapter

Paragraph

EOT # Create objects my $toc1 = HTML::Toc->new(); my $toc2 = HTML::Toc->new(); my $tocGenerator = HTML::TocGenerator->new(); # Set options $toc1->setOptions({ 'header' => '', 'footer' => '', 'tokenToToc' => [{'tokenBegin' => '

'}] }); $toc2->setOptions({ 'header' => '', 'footer' => '', 'tokenToToc' => [{'tokenBegin' => '

'}] }); # Generate ToC $tocGenerator->generateFromFile([$toc1, $toc2], $filename); # Test ToC ok($toc1->format() . $toc2->format() . "\n", <<'EOT'); EOT } # TestGlobalGroups0() #--- TestGlobalGroups1() ------------------------------------------------------ # function: Test 'HTML::TocGenerator' option 'doUseGroupsGlobal = 0'. sub TestGlobalGroups1 { # Assemble test file open(FILE, ">$filename") || die "Can't create $filename: $!"; print FILE <<'EOT';

Chapter

Paragraph

EOT close(FILE); # Create objects my $toc1 = HTML::Toc->new(); my $toc2 = HTML::Toc->new(); my $tocGenerator = HTML::TocGenerator->new(); # Set options $toc1->setOptions({ 'header' => '', 'footer' => '', 'tokenToToc' => [{'tokenBegin' => '

'}] }); $toc2->setOptions({ 'header' => '', 'footer' => '', 'tokenToToc' => [{'tokenBegin' => '

'}] }); # Generate ToC $tocGenerator->generateFromFile( [$toc1, $toc2], $filename, {'doUseGroupsGlobal' => 1} ); # Test ToC ok($toc1->format() . $toc2->format() . "\n", <<'EOT'); EOT } # TestGlobalGroups1() #--- TestMultipleGroupsAppendix() --------------------------------------------- # function: Test multiple ToCs sub TestMultipleGroupsAppendix() { # Create objects my $toc = HTML::Toc->new(); my $tocInsertor = HTML::TocInsertor->new(); my $output; # Set ToC options $toc->setOptions({ 'tokenToToc' => [{ 'tokenBegin' => '

' }, { 'tokenBegin' => '

', 'level' => 2 }, { 'groupId' => 'appendix', 'tokenBegin' => '

', }, { 'groupId' => 'appendix', 'tokenBegin' => '

', 'level' => 2 }], }); # Generate ToC $tocInsertor->insert($toc, < \$output});

Chapter

Paragraph

Subparagraph

Chapter

Appendix Chapter

Appendix Paragraph

EOT # Test ToC ok($output, <

Chapter

Paragraph

Subparagraph

Chapter

Appendix Chapter

Appendix Paragraph

EOT } # TestMultipleGroupsAppendix() #--- TestMultipleGroupsPart() ------------------------------------------------- # function: Test multiple ToCs sub TestMultipleGroupsPart() { # Create objects my $toc = HTML::Toc->new(); my $tocInsertor = HTML::TocInsertor->new(); my $output; # Set ToC options $toc->setOptions({ 'tokenToToc' => [{ 'tokenBegin' => '

' }, { 'tokenBegin' => '

', 'level' => 2, }, { 'groupId' => 'part', 'tokenBegin' => '

', 'level' => 1, 'doNumberToken' => 1, 'numberingStyle' => 'upper-alpha' }] }); # Generate ToC $tocInsertor->insert($toc, < \$output});

First Part

Chapter

Paragraph

Second Part

Chapter

Paragraph

EOT # Test ToC ok($output, <

A  First Part

Chapter

Paragraph

B  Second Part

Chapter

Paragraph

EOT } # TestMultipleGroupsPart() #--- TestMultipleTocs() ------------------------------------------------------- # function: Test multiple ToCs sub TestMultipleTocs() { # Assemble test file open(FILE, ">$filename") || die "Can't create $filename: $!"; print FILE <<'EOT'; close(FILE);

Header One

First picture

Paragraph One

Second picture EOT # Create objects my $toc1 = HTML::Toc->new(); my $toc2 = HTML::Toc->new(); my $tocInsertor = HTML::TocInsertor->new(); my $output; # Set ToC options $toc2->setOptions({ 'tokenToToc' => [{ 'groupId' => 'image', 'tokenBegin' => '@' }], }); # Generate ToC $tocInsertor->insertIntoFile( [$toc1, $toc2], $filename, {'output' => \$output} ); # Test ToC ok($output, <

Header One

First picture

Paragraph One

Second picture EOT } # TestMultipleTocs() #--- TestSpecifyNumberedList() ------------------------------------------------ # function: Test specifying numbered list. sub TestSpecifyNumberedList { # Assemble test file open(FILE, ">$filename") || die "Can't create $filename: $!"; print FILE <<'EOT'; close(FILE);

Chapter

Paragraph

EOT # Create objects my $toc = HTML::Toc->new(); my $tocGenerator = HTML::TocGenerator->new(); # Set ToC options $toc->setOptions({ 'templateLevelBegin' => '"
    \n"', 'templateLevelEnd' => '"
\n"', }); # Generate ToC $tocGenerator->generateFromFile($toc, $filename); # Test ToC ok($toc->format(), <
  1. Chapter
    1. Paragraph
EOT } # TestSpecifyNumberedList() #--- TestUpdateFile() --------------------------------------------------------- # function: Test 'HTML::TocUpdator->updateFile()' sub TestUpdateFile { # Assemble test file open(FILE, ">$filename") || die "Can't create $filename: $!"; print FILE <<'EOT'; close(FILE); foo bar

Chapter

foo EOT # Create objects my $toc = HTML::Toc->new(); my $tocUpdator = HTML::TocUpdator->new(); my $output; # Generate ToC $tocUpdator->updateFile($toc, $filename, {'output' => \$output}); # Test ToC ok($output, <

Chapter

EOT } # TestUpdateFile() #--- TestUsingCSS() ----------------------------------------------------------- # function: Test multiple ToCs sub TestUsingCSS() { # Create objects my $toc = new HTML::Toc; my $tocInsertor = new HTML::TocInsertor; my $output; $toc->setOptions({ 'templateLevelBegin' => '"
    \n"', 'templateLevelEnd' => '"
\n"', 'doNumberToken' => 1, 'tokenToToc' => [{ 'groupId' => 'appendix', 'tokenBegin' => '

', 'numberingStyle' => 'upper-alpha' }, { 'groupId' => 'appendix', 'tokenBegin' => '

', 'level' => 2, }] }); $tocInsertor->insert($toc, <

Appendix

Appendix Paragraph

Appendix

Appendix Paragraph

EOT # Insert ToC $tocInsertor->insert($toc, < \$output});

Appendix

Appendix Paragraph

Appendix

Appendix Paragraph

EOT # Test ToC ok($output, <
  1. Appendix
    1. Appendix Paragraph
  2. Appendix
    1. Appendix Paragraph

A  Appendix

A.1  Appendix Paragraph

B  Appendix

B.1  Appendix Paragraph

EOT } # TestUsingCSS() # Test 'extendFromFile()' TestExtendFromFile(); # Test 'generateFromFile()' TestGenerateFromFile(); # Test 'generateFromFiles()' TestGenerateFromFiles(); # Test 'doUseGroupsGlobal = 0' TestGlobalGroups0(); # Test 'doUseGroupsGlobal = 1' TestGlobalGroups1(); # Test 'tocInsertor->insertIntoFile' TestInsertIntoFile(); # Test 'tocUpdator->insertIntoFile' TestInsertIntoFileUsingTocUpdator(); # Test additional 'appendix' group TestMultipleGroupsAppendix(); # Test additional 'part' group TestMultipleGroupsPart(); # Test multiple ToCs TestMultipleTocs(); # Test specifying numbered list TestSpecifyNumberedList(); # Test 'updateFile()' TestUpdateFile(); # Test using CSS TestUsingCSS();