3 # Testing of the incremental parsing. Try to split a HTML document at
4 # every possible position and make sure that the result is the same as
5 # when parsing everything in one chunk.
7 # Now we use a shorter document, because we don't have all day on
22 <a href="..." name=foo bar>italic</a>
23 some entities (å)
26 $notests = length($HTML); # A test for each char in the test doc
27 $notests *= 3; # done twice
28 $notests += 4; # plus more for the the rest of the tests
32 use Test::More tests=>$notests; # Tests
35 use_ok( 'HTML::TreeBuilder');
38 my $h = new HTML::TreeBuilder;
39 isa_ok ( $h, "HTML::TreeBuilder");
40 $h->parse($HTML)->eof;
41 my $html = $h->as_HTML;
44 # Each test here tries to parse the doc when we split it in two.
45 for my $pos (0 .. length($HTML) - 1) {
46 my $first = substr($HTML, 0, $pos);
47 my $last = substr($HTML, $pos);
48 is ($first.$last, $HTML, "File split okay");
51 $h1 = new HTML::TreeBuilder;
52 isa_ok( $h1, 'HTML::TreeBuilder' );
58 print "Died when splitting at position $pos:\n";
60 $before = $pos if $pos < $before;
61 print "«", substr($HTML, $pos - $before, $before);
63 print substr($HTML, $pos, 10);
65 print "not ok $pos\n";
69 my $new_html = $h1->as_HTML;
71 $before = $pos if $pos < $before;
72 is($new_html, $html, "Still Parsing as the same after split at $pos") or
73 diag("Something is different when splitting at position $pos:\n",
74 "«", substr($HTML, $pos - $before, $before), "»\n«",
75 substr($HTML, $pos, 10), "»\n", "\n$html$new_html\n",
80 # Also try what happens when we feed the document one-char at a time
81 # print "#\n#\nNow parsing document once char at a time...\n";
82 my $perChar = new HTML::TreeBuilder;
83 isa_ok( $perChar, 'HTML::TreeBuilder' );
84 while ($HTML =~ /(.)/sg) {
88 my $new_html = $perChar->as_HTML;
89 is ($new_html, $html, "Testing per Char parsing");