Home | History | Annotate | Download | only in t
      1 #--- manual.t -----------------------------------------------------------------
      2 # function: Test HTML::ToC generating a manual.
      3 
      4 use strict;
      5 use Test;
      6 
      7 BEGIN { plan tests => 1; }
      8 
      9 use Data::Dumper;
     10 use File::Find;
     11 use HTML::Toc;
     12 use HTML::TocGenerator;
     13 use HTML::TocInsertor;
     14 use HTML::TocUpdator;
     15 
     16 
     17 	# Create objects
     18 my $toc          = HTML::Toc->new();
     19 my $tocGenerator = HTML::TocGenerator->new();
     20 my @fileList;
     21 
     22 
     23 #--- TestSiteMap() ------------------------------------------------------------
     24 # function: Test specifying numbered list.
     25 
     26 sub TestSiteMap {
     27 		# Set ToC options
     28 	$toc->setOptions({
     29 		'doLinkToFile'       => 1,
     30 		'templateAnchorName' => '""',
     31 		'templateAnchorHref' => '"<a href=$file"."#".$groupId.$level.">"',
     32 		'doLinkTocToToken'   => 1,
     33 		'tokenToToc'         => [{
     34 			'groupId'         => 'dir',
     35 			'level'           => 1,
     36 			'tokenBegin'      => '<title>',
     37 			'tokenEnd'        => '</title>',
     38 			'fileSpec'        => '\./[^/]+$'
     39 		}, {
     40 			'groupId'         => 'dir',
     41 			'level'           => 2,
     42 			'tokenBegin'      => '<title>',
     43 			'tokenEnd'        => '</title>',
     44 			'fileSpec'        => '\./[^/]+?/[^/]+$'
     45 		}, {
     46 			'groupId'         => 'dir',
     47 			'level'           => 3,
     48 			'tokenBegin'      => '<title>',
     49 			'tokenEnd'        => '</title>',
     50 			'fileSpec'        => '\./[^/]+?/[^/]+?/[^/]+$'
     51 		}]
     52 	});
     53 		# Change current directory
     54 	chdir("t/SiteMap");
     55 		# Find files, filling 'fileList'
     56 	find({wanted => \&WantedSiteMap, no_chdir => 1}, '.');
     57 		# Generate ToC of case-insensitively sorted file list
     58 	$tocGenerator->extendFromFile(
     59 		$toc, [sort {uc($a) cmp uc($b)} @fileList]
     60 	);
     61 		# Restore current directory
     62 	chdir("../..");
     63 		# Test ToC
     64 	ok($toc->format(), <<EOT);
     65 
     66 <!-- Table of Contents generated by Perl - HTML::Toc -->
     67 <ul>
     68    <li><a href=./index.htm#>Main</a>
     69    <ul>
     70       <li><a href=./SubDir1/index.htm#>Sub1</a>
     71       <ul>
     72          <li><a href=./SubDir1/SubSubDir1/index.htm#>SubSub1</a>
     73       </ul>
     74       <li><a href=./SubDir2/index.htm#>Sub2</a>
     75       <ul>
     76          <li><a href=./SubDir2/SubSubDir1/index.htm#>SubSub1</a>
     77          <li><a href=./SubDir2/SubSubDir2/index.htm#>SubSub2</a>
     78       </ul>
     79       <li><a href=./SubDir3/index.htm#>Sub3</a>
     80    </ul>
     81 </ul>
     82 <!-- End of generated Table of Contents -->
     83 EOT
     84 }  # TestSiteMap()
     85 
     86 
     87 #--- WantedSiteMap() ----------------------------------------------------------
     88 # function: 'Wanted' function, used by File::Find of 'TestSiteMap()'.
     89 
     90 sub WantedSiteMap {
     91 		# Add file to 'fileList' if extension matches '.htm'
     92 	push (@fileList, $File::Find::name) if (m/\.htm$/);
     93 } # WantedSiteMap()
     94 
     95 
     96 	# Test site map
     97 TestSiteMap();
     98