File: whine.t

package info (click to toggle)
perl 5.20.2-3%2Bdeb8u11
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 102,964 kB
  • sloc: perl: 555,553; ansic: 214,041; sh: 38,121; pascal: 8,783; cpp: 3,895; makefile: 2,393; xml: 2,325; yacc: 1,741
file content (69 lines) | stat: -rw-r--r-- 1,495 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
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
use strict;
use warnings;
use Test::More tests => 4;

{
  package Pod::Simple::ErrorFinder;
  use base 'Pod::Simple::DumpAsXML'; # arbitrary choice -- rjbs, 2013-04-16

  my @errors;
  sub whine {
    my ($self, @rest) = @_;
    push @errors, [ @rest ];
    $self->SUPER::whine(@rest);
  }

  sub scream {
    my ($self, @rest) = @_;
    push @errors, [ @rest ];
    $self->SUPER::scream(@rest);
  }

  sub errors_for_input {
    my ($class, $input, $mutor) = @_;
    @errors = ();

    my $parser = $class->new;
    my $output = '';
    $parser->output_string( \$output );
    $parser->parse_string_document( $input );

    @errors = sort { $a->[0] <=> $b->[0]
                  || $a->[1] cmp $b->[1] } @errors;

    return @errors;
  }
}

sub errors { Pod::Simple::ErrorFinder->errors_for_input(@_) }

{
  my @errors = errors("=over 4\n\n=item 1\n\nHey\n\n");
  is_deeply(
    \@errors,
    [ [ 1, "=over without closing =back" ] ],
    "no closing =back",
  );
}

{
  for my $l_code ('L< foo>', 'L< bar>') {
    my $input = "=pod\n\nAmbiguous space: $l_code\n";
    my @errors = errors("$input");
    is_deeply(
      \@errors,
      [ [ 3, "L<> starts or ends with whitespace" ] ],
      "warning for space in $l_code",
    );
  }
}

{
  my $input = "=pod\n\nAmbiguous slash: L<I/O Operators|op/io>\n";
  my @errors = errors("$input");
  is_deeply(
    \@errors,
    [ [ 3, "alternative text 'I/O Operators' contains non-escaped | or /" ] ],
    "warning for / in text part of L<>",
  );
}