use strict; use Test::More; use HTML::Tiny; # We have 100% coverage without these tests. Consider these extra # security against something getting twisted out of shape. my %schedule; BEGIN { my @common_schedule = ( { "expect_list" => [ "Hexten", "CPAN Search" ], "args" => [ { "href" => "http://hexten.net" }, "Hexten", { "href" => "http://search.cpan.org" }, "CPAN Search" ], "expect_scalar" => "HextenCPAN Search", "method" => "a" }, { "expect_list" => [ "one", "two" ], "args" => [ "one", "two" ], "expect_scalar" => "onetwo", "method" => "abbr" }, { "expect_list" => [ "one", "two" ], "args" => [ {}, "one", { x => 1 }, { x => undef }, "two" ], "expect_scalar" => "onetwo", "method" => "acronym" }, { "expect_list" => [ "
onetwo
", "
threefour
" ], "args" => [ [ "one", "two" ], [ "three", "four" ] ], "expect_scalar" => "
onetwo
threefour
", "method" => "address" }, { "expect_list" => ["two"], "args" => [ "one", "two" ], "expect_scalar" => "two", "method" => "auto_tag" }, { "expect_list" => [ "one", "two" ], "args" => [ "one", "two" ], "expect_scalar" => "onetwo", "method" => "b" }, { "expect_list" => [ "one", "two" ], "args" => [ "one", "two" ], "expect_scalar" => "onetwo", "method" => "bdo" }, { "expect_list" => [ "one", "two" ], "args" => [ "one", "two" ], "expect_scalar" => "onetwo", "method" => "big" }, { "expect_list" => [ "
one
", "
two
" ], "args" => [ "one", "two" ], "expect_scalar" => "
one
two
", "method" => "blockquote" }, { "expect_list" => [ "one\n", "two\n" ], "args" => [ "one", "two" ], "expect_scalar" => "one\ntwo\n", "method" => "body" }, { "expect_list" => [ "", "" ], "args" => [ "one", "two" ], "expect_scalar" => "", "method" => "button" }, { "expect_list" => [ "one", "two" ], "args" => [ "one", "two" ], "expect_scalar" => "onetwo", "method" => "caption" }, { "expect_list" => [ "one", "two" ], "args" => [ "one", "two" ], "expect_scalar" => "onetwo", "method" => "cite" }, { "expect_list" => [""], "args" => ["tag"], "expect_scalar" => "", "method" => "close" }, { "expect_list" => [ "one", "two" ], "args" => [ "one", "two" ], "expect_scalar" => "onetwo", "method" => "code" }, { "expect_list" => [ "one", "two" ], "args" => [ "one", "two" ], "expect_scalar" => "onetwo", "method" => "colgroup" }, { "expect_list" => [ "
one
", "
two
" ], "args" => [ "one", "two" ], "expect_scalar" => "
one
two
", "method" => "dd" }, { "expect_list" => [ "one", "two" ], "args" => [ "one", "two" ], "expect_scalar" => "onetwo", "method" => "del" }, { "expect_list" => [ "one", "two" ], "args" => [ "one", "two" ], "expect_scalar" => "onetwo", "method" => "dfn" }, { "expect_list" => [ "
one
\n", "
two
\n" ], "args" => [ "one", "two" ], "expect_scalar" => "
one
\n
two
\n", "method" => "div" }, { "expect_list" => [ "
one
", "
two
" ], "args" => [ "one", "two" ], "expect_scalar" => "
one
two
", "method" => "dl" }, { "expect_list" => [ "
one
", "
two
" ], "args" => [ "one", "two" ], "expect_scalar" => "
one
two
", "method" => "dt" }, { "expect_list" => [ "one", "two" ], "args" => [ "one", "two" ], "expect_scalar" => "onetwo", "method" => "em" }, { "expect_list" => ["one"], "args" => [ "one", "two" ], "expect_scalar" => "one", "method" => "entity_encode" }, { "expect_list" => [ "
one
", "
two
" ], "args" => [ "one", "two" ], "expect_scalar" => "
one
two
", "method" => "fieldset" }, { "expect_list" => [ "
one
", "
two
" ], "args" => [ "one", "two" ], "expect_scalar" => "
one
two
", "method" => "form" }, { "expect_list" => [ "one", "two" ], "args" => [ "one", "two" ], "expect_scalar" => "onetwo", "method" => "frameset" }, { "expect_list" => [ "

