fb98881681e59b651d86e2692c4b33e9ae8ca1a5
[pkg-perl] / deb-src / libperl-critic-perl / libperl-critic-perl-1.088 / t / 20_policy_requireconsistentnewlines.t
1 #!perl
2
3 ##############################################################################
4 #      $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/t/20_policy_requireconsistentnewlines.t $
5 #     $Date: 2008-06-06 00:48:04 -0500 (Fri, 06 Jun 2008) $
6 #   $Author: clonezone $
7 # $Revision: 2416 $
8 ##############################################################################
9
10 use 5.006001;
11 use strict;
12 use warnings;
13 use Test::More tests => 29;
14
15 # common P::C testing tools
16 use Perl::Critic::TestUtils qw(pcritique fcritique);
17 Perl::Critic::TestUtils::block_perlcriticrc();
18
19 my $code;
20 my $policy = 'CodeLayout::RequireConsistentNewlines';
21
22 my $base_code = <<'END_PERL';
23 package My::Pkg;
24 my $str = <<"HEREDOC";
25 heredoc_body
26 heredoc_body
27 HEREDOC
28
29 =head1 POD_HEADER
30
31 pod pod pod
32
33 =cut
34
35 # comment_line
36
37 1; # inline_comment
38
39 __END__
40 end_body
41 __DATA__
42 DataLine1
43 DataLine2
44 END_PERL
45
46 is( fcritique($policy, \$base_code), 0, $policy );
47
48 my @lines = split m/\n/mx, $base_code;
49 for my $keyword (qw( Pkg; heredoc_body HEREDOC POD_HEADER pod =cut
50                      comment_line inline_comment
51                      __END__ end_body __DATA__ DataLine1 DataLine2 )) {
52     my $is_first_line = $lines[0] =~ m/\Q$keyword\E\z/mx;
53     my $nfail = $is_first_line ? @lines-1 : 1;
54     for my $nl ("\012", "\015", "\015\012") {
55         next if $nl eq "\n";
56         ($code = $base_code) =~ s/(\Q$keyword\E)\n/$1$nl/;
57         is( fcritique($policy, \$code), $nfail, $policy.' - '.$keyword );
58     }
59 }
60
61 for my $nl ("\012", "\015", "\015\012") {
62     next if $nl eq "\n";
63     ($code = $base_code) =~ s/\n/$nl/;
64     is( pcritique($policy, \$code), 0, $policy.' - no filename' );
65 }
66
67 # Local Variables:
68 #   mode: cperl
69 #   cperl-indent-level: 4
70 #   fill-column: 78
71 #   indent-tabs-mode: nil
72 #   c-indentation-style: bsd
73 # End:
74 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :