1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
#!perl -T
use strict;
use warnings;
use Test::More tests => 9;
use HTML::Tidy;
my $html = do { local $/ = undef; <DATA> };
my @expected_warnings = split /\n/, q{
- (24:1) Warning: discarding unexpected <bogotag>
- (25:XX) Warning: unescaped & which should be written as &
- (25:XX) Warning: unescaped & which should be written as &
};
chomp @expected_warnings;
shift @expected_warnings; # First one's blank
my @expected_errors = split /\n/, q{
- (24:1) Error: <bogotag> is not recognized!
};
chomp @expected_errors;
shift @expected_errors; # First one's blank
WARNINGS_ONLY: {
my $tidy = HTML::Tidy->new;
isa_ok( $tidy, 'HTML::Tidy' );
$tidy->ignore( type => TIDY_ERROR, type => TIDY_INFO );
my $rc = $tidy->parse( '-', $html );
ok( $rc, 'Parsed OK' );
my @returned = map { $_->as_string } $tidy->messages;
s/[\r\n]+\z// for @returned;
munge_returned( \@returned );
is_deeply( \@returned, \@expected_warnings, 'Matching warnings' );
}
ERRORS_ONLY: {
my $tidy = HTML::Tidy->new;
isa_ok( $tidy, 'HTML::Tidy' );
$tidy->ignore( type => TIDY_WARNING, type => TIDY_INFO );
my $rc = $tidy->parse( '-', $html );
ok( $rc, 'Parsed OK' );
my @returned = map { $_->as_string } $tidy->messages;
s/[\r\n]+\z// for @returned;
is_deeply( \@returned, \@expected_errors, 'Matching errors' );
}
DIES_ON_ERROR: {
my $tidy = HTML::Tidy->new;
isa_ok( $tidy, 'HTML::Tidy' );
my $rc = eval { $tidy->ignore( blongo => TIDY_WARNING ) };
ok( !$rc, 'eval should fail' );
like( $@, qr/^Invalid ignore type.+blongo/, 'Throws an error' );
}
sub munge_returned {
# non-1 line numbers are not reliable across libtidies
my $returned = shift;
my $start_line = shift || '-';
for my $line ( @{$returned} ) {
next if $line =~ /$start_line \(\d+:1\)/;
$line =~ s/$start_line \((\d+):(\d+)\)/$start_line ($1:XX)/;
}
}
__DATA__
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html;CHARSET=iso-8859-1">
<META NAME="Author" Content="Andy Lester">
<TITLE>petdance.com: Andy Lester's Programming & Writing</TITLE>
<STYLE type="text/css">
<!--
DIV.TOC H2 {
font-family : tahoma, arial, helvetica, sans-serif;
font-weight : bold;
font-size : 15pt;
}
DIV.TOC P {
font-size : 12pt;
font-weight : normal;
}
-->
</STYLE>
</HEAD>
<BODY BGCOLOR="white">
<BOGOTAG>
<IMG SRC="/pix/petdance-logo-400x312.gif" HEIGHT=312 WIDTH=400 ALT="Andy & Amy's Pet Supplies & Dance Instruction" ALIGN=RIGHT>
<DIV CLASS="TOC">
<h2>Perl, Programming & Writing</h2>
My <A HREF="http://www.oreillynet.com/pub/au/1249">Technology & publishing blog</A> at oreillynet.com<BR>
My <A HREF="http://use.perl.org/~petdance/journal/">Perl-specific and personal blog</A> at use.perl.org<BR>
<A HREF="resume/">Andy Lester's resume</A><BR>
Andy's <A HREF="perl/">Perl Pages</A>
<H2>The Lester Family</h2>
<A HREF="/andy/">Andy</A>: The Dad<BR>
<A HREF="http://www.parsley.org/">Amy</A>: The Mom<BR>
<A HREF="http://www.parsley.org/quinn/">Quinn</A>: The Girl<BR>
<A HREF="/baxter/">Baxter</A>: The Dog<BR>
<A HREF="http://www.familytreemaker.com/users/l/e/s/Andrew-R-Lester/">Our family trees</A>
<H2>About Andy & Amy</H2>
<A HREF="/us/mush/">The Page Of Mush</A><BR>
<A HREF="/us/people/">People we're looking for</A><BR>
<A HREF="/us/herald/">Article about us and how we met</A> from the Northwest Herald<BR>
<H2>Useful Stuff</H2>
<A HREF="/start/">Andy's Magic Start Page</A>: Bunches of your favorite search engines, all in one place<BR>
<A HREF="/adds/">Add-a-page Page</A>: Bunches of website submission forms, all in one place<BR>
<A HREF="cf/">Cold Fusion stuff</A>: CFX_HTTP and other custom tags
<H2>Musical Information, etc</H2>
<A HREF="/nr/">Naked Raygun</A>: Bring your mom and your mom's friends, too<BR>
<A HREF="/actionpark/">Action Park</A>: A compendium of information about Big Black, Rapeman, Shellac and Steve Albini<BR>
<H2>Other things that might be fun</h2>
<A HREF="http://www.parsley.org/"><CITE>When In Doubt, Use Parsley</CITE></A>: Amy's journal<BR>
<A HREF="/wonder/"><CITE>Wonder</CITE></A>: Andy's old journal<BR>
<A HREF="/us/trip/">So American It Hurts</A>: Andy & Amy's trip to Graceland<BR>
<A HREF="/andy/appliances/">Gallery Of Household Appliances</A><BR>
<A HREF="/wants/">Media Wants</A>: Stuff I yearn to consume<BR>
<A HREF="/andy/bingo/">Buzzword Bingo</A>
</DIV>
</BODY>
</HTML>
|