And some other stuff
"; # use Test::HTML::Content; sub run { text_ok($HTML,qr"This is a very lang text."ism,"REs for text work"); text_count($HTML,qr"This is a very lang text.",1,"Counting text elements works"); no_text($HTML, "This is a very long test","Negation works as well"); no_text($HTML, qr"This is a very long test","Negation also works with REs"); text_ok($HTML2,"This is some text.","Complete elements are matched"); text_ok($HTML2,"And some more text.","Complete elements are matched with whitespace at the ends"); text_count($HTML2,qr"text",2,"Counting elements works with REs"); text_count($HTML2,qr"[aA]nd",2,"Counting elements works with REs"); # Now guard against inadverent stringification of REs : #$text =~ s/^\s*(.*?)\s*$/$1/; no_text("[A] simple test",qr"[A] simple test","No stringification of REs in no_text()"); text_count("[A] simple test",qr"[A] simple test",0,"No stringification of REs in text_count()"); text_ok("A simple test",qr"A simple test","Text is not broken up"); }; runtests( 11, \&run ); Test-HTML-Content-0.13/t/03-links.t 0000755 0001750 0001750 00000001460 14657463106 016102 0 ustar corion corion #!/usr/bin/perl -w use strict; use lib 't'; use testlib; sub run { # Tests for links no_link('','http://www.perl.com', "Simple non-existing link"); no_link('http://www.perl.com',"http://www.perl.com", "Plain text gets not interpreted as link"); link_ok('Title',"http://www.perl.com", "A link is found"); link_count('IconTitle',"http://www.perl.com", 2,"A link that appears twice is reported twice"); link_ok('Mail me at some address', 'corion@somewhere.else', "Links are not found if commented out"); }; runtests(5,\&run); Test-HTML-Content-0.13/t/01-internal-api.t 0000755 0001750 0001750 00000022203 14657463106 017341 0 ustar corion corion #!/usr/bin/perl -w use strict; use Test::More; use lib 't'; use testlib; # This test file tests the internal routines of Test::HTML. # The internal routines aren't really intended for public # consumption, but the tests you'll find in here should # document the behaviour enough ... my (%cases_2,%cases_3); my $count; BEGIN { $cases_2{__dwim_compare} = [ "foo" => "bar" => 0, "foo" => "..." => 0, "bar" => "foo" => 0, "bar" => "barra" => 0, "barra" => "bar" => 0, "foo" => qr"bar" => 0, "foo" => qr"..." => 1, "bar" => qr"foo" => 0, "bar" => qr"barra" => 0, "barra" => qr"bar" => 1, "foo" => qr"^oo" => 0, "foo" => qr"oo$" => 1, "FOO" => qr"foo$" => 0, "FOO" => qr"foo$"i => 1, ]; $cases_2{__match_comment} = [ "hidden message" => qr"hidden\s+message" => 1, "FOO" => qr"foo$"i => 1, " FOO" => qr"foo$"i => 1, "FOO " => qr"foo$"i => 0, "FOO " => qr"^foo$"i => 0, " hidden message " => "hidden message" => 1, " hidden message " => "hidden message" => 0, ]; $cases_2{__match_text} = [ "hidden message" => qr"hidden\s+message" => 1, "FOO" => qr"foo$"i => 1, " FOO" => qr"foo$"i => 1, "FOO " => qr"foo$"i => 0, "FOO " => qr"^foo$"i => 0, " hidden message " => "hidden message" => 1, " hidden message " => "hidden message" => 0, ]; $cases_2{__match_declaration} = [ "hidden message" => qr"hidden\s+message" => 1, "FOO" => qr"foo$"i => 1, " FOO" => qr"foo$"i => 1, "FOO " => qr"foo$"i => 0, "FOO " => qr"^foo$"i => 0, " hidden message " => "hidden message" => 1, " hidden message " => "hidden message" => 0, ]; $cases_3{__match} = [ {href => 'http://www.perl.com', alt =>"foo"},{}, "href" => 0, {href => 'http://www.perl.com', alt =>"foo"},{}, "alt" => 0, {href => 'http://www.perl.com', alt =>undef},{alt => "boo"}, "alt" => 0, {href => undef, alt =>"foo"},{href => 'http://www.perl.com'}, "href" => 0, {href => 'http://www.perl.com', alt =>"foo"},{href => 'www.perl.com'}, "href" => 0, {href => 'http://www.perl.com', alt =>"foo"},{href => '.', alt => "foo"}, "href" => 0, {href => 'http://www.perl.com', alt =>"foo"},{href => 'http://www.perl.com'}, "href" => 1, {href => qr'www\.perl\.com'},{href => 'http://www.perl.com', alt =>"foo"}, "href" => 1, {href => qr'.', alt => "foo"},{href => 'http://www.perl.com', alt =>"foo"}, "href" => 1, ]; $count = (18 + 24 + 12); $count += (@{$cases_2{$_}} / 3) for (keys %cases_2); $count += (@{$cases_3{$_}} / 4) for (keys %cases_3); }; sub run_case { my ($count,$methods) = @_; my $method; for $method (sort keys %$methods) { my @cases = @{$methods->{$method}}; while (@cases) { my (@params) = splice @cases, 0, $count; my $outcome = pop @params; my ($visual); ($visual = $method) =~ tr/_/ /; $visual =~ s/^\s*(.*?)\s*$/$1/; no strict 'refs'; cmp_ok("Test::HTML::Content::$method"->(@params), '==',$outcome,"$visual(". join( "=~",@params ).")"); }; }; }; sub run { run_case( 3, \%cases_2 ); run_case( 4, \%cases_3 ); my ($count,$seen); ($count,$seen) = Test::HTML::Content::__count_tags->("foo","a",{href => "http://www.perl.com"}); is($count, 0,"Counting tags 1"); is(@$seen, 0,"Checking possible candidates"); ($count,$seen) = Test::HTML::Content::__count_tags->("Perl","a",{href => "http://www.perl.com"}); is($count, 0,"Counting tags 2"); is(@$seen, 1,"Checking possible candidates"); ($count,$seen) = Test::HTML::Content::__count_tags->("Perl","a",{href => "http://www.perl.com"}); is($count, 0,"Counting tags 3"); is(@$seen, 0,"Checking possible candidates"); ($count,$seen) = Test::HTML::Content::__count_tags->("Perl","a",{href => "http://www.perl.com"}); is($count, 0,"Counting tags 4"); is(@$seen, 0,"Checking possible candidates"); ($count,$seen) = Test::HTML::Content::__count_tags->("Perl","a",{href => "http://www.perl.com"}); is($count, 1,"Counting tags 6"); is(@$seen, 1,"Checking possible candidates"); ($count,$seen) = Test::HTML::Content::__count_tags->("Perl","a",{href => "http://www.perl.com"}); is($count, 1,"Counting tags 7"); is(@$seen, 1,"Checking possible candidates"); ($count,$seen) = Test::HTML::Content::__count_tags->("PerlPerl","a",{href => "http://www.perl.com", alt => undef}); is($count, 1,"Counting tags 8"); is(@$seen, 2,"Checking possible candidates"); ($count,$seen) = Test::HTML::Content::__count_tags->("PerlPerl","a",{href => "http://www.perl.com"}); is($count, 2,"Counting tags 9"); is(@$seen, 2,"Checking possible candidates"); ($count,$seen) = Test::HTML::Content::__count_tags->("Perl","a",{href => "http://www.perl.com"}); is($count, 2,"Counting tags 10"); is(@$seen, 2,"Checking possible candidates"); ($count,$seen) = Test::HTML::Content::__count_comments( "" => "foo" ); is($count,0,"Counting comments 0"); is(@$seen,0,"Counting possible candidates 0"); ($count,$seen) = Test::HTML::Content::__count_comments( "foo" => "foo" ); is($count,0,"Counting comments 1"); is(@$seen,0,"Counting possible candidates 1"); ($count,$seen) = Test::HTML::Content::__count_comments( "" => "foo" ); is($count,1,"Counting comments 2"); is(@$seen,1,"Counting possible candidates 2"); ($count,$seen) = Test::HTML::Content::__count_comments( "" => "foo" ); is($count,0,"Counting comments 3"); is(@$seen,1,"Counting possible candidates 3"); ($count,$seen) = Test::HTML::Content::__count_comments( "" => "foo" ); is($count,0,"Counting comments 4"); is(@$seen,1,"Counting possible candidates 4"); ($count,$seen) = Test::HTML::Content::__count_comments( "" => "foo" ); is($count,0,"Counting comments 5"); is(@$seen,1,"Counting possible candidates 5"); ($count,$seen) = Test::HTML::Content::__count_comments( "" => "foo " ); is($count,1,"Counting comments 6"); is(@$seen,1,"Counting possible candidates 6"); ($count,$seen) = Test::HTML::Content::__count_comments( "" => qr"foo" ); is($count,1,"Counting comments 7"); is(@$seen,1,"Counting possible candidates 7"); ($count,$seen) = Test::HTML::Content::__count_comments( "" => "foo" ); is($count,1,"Counting comments 8"); is(@$seen,1,"Counting possible candidates 8"); ($count,$seen) = Test::HTML::Content::__count_comments( "" => "foo" ); is($count,2,"Counting comments 9"); is(@$seen,2,"Counting possible candidates 9"); ($count,$seen) = Test::HTML::Content::__count_comments( "" => "foo" ); is($count,3,"Counting comments 10"); is(@$seen,3,"Counting possible candidates 10"); ($count,$seen) = Test::HTML::Content::__count_comments( "" => "foo" ); is($count,2,"Counting comments 11"); is(@$seen,3,"Counting possible candidates 11"); ($count,$seen) = Test::HTML::Content::__count_text( "" => "foo" ); is($count,0,"Counting text occurrences 0"); is(@$seen,0,"Counting possible candidates 0"); ($count,$seen) = Test::HTML::Content::__count_text( "foo" => "foo" ); is($count,1,"counting text occurrences 1"); is(@$seen,1,"Counting possible candidates 1"); ($count,$seen) = Test::HTML::Content::__count_text( "" => "foo" ); is($count,0,"counting text occurrences 2"); is(@$seen,0,"Counting possible candidates 2"); # This test disabled, as it is not consistent between XPath and NoXPath... #($count,$seen) = Test::HTML::Content::__count_text( "" => "foo" ); #is($count,0,"counting text occurrences 3"); #is(@$seen,2,"Counting possible candidates 3"); ($count,$seen) = Test::HTML::Content::__count_text( "foo bar" => "foo" ); is($count,1,"counting text occurrences 4"); is(@$seen,2,"Counting possible candidates 4"); ($count,$seen) = Test::HTML::Content::__count_text( "foo" => "foo" ); is($count,0,"counting text occurrences 5"); is(@$seen,3,"Counting possible candidates 5"); ($count,$seen) = Test::HTML::Content::__count_text( "Hello foo World" => qr"foo" ); is($count,1,"Checking RE for text 6"); is(@$seen,1,"Counting possible candidates 6"); }; runtests( $count, \&run ); Test-HTML-Content-0.13/t/08-errors.comment.t 0000755 0001750 0001750 00000006651 14657463106 017753 0 ustar corion corion # Test script to test the failure modes of Test::HTML::Content use Test::More; use lib 't'; use testlib; use vars qw( $Test::HTML::Content::can_xpath ); eval { require Test::Builder::Tester; Test::Builder::Tester->import; }; if ($@) { plan skip_all => "Test::Builder::Tester required for testing error messages"; } # perldelta 5.14 # Accept both old and new-style stringification my $modifiers = (qr/foobar/ =~ /\Q(?^/) ? "^" : "-xism"; sub run { # Test that each exported function fails as documented test_out("not ok 1 - Comment failure (no comments)"); test_fail(+7); if ($Test::HTML::Content::can_xpath eq 'XML::LibXML') { test_diag("Invalid HTML:",""); } else { test_diag("No comment found at all", "Expected at least one comment like 'hidden message'",); }; comment_ok("","hidden message","Comment failure (no comments)"); test_test("Finding no comment works"); test_out("not ok 1 - Comment failure (nonmatching comments)"); test_fail(+9); #if ($Test::HTML::Content::can_xpath eq 'XML::XPath') { # test_diag("Invalid HTML:",""); #} else { test_diag("Saw ''", "Saw ''", "Saw ''", "Expected at least one comment like 'hidden message'"); #}; comment_ok("", "hidden message","Comment failure (nonmatching comments)"); test_test("Finding no comment returns all other comments"); test_out("not ok 1 - Comment failure (two comments that shouldn't exist do)"); test_fail(+8); #if ($Test::HTML::Content::can_xpath eq 'XML::XPath') { # test_diag("Invalid HTML:",""); #} else { test_diag("Saw ''", "Saw ''", "Expected no comment like '(?$modifiers:hidden m.ssage)'"); #}; no_comment("", qr"hidden m.ssage","Comment failure (two comments that shouldn't exist do)"); test_test("Finding a comment where none should be returns all comments"); test_out("not ok 1 - Comment failure (too few comments)"); test_fail(+8); #if ($Test::HTML::Content::can_xpath eq 'XML::XPath') { # test_diag("Invalid HTML:",""); #} else { test_diag("Saw ''", "Saw ''", "Expected exactly 3 comments like '(?$modifiers:hidden m.ssage)'"); #}; comment_count("", qr"hidden m.ssage",3,"Comment failure (too few comments)"); test_test("Diagnosing too few comments works"); test_out("not ok 1 - Comment failure (too few comments)"); test_fail(+8); #if ($Test::HTML::Content::can_xpath eq 'XML::XPath') { # test_diag("Invalid HTML:",""); #} else { test_diag("Saw ''", "Saw ''", "Expected exactly 1 comments like '(?$modifiers:hidden m.ssage)'"); #}; comment_count("", qr"hidden m.ssage",1,"Comment failure (too few comments)"); test_test("Diagnosing too many comments works"); }; runtests( 5, \&run ); Test-HTML-Content-0.13/t/01-libxml-xpath-abstraction.t 0000755 0001750 0001750 00000001436 14657463106 021703 0 ustar corion corion #!/usr/bin/perl -w use strict; use Test::More; use lib 't'; use testlib; # This test file tests the abstraction # of XML::LibXML and XML::XPath nodes my $HTML = 'test'; sub run { my ($implementation) = @_; SKIP: { skip "Tests irrelevant for pure Perl implementation", 4 if $implementation eq 'PurePerl'; use_ok('Test::HTML::Content'); my $tree = Test::HTML::Content::__get_node_tree($HTML, '/html/body'); isnt( $tree, undef, "Got body node"); foreach my $node ($tree->get_nodelist) { is( Test::HTML::Content::__get_node_content($node,'onload'), 'foo()', 'onload attribute'); is( Test::HTML::Content::__get_node_content($node,'_content'), 'test','_content pseudo attribute'); }; }; }; runtests( 4,\&run ); Test-HTML-Content-0.13/t/00-prerequisites.t 0000755 0001750 0001750 00000000734 14657463106 017666 0 ustar corion corion #!/usr/bin/perl -w use strict; use Test::More tests => 3; # TODO: # * Better prerequisites checking # * Split up the tests into separate files # First, check the prerequisites use_ok('Test::Builder') or BAILOUT("The tests require Test::Builder"); use_ok('HTML::TokeParser') or BAILOUT("The tests require HTML::TokeParser"); use_ok('Test::HTML::Content') or Test::Builder::BAILOUT("The tests require Test::HTML::Content - this shouldn't happen at all"); Test-HTML-Content-0.13/t/13-xpath-gracefull-errors.t 0000755 0001750 0001750 00000002042 14657463106 021360 0 ustar corion corion # Test script to test the failure modes of Test::HTML::Content use Test::More; use lib 't'; use testlib; eval { require Test::Builder::Tester; Test::Builder::Tester->import; }; if ($@) { plan skip_all => "Test::Builder::Tester required for testing error messages"; } sub run { use_ok('Test::HTML::Content'); SKIP: { { no warnings 'once'; $Test::HTML::Content::can_xpath or skip "XML::XPath or XML::LibXML required", 2; }; my ($tree,$result,$seen); eval { ($result,$seen) = Test::HTML::Content::__count_comments("", "hidden message"); }; is($@,'',"Invalid HTML does not crash the test"); eval { ($tree) = Test::HTML::Content::__get_node_tree("",'//comment()'); }; is($@,'',"Invalid HTML does not crash the test"); # is($tree,undef,"The result of __get_node_tree is undef"); } }; runtests( 3, \&run); Test-HTML-Content-0.13/t/testlib.pm 0000755 0001750 0001750 00000001603 14657463106 016360 0 ustar corion corion use strict; use Test::More; use vars qw(%modules); BEGIN { $modules{pureperl} = \&run_pureperl; eval { require XML::XPath; $XML::XPath::VERSION >= 1.13 and $modules{xpath} = \&run_xpath }; eval { require XML::LibXML; $modules{libxml} = \&run_libxml }; }; sub main::runtests { my ($count,$code) = @_; my @candidates = (sort keys %modules); plan( tests => 1+ $count * scalar @candidates ); use_ok('Test::HTML::Content'); for my $implementation (@candidates) { my $test = $modules{$implementation}; $test->($count,$code); }; }; sub run_libxml { my ($count,$code) = @_; Test::HTML::Content::install_libxml(); $code->('XML::LibXML'); }; sub run_xpath { my ($count,$code) = @_; Test::HTML::Content::install_xpath(); $code->('XML::XPath'); }; sub run_pureperl { my ($count,$code) = @_; Test::HTML::Content::install_pureperl(); $code->('PurePerl'); }; 1; Test-HTML-Content-0.13/t/01-fallback-xpath.t 0000755 0001750 0001750 00000001322 14657463106 017636 0 ustar corion corion use strict; use Test::More tests => 4; my $HTML = "dot"; SKIP: { eval { require Test::Without::Module; Test::Without::Module->import( 'XML::LibXML' ); }; skip "Need Test::Without::Module to test the fallback", 4 if $@; use_ok("Test::HTML::Content"); link_ok($HTML,'target',"Finding a link works without XML::LibXML"); my ($result,$args); eval { ($result,$args) = Test::HTML::Content::__count_tags($HTML,'a',{_content=>'dot'}); }; is($@,'',"Missing prerequisites don't let the tests fail"); ok($result eq 'skip' || $result == 1,'Skipped or passed when XML::LibXML is missing') or diag "Expected 'skip' or '1', but got '$result'"; }; Test-HTML-Content-0.13/t/embedded-Test-HTML-Content-NoXPath.t 0000644 0001750 0001750 00000002127 14657463106 022677 0 ustar corion corion #!D:\perl\5.8.2\bin\perl.exe -w use Test::More 'no_plan'; package Catch; sub TIEHANDLE { my($class, $var) = @_; return bless { var => $var }, $class; } sub PRINT { my($self) = shift; ${'main::'.$self->{var}} .= join '', @_; } sub OPEN {} # XXX Hackery in case the user redirects sub CLOSE {} # XXX STDERR/STDOUT. This is not the behavior we want. sub READ {} sub READLINE {} sub GETC {} my $Original_File = 'lib\Test\HTML\Content\NoXPath.pm'; package main; # pre-5.8.0's warns aren't caught by a tied STDERR. $SIG{__WARN__} = sub { $main::_STDERR_ .= join '', @_; }; tie *STDOUT, 'Catch', '_STDOUT_' or die $!; tie *STDERR, 'Catch', '_STDERR_' or die $!; undef $main::_STDOUT_; undef $main::_STDERR_; eval q{ my $example = sub { local $^W = 0; #line 195 lib/Test/HTML/Content/NoXPath.pm # This module is implicitly loaded by Test::HTML::Content # if XML::XPath or HTML::Tidy::Simple are unavailable. ; } }; is($@, '', "example from line 195"); undef $main::_STDOUT_; undef $main::_STDERR_; Test-HTML-Content-0.13/t/embedded-Test-HTML-Content.t 0000644 0001750 0001750 00000005046 14657463106 021363 0 ustar corion corion #!D:\perl\5.8.2\bin\perl.exe -w use Test::More 'no_plan'; package Catch; sub TIEHANDLE { my($class, $var) = @_; return bless { var => $var }, $class; } sub PRINT { my($self) = shift; ${'main::'.$self->{var}} .= join '', @_; } sub OPEN {} # XXX Hackery in case the user redirects sub CLOSE {} # XXX STDERR/STDOUT. This is not the behavior we want. sub READ {} sub READLINE {} sub GETC {} my $Original_File = 'lib\Test\HTML\Content.pm'; package main; # pre-5.8.0's warns aren't caught by a tied STDERR. $SIG{__WARN__} = sub { $main::_STDERR_ .= join '', @_; }; tie *STDOUT, 'Catch', '_STDOUT_' or die $!; tie *STDERR, 'Catch', '_STDERR_' or die $!; undef $main::_STDOUT_; undef $main::_STDERR_; eval q{ my $example = sub { local $^W = 0; #line 598 lib/Test/HTML/Content.pm $HTML = "
Home page