File: LintTest.pl

package info (click to toggle)
libhtml-lint-perl 2.20%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 304 kB
  • ctags: 64
  • sloc: perl: 1,014; sh: 48; makefile: 20
file content (67 lines) | stat: -rw-r--r-- 1,618 bytes parent folder | download | duplicates (5)
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
use Test::More;
use HTML::Lint;

sub checkit {
    my @expected = @{+shift};
    my @linesets = @_;

    plan( tests => 3*(scalar @expected) + 4 );

    my $lint = new HTML::Lint;
    isa_ok( $lint, 'HTML::Lint', 'Created lint object' );

    my $n;
    for my $set ( @linesets ) {
        ++$n;
        $lint->newfile( "Set #$n" );
        $lint->parse( $_ ) for @$set;
        $lint->eof;
    }

    my @errors = $lint->errors();
    is( scalar @errors, scalar @expected, 'Right # of errors' );

    while ( @errors && @expected ) {
        my $error = shift @errors;
        isa_ok( $error, 'HTML::Lint::Error' );

        my $expected = shift @expected;

        is( $error->errcode, $expected->[0], 'Error codes match' );
        my $match = $expected->[1];
        if ( ref $match eq "Regexp" ) {
            like( $error->as_string, $match, 'Error matches regex' );
        }
        else {
            is( $error->as_string, $match, 'Error matches string' );
        }
    }

    my $dump;

    is( scalar @errors, 0, 'No unexpected errors found' ) or $dump = 1;
    is( scalar @expected, 0, 'No expected errors missing' ) or $dump = 1;

    if ( $dump && @errors ) {
        diag( "Leftover errors..." ); 
        diag( $_->as_string ) for @errors;
    }
}

# Read in a set of sets of lines, where each "file" is separated by a
# blank line in <DATA>
sub get_paragraphed_files {
    local $/ = "";

    my @sets;

    while ( my $paragraph = <DATA> ) {
        my @lines = split /\n/, $paragraph;
        @lines = map { "$_\n" } @lines;
        push( @sets, [@lines] );
    }

    return @sets;
}

1; # happy