File: parse-errors.t

package info (click to toggle)
libhtml-tidy5-perl 1.06-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 368 kB
  • sloc: perl: 1,853; makefile: 14
file content (40 lines) | stat: -rw-r--r-- 1,185 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/perl -T

use 5.010001;
use strict;
use warnings;

use Test::Exception;
use Test::More tests => 4;

use HTML::Tidy5;

my $tidy = HTML::Tidy5->new;

my $errbuf = join( '', <DATA> );

CATCH_A_WARNING: {
    my $stashed_warning;
    my $ncalls = 0;
    local $SIG{__WARN__} = sub { $stashed_warning = shift; ++$ncalls; };

    my $ret = $tidy->_parse_errors('fake_filename.html', $errbuf, "\n");
    is( $ret, 1, 'encountered 1 parsing error' );
    is( scalar @{$tidy->{messages}},  7, 'got 7 messages when parsing errors' );

    # Check our warnings.
    is( $ncalls, 1, 'Warning should have been called exactly once' );
    like( $stashed_warning, qr/HTML::Tidy5: Unknown error type: FAKE_ERROR_TYPE at/, 'Expected warning' );
}

__DATA__
line 1 column 1 - Warning: missing <!DOCTYPE> declaration
line 1 column 1 - Warning: plain text isn\'t allowed in <head> elements
line 1 column 1 - Info: <head> previously mentioned
line 1 column 1 - Warning: inserting implicit <body>
line 1 column 13 - Warning: missing </b>
line 1 column 1 - Warning: inserting missing \'title\' element
Info: Document content looks like HTML 3.2

FAKE_ERROR_TYPE
Tidy found 5 warnings and 0 errors!