Login
RT #61301: Bug in policy
[gknop/Perl-Critic.git] / t / ValuesAndExpressions / ProhibitCommaSeparatedStatements.run
CommitLineData
c948abe5
ES
1## name Basic passing
2## failures 0
3## cut
4
5@x = (@y, @z);
6my $expl = [133, 138];
7$lookup = { a => 1, b => 2 };
8
9#-----------------------------------------------------------------------------
10
11## name Basic failure
12## failures 1
13## cut
14
15@x = @y, @z;
16
17#-----------------------------------------------------------------------------
18
19## name List including assignments
20## failures 0
21## cut
22
23@w = ($x = 1, $y = 2, $z = 3);
24
25#-----------------------------------------------------------------------------
26
27## name List containing statement
28## failures 0
29## cut
30
31@w = ( {}, [] );
32
33#-----------------------------------------------------------------------------
34
35## name List containing statement in a constructor that is reported as a block
36## failures 0
37## cut
38
39my %foo = (
40 blah => {
41 blah => 'blah',
42 },
43);
44
45#-----------------------------------------------------------------------------
46
47## name Regular statement inside a block.
27ac78c7 48## failures 0
c948abe5
ES
49## cut
50
51foreach my $path ( @ARGV ) {
27ac78c7 52 utter 'Looking at ', $path, '.';
c948abe5
ES
53}
54
55#-----------------------------------------------------------------------------
56
57## name Sub call after comma
58## failures 1
59## cut
60
61@x = @y, foo @z;
62
63#-----------------------------------------------------------------------------
64
65## name Regular sub call before comma
66## failures 1
67## cut
68
27ac78c7
ES
69# The space between the sub name and the left parenthesis is significant
70# in that part of Conway's point is that things that look like lists may
71# not be.
72
73@x = foo (@y), @z;
c948abe5
ES
74
75#-----------------------------------------------------------------------------
76
77## name No-argument sub call via use of sigil
78## failures 1
79## cut
80
81@x = &foo, @y, bar @z;
82
83#-----------------------------------------------------------------------------
84
85## name Two sub calls
27ac78c7 86## failures 0
c948abe5
ES
87## cut
88
89@x = foo @y, bar @z;
90
91#-----------------------------------------------------------------------------
92
27ac78c7 93## name Built-in call that provides a list context without parentheses
c948abe5
ES
94## failures 0
95## cut
96
97@x = push @y, @z;
98
99#-----------------------------------------------------------------------------
100
101## name Built-in call that provides a list context, called like a function
102## failures 1
103## cut
104
105@x = push (@y), @z;
106
107#-----------------------------------------------------------------------------
108
109## name Built-in call that takes multiple arguments without parentheses
110## failures 0
111## cut
112
27ac78c7
ES
113@x = substr $y, 1, 2;
114
115#-----------------------------------------------------------------------------
116
117## name Built-in call that takes multiple arguments, called like a function
118## failures 1
119## cut
120
121@x = substr ($y, 1), 2;
122
123#-----------------------------------------------------------------------------
124
125## name Call to unary built-in without parentheses
126## failures 1
127## cut
128
129@x = tied @y, @z;
130
131#-----------------------------------------------------------------------------
132
133## name Unary built-in, called like a function
134## failures 1
135## cut
136
137@x = tied (@y), @z;
c948abe5
ES
138
139#-----------------------------------------------------------------------------
140
27ac78c7 141## name Call to no-argument built-in without parentheses
c948abe5
ES
142## failures 1
143## cut
144
27ac78c7 145@x = time, @z;
c948abe5
ES
146
147#-----------------------------------------------------------------------------
148
27ac78c7
ES
149## name No-argument built-in, called like a function
150## failures 1
151## cut
152
153@x = time (), @z;
154
155#-----------------------------------------------------------------------------
156
157## name Call to optional argument built-in without an argument without parentheses
158## failures 1
159## cut
160
161@x = sin, @z;
162
163#-----------------------------------------------------------------------------
164
165## name Optional argument built-in, called like a function without an argument
166## failures 1
167## cut
168
169@x = sin (), @z;
170
171#-----------------------------------------------------------------------------
172
173## name Call to optional argument built-in with an argument without parentheses
c948abe5
ES
174## failures 1
175## cut
176
177@x = sin @y, @z;
178
179#-----------------------------------------------------------------------------
180
27ac78c7
ES
181## name Optional argument built-in, called like a function with an argument
182## failures 1
183## cut
184
185@x = sin (@y), @z;
186
187#-----------------------------------------------------------------------------
188
c948abe5
ES
189## name For loop
190## failures 2
191## cut
192
193for ($x = 0, $y = 0; $x < 10; $x++, $y += 2) {
194 foo($x, $y);
195}
196
197#-----------------------------------------------------------------------------
198
9fae7483
CD
199## name For loop
200## failures 0
201## cut
202
e1a212fa 203for ($x, 'x', @y, 1, ) {
9fae7483
CD
204 print;
205}
206
207#-----------------------------------------------------------------------------
208
b34e4aff
CD
209## name qw<>
210## failures 0
211## cut
212
213@list = qw<1, 2, 3>; # this really means @list = ('1,', '2,', '3');
214
215#-----------------------------------------------------------------------------
216
72c43035 217## name original RT #27654
b6bc38d4
ES
218## failures 0
219## cut
220
221my @arr1;
222@arr1 = split /b/, 'abc';
223
224#-----------------------------------------------------------------------------
225
72c43035
ES
226## name RT #27654 - NKH example 1
227## failures 0
c87d8e37 228## TODO PPI parses this code as a block and not a hash constructor.
72c43035
ES
229## cut
230
231return
232 {
233 "string" => $aliased_history,
234 TIME => $self->{something},
235 } ;
236
237#-----------------------------------------------------------------------------
238
c87d8e37
ES
239## name RT #27654 - NKH example 2 - without allow_last_statement_to_be_comma_separated_in_map_and_grep
240## failures 1
241## cut
242
243%hash = map {$_, 1} @list ;
244
245#-----------------------------------------------------------------------------
246
247## name RT #27654 - NKH example 2 - with allow_last_statement_to_be_comma_separated_in_map_and_grep
72c43035 248## failures 0
c87d8e37 249## parms { allow_last_statement_to_be_comma_separated_in_map_and_grep => 1 }
72c43035
ES
250## cut
251
252%hash = map {$_, 1} @list ;
253
254#-----------------------------------------------------------------------------
255
256## name RT #27654 - NKH example 3
257## failures 0
c87d8e37 258## TODO PPI parses this code as blocks and not hash constructors.
72c43035
ES
259## cut
260
261$self->DoSomething
262 (
263 { %{$a_hash_ref}, %{$another_hash_ref}},
264 @more_data,
265 ) ;
266
267#-----------------------------------------------------------------------------
268
3beeb9e7 269## name RT #33935 and 49679
9f662e12
KH
270## failures 0
271## cut
272
273func( @{ $href }{'1', '2'} );
274
275#-----------------------------------------------------------------------------
276
45a557b1
TW
277## name RT #61301 (requires PPI 1.215)
278## failures 0
279## cut
280
281sub foo {
282 return { bar => 1, answer => 42 };
283}
284
285#-----------------------------------------------------------------------------
286
c948abe5
ES
287##############################################################################
288# $URL$
289# $Date$
290# $Author$
291# $Revision$
292##############################################################################
293
294# Local Variables:
295# mode: cperl
296# cperl-indent-level: 4
297# fill-column: 78
298# indent-tabs-mode: nil
299# c-indentation-style: bsd
300# End:
96fed375 301# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :