use Test::More tests => 7; use HTML::GenToc; # Insert your test code below #=================================================== $toc = new HTML::GenToc(debug=>0, quiet=>1); #---------------------------------------------------------- # string input and output $html1 ="

Cool header

This is a paragraph.

Getting Cooler

Another paragraph.

"; $html2 ="

Cool header

This is a paragraph.

Getting Cooler

Another paragraph.

"; $out_str = $toc->generate_toc( make_anchors=>1, make_toc=>0, to_string=>1, filenames=>["fred.html"], input=>$html1, toc_entry=>{ 'H1' =>1, 'H2' =>2, }, toc_end=>{ 'H1' =>'/H1', 'H2' =>'/H2', }, ); is($out_str, $html2, "(1) generate_anchors matches strings"); $out_str = $toc->generate_toc( make_anchors=>0, make_toc=>1, to_string=>1, filenames=>["fred.html"], input=>$html2, ); $ok_toc_str1=' Table of Contents

Table of Contents

'; is($out_str, $ok_toc_str1, "(2) generate_toc matches toc string"); $out_str = $toc->generate_toc( make_anchors=>0, make_toc=>1, to_string=>1, filenames=>["fred.html"], input=>$html2, inline=>1, toc_tag=>'/H1', toc_tag_replace=>0, toclabel=>'', ); $ok_toc_str2='

Cool header

This is a paragraph.

Getting Cooler

Another paragraph.

'; is($out_str, $ok_toc_str2, "(3) generate_toc matches inline toc string"); # # Reset undef $toc; $toc = new HTML::GenToc(debug=>0, quiet=>1); $html1 ="

Cool header

This is a paragraph.

Getting Cooler

Another paragraph.

"; $html2 ="

Cool header

This is a paragraph.

Getting Cooler

Another paragraph.

"; $out_str = $toc->generate_toc( make_anchors=>1, make_toc=>0, to_string=>1, use_id=>1, filenames=>["fred.html"], input=>$html1, toc_entry=>{ 'H1' =>1, 'H2' =>2, }, toc_end=>{ 'H1' =>'/H1', 'H2' =>'/H2', }, ); is($out_str, $html2, "(4) generate_anchors (id) matches strings"); $out_str = $toc->generate_toc( make_anchors=>0, make_toc=>1, to_string=>1, filenames=>["fred.html"], input=>$html2, ); $ok_toc_str1=' Table of Contents

Table of Contents

'; is($out_str, $ok_toc_str1, "(5) generate_toc (id) matches toc string"); # ignore sole first $out_str = $toc->generate_toc( make_anchors=>0, make_toc=>1, to_string=>1, filenames=>["fred.html"], ignore_sole_first=>1, input=>$html2, ); $ok_toc_str1=' Table of Contents

Table of Contents

'; is($out_str, $ok_toc_str1, "(6) generate_toc (ignore_sole_first) matches toc string"); # ignore_only_one $html1 =<Cool header

This is a paragraph.

EOT $out_str = $toc->generate_toc( to_string=>1, use_id=>1, inline=>1, ignore_only_one=>1, toc_tag=>'/h1', input=>$html1, ); $ok_toc_str1 =<Cool header

This is a paragraph.

EOT is($out_str, $ok_toc_str1, "(7) generate_toc (ignore_only_one) matches string");