| 1 |
#!perl |
| 2 |
|
| 3 |
use 5.010001; |
| 4 |
use warnings; |
| 5 |
use strict; |
| 6 |
|
| 7 |
use Test::More tests => 3; |
| 8 |
|
| 9 |
use Test::Builder::Tester; |
| 10 |
use Test::HTML::Tidy5; |
| 11 |
|
| 12 |
subtest 'html_fragment_tidy_ok fails on undef' => sub { |
| 13 |
plan tests => 1; |
| 14 |
|
| 15 |
my $msg = 'Fails on undef'; |
| 16 |
test_out( "not ok 1 - $msg" ); |
| 17 |
test_fail( +2 ); |
| 18 |
test_diag( 'Error: html_fragment_tidy_ok() got undef' ); |
| 19 |
html_fragment_tidy_ok( undef, $msg ); |
| 20 |
test_test( $msg ); |
| 21 |
}; |
| 22 |
|
| 23 |
|
| 24 |
subtest 'html_tidy_ok fails on a fragment, but html_fragment_tidy_ok is OK' => sub { |
| 25 |
plan tests => 2; |
| 26 |
|
| 27 |
my $html = <<'HTML'; |
| 28 |
<p> |
| 29 |
This is an incomplete document but it's structurally OK. |
| 30 |
<img src="alpha.jpg" height="21" width="12" alt="alpha"> |
| 31 |
<input type="image"> |
| 32 |
</p> |
| 33 |
HTML |
| 34 |
|
| 35 |
my $msg = 'Called html_tidy_ok on incomplete document'; |
| 36 |
test_out( "not ok 1 - $msg" ); |
| 37 |
test_fail( +6 ); |
| 38 |
test_diag( "Errors: $msg" ); |
| 39 |
test_diag( '(1:1) Warning: missing <!DOCTYPE> declaration' ); |
| 40 |
test_diag( '(1:1) Warning: inserting implicit <body>' ); |
| 41 |
test_diag( '(1:1) Warning: inserting missing \'title\' element' ); |
| 42 |
test_diag( '3 messages on the page' ); |
| 43 |
html_tidy_ok( $html, $msg ); |
| 44 |
test_test( $msg ); |
| 45 |
|
| 46 |
$msg = 'html_fragment_tidy_ok can handle it'; |
| 47 |
test_out( "ok 1 - $msg" ); |
| 48 |
html_fragment_tidy_ok( $html, $msg ); |
| 49 |
test_test( $msg ); |
| 50 |
}; |
| 51 |
|
| 52 |
|
| 53 |
subtest 'html_fragment_tidy_ok gets the same errors as html_tidy_ok' => sub { |
| 54 |
plan tests => 2; |
| 55 |
|
| 56 |
my $html = <<'HTML'; |
| 57 |
<p> |
| 58 |
This is an incomplete document, and it has structural </td> errors. |
| 59 |
<img src="alpha.jpg" height="21" width="12"> |
| 60 |
</p> |
| 61 |
HTML |
| 62 |
|
| 63 |
my $msg = 'html_tidy_ok on sloppy doc'; |
| 64 |
test_out( "not ok 1 - $msg" ); |
| 65 |
test_fail( +8 ); |
| 66 |
test_diag( "Errors: $msg" ); |
| 67 |
test_diag( '(1:1) Warning: missing <!DOCTYPE> declaration' ); |
| 68 |
test_diag( '(1:1) Warning: inserting implicit <body>' ); |
| 69 |
test_diag( '(2:59) Warning: discarding unexpected </td>' ); |
| 70 |
test_diag( '(1:1) Warning: inserting missing \'title\' element' ); |
| 71 |
test_diag( '(3:5) Warning: <img> lacks "alt" attribute' ); |
| 72 |
test_diag( '5 messages on the page' ); |
| 73 |
html_tidy_ok( $html, $msg ); |
| 74 |
test_test( $msg ); |
| 75 |
|
| 76 |
# Note that the line numbers are the same between html_tidy_ok and html_fragment_tidy_ok. |
| 77 |
$msg = 'html_fragment_tidy_ok on sloppy doc'; |
| 78 |
test_out( "not ok 1 - $msg" ); |
| 79 |
test_fail( +5 ); |
| 80 |
test_diag( "Errors: $msg" ); |
| 81 |
test_diag( '(2:59) Warning: discarding unexpected </td>' ); |
| 82 |
test_diag( '(3:5) Warning: <img> lacks "alt" attribute' ); |
| 83 |
test_diag( '2 messages on the page' ); |
| 84 |
html_fragment_tidy_ok( $html, $msg ); |
| 85 |
test_test( $msg ); |
| 86 |
}; |
| 87 |
|
| 88 |
exit 0; |