one

", "

two

" ], "args" => [ "one", "two" ], "expect_scalar" => "

one

two

", "method" => "h1" }, { "expect_list" => [ "

one

", "

two

" ], "args" => [ "one", "two" ], "expect_scalar" => "

one

two

", "method" => "h2" }, { "expect_list" => [ "

one

", "

two

" ], "args" => [ "one", "two" ], "expect_scalar" => "

one

two

", "method" => "h3" }, { "expect_list" => [ "

one

", "

two

" ], "args" => [ "one", "two" ], "expect_scalar" => "

one

two

", "method" => "h4" }, { "expect_list" => [ "
one
", "
two
" ], "args" => [ "one", "two" ], "expect_scalar" => "
one
two
", "method" => "h5" }, { "expect_list" => [ "
one
", "
two
" ], "args" => [ "one", "two" ], "expect_scalar" => "
one
two
", "method" => "h6" }, { "expect_list" => [ "one\n", "two\n" ], "args" => [ "one", "two" ], "expect_scalar" => "one\ntwo\n", "method" => "head" }, { "expect_list" => [ "one\n", "two\n" ], "args" => [ "one", "two" ], "expect_scalar" => "one\ntwo\n", "method" => "html" }, { "expect_list" => [ "one", "two" ], "args" => [ "one", "two" ], "expect_scalar" => "onetwo", "method" => "i" }, { "expect_list" => [ "", "" ], "args" => [ "one", "two" ], "expect_scalar" => "", "method" => "iframe" }, { "expect_list" => [ "one", "two" ], "args" => [ "one", "two" ], "expect_scalar" => "onetwo", "method" => "ins" }, { "expect_list" => ["[{},{},null,{\"x\":1}]"], "args" => [ [ {}, {}, undef, { x => 1 } ] ], "expect_scalar" => "[{},{},null,{\"x\":1}]", "method" => "json_encode" }, { "expect_list" => [ "one", "two" ], "args" => [ "one", "two" ], "expect_scalar" => "onetwo", "method" => "kbd" }, { "expect_list" => [ "", "" ], "args" => [ "one", "two" ], "expect_scalar" => "", "method" => "label" }, { "expect_list" => [ "one", "two" ], "args" => [ "one", "two" ], "expect_scalar" => "onetwo", "method" => "legend" }, { "expect_list" => [ "
  • one
  • ", "
  • two
  • " ], "args" => [ "one", "two" ], "expect_scalar" => "
  • one
  • two
  • ", "method" => "li" }, { "expect_list" => [ "one", "two" ], "args" => [ "one", "two" ], "expect_scalar" => "onetwo", "method" => "map" }, { "expect_list" => [ "one", "two" ], "args" => [ "one", "two" ], "expect_scalar" => "onetwo", "method" => "noframes" }, { "expect_list" => [ "", "" ], "args" => [ "one", "two" ], "expect_scalar" => "", "method" => "noscript" }, { "expect_list" => [ "one", "two" ], "args" => [ "one", "two" ], "expect_scalar" => "onetwo", "method" => "object" }, { "expect_list" => [ "
      one
    ", "
      two
    " ], "args" => [ "one", "two" ], "expect_scalar" => "
      one
      two
    ", "method" => "ol" }, { "args" => ['pie'], "expect_scalar" => "", "method" => "open" }, { "expect_list" => [ "one", "two" ], "args" => [ "one", "two" ], "expect_scalar" => "onetwo", "method" => "optgroup" }, { "expect_list" => [ "", "" ], "args" => [ "one", "two" ], "expect_scalar" => "", "method" => "option" }, { "expect_list" => [ "

    one

    \n", "

    two

    \n" ], "args" => [ "one", "two" ], "expect_scalar" => "

    one

    \n

    two

    \n", "method" => "p" }, { "expect_list" => [ "
    one
    ", "
    two
    " ], "args" => [ "one", "two" ], "expect_scalar" => "
    one
    two
    ", "method" => "pre" }, { "expect_list" => [ "one", "two" ], "args" => [ "one", "two" ], "expect_scalar" => "onetwo", "method" => "q" }, { "args" => [ { spaces => ' ', '&' => '>' } ], "expect_scalar" => "%26=%3e&spaces=+++", "method" => "query_encode" }, { "expect_list" => [ "one", "two" ], "args" => [ "one", "two" ], "expect_scalar" => "onetwo", "method" => "samp" }, { "expect_list" => [ "", "" ], "args" => [ "one", "two" ], "expect_scalar" => "", "method" => "script" }, { "expect_list" => [ "", "" ], "args" => [ "one", "two" ], "expect_scalar" => "", "method" => "select" }, { "expect_list" => [ "one", "two" ], "args" => [ "one", "two" ], "expect_scalar" => "onetwo", "method" => "small" }, { "expect_list" => [ "one", "two" ], "args" => [ "one", "two" ], "expect_scalar" => "onetwo", "method" => "span" }, { "expect_list" => [ "one", "two" ], "args" => [ "one", "two" ], "expect_scalar" => "onetwo", "method" => "strong" }, { "expect_list" => [ "", "" ], "args" => [ "one", "two" ], "expect_scalar" => "", "method" => "style" }, { "expect_list" => [ "one", "two" ], "args" => [ "one", "two" ], "expect_scalar" => "onetwo", "method" => "sub" }, { "expect_list" => [ "one", "two" ], "args" => [ "one", "two" ], "expect_scalar" => "onetwo", "method" => "sup" }, { "expect_list" => [ "one
    \n", "two
    \n" ], "args" => [ "one", "two" ], "expect_scalar" => "one
    \ntwo
    \n", "method" => "table" }, { "expect_list" => ["two"], "args" => [ "one", "two" ], "expect_scalar" => "two", "method" => "tag" }, { "expect_list" => [ "one", "two" ], "args" => [ "one", "two" ], "expect_scalar" => "onetwo", "method" => "tbody" }, { "expect_list" => [ "one", "two" ], "args" => [ "one", "two" ], "expect_scalar" => "onetwo", "method" => "td" }, { "expect_list" => [ "", "" ], "args" => [ "one", { cols => 20 }, "two" ], "expect_scalar" => "", "method" => "textarea" }, { "expect_list" => [ "one", "two" ], "args" => [ "one", "two" ], "expect_scalar" => "onetwo", "method" => "tfoot" }, { "expect_list" => [ "one", "two" ], "args" => [ "one", "two" ], "expect_scalar" => "onetwo", "method" => "th" }, { "expect_list" => [ "one", "two" ], "args" => [ "one", "two" ], "expect_scalar" => "onetwo", "method" => "thead" }, { "expect_list" => [ "one", "two" ], "args" => [ "one", "two" ], "expect_scalar" => "onetwo", "method" => "title" }, { "expect_list" => [ "one\n", "two\n" ], "args" => [ "one", "two" ], "expect_scalar" => "one\ntwo\n", "method" => "tr" }, { "expect_list" => [ "one", "two" ], "args" => [ "one", "two" ], "expect_scalar" => "onetwo", "method" => "tt" }, { "expect_list" => [ "", "" ], "args" => [ "one", "two" ], "expect_scalar" => "", "method" => "ul" }, { "expect_list" => [" !"], "args" => ['++%20%21'], "expect_scalar" => " !", "method" => "url_decode" }, { "expect_list" => ['+++%21'], "args" => [' !'], "expect_scalar" => '+++%21', "method" => "url_encode" }, { "expect_list" => [ "one", "two" ], "args" => [ "one", "two" ], "expect_scalar" => "onetwo", "method" => "var" } ); my @schedule_xml = ( @common_schedule, { "args" => [ { name => 'foo' } ], "expect_scalar" => "", "expect_list" => [""], "method" => "area" }, { "args" => [ { href => 'http://hexten.net/' } ], "expect_scalar" => "", "expect_list" => [""], "method" => "base" }, { "args" => [], "expect_scalar" => "
    ", "method" => "br" }, { "args" => ['frob'], "expect_scalar" => "", "method" => "closed" }, { "args" => [], "expect_scalar" => "", "method" => "col" }, { "args" => [], "expect_scalar" => "", "method" => "frame" }, { "args" => [], "expect_scalar" => "
    ", "method" => "hr" }, { # This is correct according to our hash merging rules "args" => [ { src => 'logo.png' }, { src => 'header.png' } ], "expect_list" => [''], "expect_scalar" => '', "method" => "img" }, { "args" => [ { type => 'text' }, { name => 'widget' } ], "expect_scalar" => "", "method" => "input" }, { "args" => [ { href => 'http://foo.net/' } ], "expect_scalar" => '' , "method" => "link" }, { "args" => [], "expect_scalar" => "", "method" => "meta" }, { "args" => [ { value => 1 } ], "expect_scalar" => "", "method" => "param" }, ); my @schedule_html = ( @common_schedule, { "args" => [ { name => 'foo' } ], "expect_scalar" => "", "expect_list" => [""], "method" => "area" }, { "args" => [ { href => 'http://hexten.net/' } ], "expect_scalar" => "", "expect_list" => [""], "method" => "base" }, { "args" => [], "expect_scalar" => "
    ", "method" => "br" }, { "args" => ['frob'], "expect_scalar" => "", "method" => "closed" }, { "args" => [], "expect_scalar" => "", "method" => "col" }, { "args" => [], "expect_scalar" => "", "method" => "frame" }, { "args" => [], "expect_scalar" => "
    ", "method" => "hr" }, { # This is correct according to our hash merging rules "args" => [ { src => 'logo.png' }, { src => 'header.png' } ], "expect_list" => [''], "expect_scalar" => '', "method" => "img" }, { "args" => [ { type => 'text' }, { name => 'widget' } ], "expect_scalar" => "", "method" => "input" }, { "args" => [ { href => 'http://foo.net/' } ], "expect_scalar" => '' , "method" => "link" }, { "args" => [], "expect_scalar" => "", "method" => "meta" }, { "args" => [ { value => 1 } ], "expect_scalar" => "", "method" => "param" }, ); plan tests => ( @schedule_xml + @schedule_html ) * 3 * 4; @schedule{qw(xml html)} = ( \@schedule_xml, \@schedule_html ); } sub apply_test { my ( $h, $test ) = @_; my $method = $test->{method}; can_ok $h, $method; my $got = $h->$method( @{ $test->{args} } ); is_deeply $got, $test->{expect_scalar}, "$method: scalar result matches"; my $expect_list = $test->{expect_list} || [ $test->{expect_scalar} ]; my @got = $h->$method( @{ $test->{args} } ); is_deeply \@got, $expect_list, "$method: list result matches"; } for my $mode ( qw(xml html) ) { my @schedule = @{ $schedule{$mode} }; # Run the tests three times, forwards and backwards to make sure they # don't interfere with each other. { my $h = HTML::Tiny->new( mode => $mode ); apply_test( $h, $_ ) for @schedule, reverse @schedule, @schedule; } # And once again, this time with a fresh HTML::Tiny for each test apply_test( HTML::Tiny->new( mode => $mode ), $_ ) for @schedule; }