|
Packit |
16975c |
#!/usr/bin/perl -T
|
|
Packit |
16975c |
|
|
Packit |
16975c |
use warnings;
|
|
Packit |
16975c |
use strict;
|
|
Packit |
16975c |
use Test::More tests => 16;
|
|
Packit |
16975c |
|
|
Packit |
16975c |
use HTML::Parse;
|
|
Packit |
16975c |
|
|
Packit |
16975c |
# This is a very simple test. It basically just ensures that the
|
|
Packit |
16975c |
# HTML::Parse module is parsed ok by perl and that it will interact
|
|
Packit |
16975c |
# nicely with the rest of our modules
|
|
Packit |
16975c |
|
|
Packit |
16975c |
our $TestInput = "t/oldparse.html";
|
|
Packit |
16975c |
|
|
Packit |
16975c |
my $HTML;
|
|
Packit |
16975c |
{
|
|
Packit |
16975c |
local $/ = undef;
|
|
Packit |
16975c |
open( "INFILE", "$TestInput" ) || die "$!";
|
|
Packit |
16975c |
binmode INFILE;
|
|
Packit |
16975c |
$HTML = <INFILE>;
|
|
Packit |
16975c |
close(INFILE);
|
|
Packit |
16975c |
}
|
|
Packit |
16975c |
|
|
Packit |
16975c |
my $own_builder = new HTML::TreeBuilder;
|
|
Packit |
16975c |
isa_ok( $own_builder, 'HTML::TreeBuilder' );
|
|
Packit |
16975c |
|
|
Packit |
16975c |
my $obj_h = parse_html $HTML, $own_builder;
|
|
Packit |
16975c |
isa_ok( $obj_h, "HTML::TreeBuilder", "existing TreeBuilder handled OK." );
|
|
Packit |
16975c |
|
|
Packit |
16975c |
my $h = parse_html $HTML;
|
|
Packit |
16975c |
isa_ok( $h, "HTML::TreeBuilder" );
|
|
Packit |
16975c |
|
|
Packit |
16975c |
# This ensures that the output from $h->dump goes to STDOUT
|
|
Packit |
16975c |
my $html;
|
|
Packit |
16975c |
ok( $html = $h->as_HTML( undef, ' ' ), "Get html as string." );
|
|
Packit |
16975c |
|
|
Packit |
16975c |
# This is a very simple test just to ensure that we get something
|
|
Packit |
16975c |
# sensible back.
|
|
Packit |
16975c |
like( $html, qr/<BODY>/i, "<BODY> found OK." );
|
|
Packit |
16975c |
like( $html, qr/www\.sn\.no/, "found www.sn.no link" );
|
|
Packit |
16975c |
unlike( $html, qr/comment/, "Didn't find comment" );
|
|
Packit |
16975c |
like( $html, qr/Gisle/, "found Gisle" );
|
|
Packit |
16975c |
|
|
Packit |
16975c |
my $bad_file = parse_htmlfile("non-existent-file.html");
|
|
Packit |
16975c |
ok( !$bad_file, "Properly returned undef on missing file." );
|
|
Packit |
16975c |
|
|
Packit |
16975c |
my $own_obj_parser2 = parse_htmlfile( "t/oldparse.html", $own_builder );
|
|
Packit |
16975c |
isa_ok( $own_obj_parser2, "HTML::TreeBuilder" );
|
|
Packit |
16975c |
|
|
Packit |
16975c |
my $h2 = parse_htmlfile("t/oldparse.html");
|
|
Packit |
16975c |
isa_ok( $h2, "HTML::TreeBuilder" );
|
|
Packit |
16975c |
|
|
Packit |
16975c |
ok( $html = $h2->as_HTML( undef, ' ' ), "Get html as string." );
|
|
Packit |
16975c |
|
|
Packit |
16975c |
# This is a very simple test just to ensure that we get something
|
|
Packit |
16975c |
# sensible back.
|
|
Packit |
16975c |
like( $html, qr/<BODY>/i, "parse_htmlfile: <BODY> found OK." );
|
|
Packit |
16975c |
like( $html, qr/www\.sn\.no/, "parse_htmlfile: found www.sn.no link" );
|
|
Packit |
16975c |
unlike( $html, qr/comment/, "parse_htmlfile: found comment" );
|
|
Packit |
16975c |
like( $html, qr/Gisle/, "parse_htmlfile: found Gisle" );
|
|
Packit |
16975c |
|