Commit | Line | Data |
---|---|---|
b5ae6e74 CBW |
1 | use strict; |
2 | use warnings; | |
3 | use Test::More tests => 4; | |
4 | ||
5 | { | |
6 | package Pod::Simple::ErrorFinder; | |
7 | use base 'Pod::Simple::DumpAsXML'; # arbitrary choice -- rjbs, 2013-04-16 | |
8 | ||
9 | my @errors; | |
10 | sub whine { | |
11 | my ($self, @rest) = @_; | |
12 | push @errors, [ @rest ]; | |
13 | $self->SUPER::whine(@rest); | |
14 | } | |
15 | ||
16 | sub scream { | |
17 | my ($self, @rest) = @_; | |
18 | push @errors, [ @rest ]; | |
19 | $self->SUPER::scream(@rest); | |
20 | } | |
21 | ||
22 | sub errors_for_input { | |
23 | my ($class, $input, $mutor) = @_; | |
24 | @errors = (); | |
25 | ||
26 | my $parser = $class->new; | |
27 | my $output = ''; | |
28 | $parser->output_string( \$output ); | |
29 | $parser->parse_string_document( $input ); | |
30 | ||
31 | @errors = sort { $a->[0] <=> $b->[0] | |
32 | || $a->[1] cmp $b->[1] } @errors; | |
33 | ||
34 | return @errors; | |
35 | } | |
36 | } | |
37 | ||
38 | sub errors { Pod::Simple::ErrorFinder->errors_for_input(@_) } | |
39 | ||
40 | { | |
41 | my @errors = errors("=over 4\n\n=item 1\n\nHey\n\n"); | |
42 | is_deeply( | |
43 | \@errors, | |
44 | [ [ 1, "=over without closing =back" ] ], | |
45 | "no closing =back", | |
46 | ); | |
47 | } | |
48 | ||
49 | { | |
50 | for my $l_code ('L< foo>', 'L< bar>') { | |
51 | my $input = "=pod\n\nAmbiguous space: $l_code\n"; | |
52 | my @errors = errors("$input"); | |
53 | is_deeply( | |
54 | \@errors, | |
55 | [ [ 3, "L<> starts or ends with whitespace" ] ], | |
56 | "warning for space in $l_code", | |
57 | ); | |
58 | } | |
59 | } | |
60 | ||
61 | { | |
62 | my $input = "=pod\n\nAmbiguous slash: L<I/O Operators|op/io>\n"; | |
63 | my @errors = errors("$input"); | |
64 | is_deeply( | |
65 | \@errors, | |
66 | [ [ 3, "alternative text 'I/O Operators' contains non-escaped | or /" ] ], | |
67 | "warning for / in text part of L<>", | |
68 | ); | |
69 | } |