3 use Test::More tests => (3 + 7 * 8);
4 #initial tests + number of tests in test_new_obj() * number of times called
9 use_ok( 'HTML::Tree' );
12 my $obj = new HTML::Tree;
13 isa_ok($obj, "HTML::TreeBuilder");
15 my $TestInput = "t/oldparse.html";
20 open(INFILE, $TestInput) || die "Can't open $TestInput: $!";
25 # setup some parts of the HTML for the list tests.
27 # die "$TestInput does not have at least 2 characters!"
28 # if length($HTML) <= 2;
29 # my $HTMLPart1 = substr( $HTML, 0, int( length($HTML) / 2 ) );
30 # my $HTMLPart2 = substr( $HTML, int( length($HTML) / 2 ) );
32 # The logic here is to try to split the HTML in the middle of a tag.
33 # The above commented-out code is also an option.
36 die "$TestInput does not have at least " . ($split_at + 1) . " characters!"
37 if length($HTML) <= $split_at;
38 my $HTMLPart1 = substr( $HTML, 0, 4 );
39 my $HTMLPart2 = substr( $HTML, 4 );
41 is($HTMLPart1 . $HTMLPart2, $HTML, "split \$HTML correctly");
46 open(INFILE, $TestInput) || die "Can't open $TestInput: $!";
47 my $file_obj = HTML::Tree->new_from_file( *INFILE );
48 test_new_obj($file_obj, "new_from_file Filehandle" ) ;
55 my $content_obj = HTML::Tree->new_from_content($HTML);
56 test_new_obj($content_obj, "new_from_content Scalar") ;
60 my $file_obj = HTML::Tree->new_from_file( $TestInput);
61 test_new_obj($file_obj, "new_from_file Scalar" ) ;
65 my $parse_content_obj = HTML::Tree->new;
66 $parse_content_obj->parse_content( $HTML);
67 test_new_obj($parse_content_obj, "new(); parse_content Scalar" );
73 my $content_obj = HTML::Tree->new_from_content($HTML);
74 test_new_obj($content_obj, "new_from_content Scalar REF") ;
77 # None for new_from_file
78 # Filehandle test instead. (see above)
81 my $parse_content_obj = HTML::Tree->new;
82 $parse_content_obj->parse_content( $HTML);
83 test_new_obj($parse_content_obj, "new(); parse_content Scalar REF" );
87 # List Tests (Scalar and Scalar REF)
89 my $content_obj = HTML::Tree->new_from_content(\$HTMLPart1, $HTMLPart2);
90 test_new_obj($content_obj, "new_from_content List") ;
93 # None for new_from_file.
94 # Does not support lists.
97 my $parse_content_obj = HTML::Tree->new;
98 $parse_content_obj->parse_content( \$HTMLPart1, $HTMLPart2 );
99 test_new_obj($parse_content_obj, "new(); parse_content List");
105 my $test_description = shift;
107 isa_ok($obj, "HTML::TreeBuilder", $test_description);
109 my $html = $obj->as_HTML(undef, ' ');
110 ok( $html, "Get HTML as string." );
112 # This is a very simple test just to ensure that we get something
114 like( $html, qr/<BODY>/i, "<BODY> found OK." );
115 like( $html, qr/www\.sn\.no/, "found www.sn.no link" );
118 local $TODO = <<ENDTEXT;
119 HTML::Parser doesn't handle nested comments correctly.
120 See: http://phalanx.kwiki.org/index.cgi?HTMLTreeNestedComments
123 unlike( $html, qr/nested-comment/, "Nested comment not found" );
126 unlike( $html, qr/simple-comment/, "Simple comment not found" );
127 like( $html, qr/Gisle/, "found Gisle" );