File: 20_policy_prohibit_hard_tabs.t

package info (click to toggle)
libperl-critic-perl 1.156-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 3,544 kB
  • sloc: perl: 24,092; lisp: 341; makefile: 7
file content (195 lines) | stat: -rw-r--r-- 3,684 bytes parent folder | download
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!perl

use 5.010001;
use strict;
use warnings;

# common P::C testing tools
use Perl::Critic::TestUtils qw(pcritique fcritique);

use Test::More tests => 10;

our $VERSION = '1.156';

Perl::Critic::TestUtils::assert_version( $VERSION );
Perl::Critic::TestUtils::block_perlcriticrc();

# This specific policy is being tested without run.t because the .run file
# would have to contain invisible characters.

my $code;
my $policy = 'CodeLayout::ProhibitHardTabs';
my %config;

#-----------------------------------------------------------------------------

$code = <<"END_PERL";
#This will be interpolated!

sub my_sub {
\tfor(1){
\t\tdo_something();
\t}
}

\t\t\t;

END_PERL

is( pcritique($policy, \$code), 0, $policy );

#-----------------------------------------------------------------------------

$code = <<"END_PERL";
#This will be interpolated!
print "\t  \t  foobar  \t";
END_PERL

is( pcritique($policy, \$code), 1, $policy );

#-----------------------------------------------------------------------------

$code = <<"END_PERL";
#This will be interpolated!

my \@list = qw(
\tfoo
\tbar
\tbaz
);

END_PERL

is( pcritique($policy, \$code, \%config), 0, 'Leading tabs in qw()' );

#-----------------------------------------------------------------------------

$code = <<"END_PERL";
#This will be interpolated!

my \@list = qw(
\tfoo\tbar
\tbaz\tnuts
);

END_PERL

is( pcritique($policy, \$code, \%config), 1, 'Non-leading tabs in qw()' );

#-----------------------------------------------------------------------------
# RT #32440

$code = <<"END_PERL";
#This will be interpolated!
\$x =~ m/
\tsome
\t(really | long)
\tpattern
/mx;

#This will be interpolated!
\$z = qr/
\tsome
\t(really | long)
\tpattern
/mx;

END_PERL

is( pcritique($policy, \$code, \%config), 0, 'Leading tabs in extended regex' );

#-----------------------------------------------------------------------------
# RT #32440

$code = <<"END_PERL";
#This will be interpolated!
#Note that these regex does not have /x, so tabs are significant

\$x =~ m/
\tsome
\tugly
\tpattern
/m;


\$z = qr/
\tsome
\tugly
\tpattern
/gis;

END_PERL

is( pcritique($policy, \$code, \%config), 2, 'Leading tabs in non-extended regex' );

#-----------------------------------------------------------------------------
# RT #32440

$code = <<"END_PERL";
#This will be interpolated!
#Note that these regex does not have /x, so tabs are significant

\$x =~ m/
\tsome\tugly\tpattern
/xm;

END_PERL

is( pcritique($policy, \$code, \%config), 1, 'Non-leading tabs in extended regex' );

#-----------------------------------------------------------------------------

$code = <<"END_PERL";
##This will be interpolated!

sub my_sub {
\tfor(1){
\t\tdo_something();
\t}
}

END_PERL

%config = (allow_leading_tabs => 0);
is( pcritique($policy, \$code, \%config), 3, $policy );

#-----------------------------------------------------------------------------

$code = <<"END_PERL";
##This will be interpolated!

sub my_sub {
;\tfor(1){
\t\tdo_something();
;\t}
}

END_PERL

%config = (allow_leading_tabs => 0);
is( pcritique($policy, \$code, \%config), 3, $policy );

#-----------------------------------------------------------------------------

$code = <<"END_PERL";
#This will be interpolated!

__DATA__
foo\tbar\tbaz
\tfred\barney

END_PERL

%config = (allow_leading_tabs => 0);
is( pcritique($policy, \$code, \%config), 0, 'Tabs in __DATA__' );

#-----------------------------------------------------------------------------

# Local Variables:
#   mode: cperl
#   cperl-indent-level: 4
#   fill-column: 78
#   indent-tabs-mode: nil
#   c-indentation-style: bsd
# End:
# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :