This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
bench.pl: add 'compile' benchmark field
[perl5.git] / t / perf / benchmarks
CommitLineData
24fb648d
DM
1#!perl
2
9e7973fa 3# This file specifies an array-of-hashes that define snippets of code that
24fb648d
DM
4# can be run by various measurement and profiling tools.
5#
6# The basic idea is that any time you add an optimisation that is intended
7# to make a particular construct faster, then you should add that construct
8# to this file.
9#
10# Under the normal test suite, the test file benchmarks.t does a basic
11# compile and run of each of these snippets; not to test performance,
12# but just to ensure that the code doesn't have errors.
13#
14# Over time, it is intended that various measurement and profiling tools
15# will be written that can run selected (or all) snippets in various
16# environments. These will not be run as part of a normal test suite run.
17#
9e7973fa
DM
18# It is intended that the tests in this file will be lightweight; e.g.
19# a hash access, an empty function call, or a single regex match etc.
20#
24fb648d
DM
21# This file is designed to be read in by 'do' (and in such a way that
22# multiple versions of this file from different releases can be read in
23# by a single process).
24#
9e7973fa
DM
25# The top-level array has name/hash pairs (we use an array rather than a
26# hash so that duplicate keys can be spotted) Each name is a token that
27# describes a particular test. Code will be compiled in the package named
28# after the token, so it should match /^(\w|::)+$/a. It is intended that
29# this can be used on the command line of tools to select particular
30# tests.
31# In addition, the package names are arranged into an informal hierarchy
32# whose top members are (this is subject to change):
33#
34# call:: subroutine and method handling
35# expr:: expressions: e.g. $x=1, $foo{bar}[0]
84721d61 36# func:: perl functions, e.g. func::sort::...
9e7973fa
DM
37# loop:: structural code like for, while(), etc
38# regex:: regular expressions
39# string:: string handling
24fb648d 40#
9e7973fa 41#
485eb009 42# Each hash has up to five fields:
24fb648d 43#
b0ecc2e1
DM
44# desc is a description of the test; if not present, it defaults
45# to the same value as the 'code' field
46#
485eb009 47# setup is an optional string containing setup code that is run once
b0ecc2e1 48#
24fb648d
DM
49# code is a string containing the code to run in a loop
50#
485eb009
DM
51# pre is an optional string containing setup code which is executed
52# just before 'code' for every iteration, but whose execution
53# time is not included in the result
24fb648d 54#
485eb009
DM
55# post like pre, but executed just after 'code'.
56#
57# So typically a benchmark tool might execute variations on something like
58#
59# eval "package $name; $setup; for (1..1000000) { $pre; $code; $post }"
9e7973fa
DM
60#
61# Currently the only tool that uses this file is Porting/bench.pl;
62# try C<perl Porting/bench.pl --help> for more info
15a75fdb
DM
63#
64# ------
65#
66# Note: for the cachegrind variant, an entry like
67# 'foo::bar' => {
68# setup => 'SETUP',
485eb009 69# pre => 'PRE',
15a75fdb 70# code => 'CODE',
485eb009 71# post => 'POST',
15a75fdb
DM
72# }
73# creates two temporary perl sources looking like:
74#
75# package foo::bar;
76# BEGIN { srand(0) }
77# SETUP;
78# for my $__loop__ (1..$ARGV[0]) {
485eb009 79# PRE; 1; POST;
15a75fdb 80# }
5247d03d 81#
485eb009 82# and as above, but with the loop body replaced with:
5247d03d 83#
485eb009 84# PRE; CODE; POST;
15a75fdb
DM
85#
86# It then pipes each of the two sources into
5247d03d 87#
15a75fdb 88# PERL_HASH_SEED=0 valgrind [options] someperl [options] - N
5247d03d
DM
89#
90# where N is set to 10 and then 20.
91#
92# It then uses the result of those four cachegrind runs to subtract out
485eb009
DM
93# the perl startup and loop overheads (including SETUP, PRE and POST), leaving
94# (in theory only CODE);
95#
96# Note that misleading results may be obtained if each iteration is
97# not identical. For example with
98#
99# code => '$x .= "foo"',
100#
101# the string $x gets longer on each iteration. Similarly, a hash might be
102# empty on the first iteration, but have entries on subsequent iterations.
103#
104# To avoid this, use 'pre' or 'post', e.g.
105#
106# pre => '$x = ""',
107# code => '$x .= "foo"',
108#
a9b10838
DM
109# Finally, the optional 'compile' key causes the code body to be wrapped
110# in eval qw{ sub { ... }}, so that compile time rather than execution
111# time is measured.
24fb648d
DM
112
113
9e7973fa 114[
e800e134
DM
115 'call::sub::empty' => {
116 desc => 'function call with no args or body',
117 setup => 'sub f { }',
118 code => 'f()',
119 },
f7a874b8
DM
120 'call::sub::amp_empty' => {
121 desc => '&foo function call with no args or body',
122 setup => 'sub f { }; @_ = ();',
123 code => '&f',
124 },
e800e134 125 'call::sub::args3' => {
9e7973fa 126 desc => 'function call with 3 local lexical vars',
e800e134
DM
127 setup => 'sub f { my ($a, $b, $c) = @_; 1 }',
128 code => 'f(1,2,3)',
129 },
f7a874b8
DM
130 'call::sub::args2_ret1' => {
131 desc => 'function call with 2 local lex vars and 1 return value',
132 setup => 'my $x; sub f { my ($a, $b) = @_; $a+$b }',
133 code => '$x = f(1,2)',
134 },
135 'call::sub::args2_ret1temp' => {
136 desc => 'function call with 2 local lex vars and 1 return TEMP value',
137 setup => 'my $x; sub f { my ($a, $b) = @_; \$a }',
138 code => '$x = f(1,2)',
139 },
e800e134
DM
140 'call::sub::args3_ret3' => {
141 desc => 'function call with 3 local lex vars and 3 return values',
142 setup => 'my @a; sub f { my ($a, $b, $c) = @_; $a+$b, $c, 1 }',
143 code => '@a = f(1,2,3)',
144 },
f7a874b8
DM
145 'call::sub::args3_ret3str' => {
146 desc => 'function call with 3 local lex vars and 3 string return values',
147 setup => 'my @a; sub f { my ($a, $b, $c) = @_; my @s = ("aa","bb","cc"); @s }',
148 code => '@a = f(1,2,3)',
149 },
150 'call::sub::args3_ret3temp' => {
151 desc => 'function call with 3 local lex vars and 3 TEMP return values',
152 setup => 'my @a; sub f { my ($a, $b, $c) = @_; 1..3 }',
153 code => '@a = f(1,2,3)',
154 },
155 'call::sub::recursive' => {
156 desc => 'basic recursive function call',
157 setup => 'my $x; sub f { my ($i) = @_; $i > 0 ? $i + f($i-1) : 0 }',
158 code => '$x = f(1)',
159 },
e800e134
DM
160
161 'call::goto::empty' => {
162 desc => 'goto &funtion with no args or body',
163 setup => 'sub f { goto &g } sub g {}',
164 code => 'f()',
165 },
166 'call::goto::args3' => {
167 desc => 'goto &funtion with 3 local lexical vars',
168 setup => 'sub f { goto &g } sub g { my ($a, $b, $c) = @_ }',
9e7973fa
DM
169 code => 'f(1,2,3)',
170 },
171
fedf30e1
DM
172
173 'expr::array::lex_1const_0' => {
174 desc => 'lexical $array[0]',
175 setup => 'my @a = (1)',
176 code => '$a[0]',
177 },
178 'expr::array::lex_1const_m1' => {
179 desc => 'lexical $array[-1]',
180 setup => 'my @a = (1)',
181 code => '$a[-1]',
182 },
183 'expr::array::lex_2const' => {
184 desc => 'lexical $array[const][const]',
185 setup => 'my @a = ([1,2])',
186 code => '$a[0][1]',
187 },
188 'expr::array::lex_2var' => {
189 desc => 'lexical $array[$i1][$i2]',
190 setup => 'my ($i1,$i2) = (0,1); my @a = ([1,2])',
191 code => '$a[$i1][$i2]',
192 },
193 'expr::array::ref_lex_2var' => {
194 desc => 'lexical $arrayref->[$i1][$i2]',
195 setup => 'my ($i1,$i2) = (0,1); my $r = [[1,2]]',
196 code => '$r->[$i1][$i2]',
197 },
198 'expr::array::ref_lex_3const' => {
199 desc => 'lexical $arrayref->[const][const][const]',
200 setup => 'my $r = [[[1,2]]]',
201 code => '$r->[0][0][0]',
202 },
203 'expr::array::ref_expr_lex_3const' => {
204 desc => '(lexical expr)->[const][const][const]',
205 setup => 'my $r = [[[1,2]]]',
92792a1c 206 code => '($r||0)->[0][0][0]',
fedf30e1
DM
207 },
208
209
210 'expr::array::pkg_1const_0' => {
211 desc => 'package $array[0]',
92792a1c 212 setup => '@a = (1)',
fedf30e1
DM
213 code => '$a[0]',
214 },
215 'expr::array::pkg_1const_m1' => {
216 desc => 'package $array[-1]',
92792a1c 217 setup => '@a = (1)',
fedf30e1
DM
218 code => '$a[-1]',
219 },
220 'expr::array::pkg_2const' => {
221 desc => 'package $array[const][const]',
92792a1c 222 setup => '@a = ([1,2])',
fedf30e1
DM
223 code => '$a[0][1]',
224 },
225 'expr::array::pkg_2var' => {
226 desc => 'package $array[$i1][$i2]',
92792a1c 227 setup => '($i1,$i2) = (0,1); @a = ([1,2])',
fedf30e1
DM
228 code => '$a[$i1][$i2]',
229 },
230 'expr::array::ref_pkg_2var' => {
231 desc => 'package $arrayref->[$i1][$i2]',
92792a1c 232 setup => '($i1,$i2) = (0,1); $r = [[1,2]]',
fedf30e1
DM
233 code => '$r->[$i1][$i2]',
234 },
235 'expr::array::ref_pkg_3const' => {
236 desc => 'package $arrayref->[const][const][const]',
92792a1c 237 setup => '$r = [[[1,2]]]',
fedf30e1
DM
238 code => '$r->[0][0][0]',
239 },
240 'expr::array::ref_expr_pkg_3const' => {
241 desc => '(package expr)->[const][const][const]',
92792a1c
DM
242 setup => '$r = [[[1,2]]]',
243 code => '($r||0)->[0][0][0]',
fedf30e1
DM
244 },
245
7be75ccf
DM
246 'expr::array::lex_bool_empty' => {
247 desc => 'empty lexical array in boolean context',
248 setup => 'my @a;',
249 code => '!@a',
250 },
251 'expr::array::lex_bool_full' => {
252 desc => 'non-empty lexical array in boolean context',
253 setup => 'my @a = 1..10;',
254 code => '!@a',
255 },
256 'expr::array::lex_scalar_empty' => {
257 desc => 'empty lexical array in scalar context',
258 setup => 'my (@a, $i);',
259 code => '$i = @a',
260 },
261 'expr::array::lex_scalar_full' => {
262 desc => 'non-empty lexical array in scalar context',
263 setup => 'my @a = 1..10; my $i',
264 code => '$i = @a',
265 },
266 'expr::array::pkg_bool_empty' => {
267 desc => 'empty lexical array in boolean context',
268 setup => 'our @a;',
269 code => '!@a',
270 },
271 'expr::array::pkg_bool_full' => {
272 desc => 'non-empty lexical array in boolean context',
273 setup => 'our @a = 1..10;',
274 code => '!@a',
275 },
276 'expr::array::pkg_scalar_empty' => {
277 desc => 'empty lexical array in scalar context',
278 setup => 'our @a; my $i;',
279 code => '$i = @a',
280 },
281 'expr::array::pkg_scalar_full' => {
282 desc => 'non-empty lexical array in scalar context',
283 setup => 'our @a = 1..10; my $i',
284 code => '$i = @a',
285 },
fedf30e1
DM
286
287 'expr::arrayhash::lex_3var' => {
288 desc => 'lexical $h{$k1}[$i]{$k2}',
289 setup => 'my ($i, $k1, $k2) = (0,"foo","bar");'
290 . 'my %h = (foo => [ { bar => 1 } ])',
291 code => '$h{$k1}[$i]{$k2}',
292 },
293 'expr::arrayhash::pkg_3var' => {
294 desc => 'package $h{$k1}[$i]{$k2}',
92792a1c
DM
295 setup => '($i, $k1, $k2) = (0,"foo","bar");'
296 . '%h = (foo => [ { bar => 1 } ])',
fedf30e1
DM
297 code => '$h{$k1}[$i]{$k2}',
298 },
299
fedf30e1
DM
300 'expr::hash::lex_1const' => {
301 desc => 'lexical $hash{const}',
302 setup => 'my %h = ("foo" => 1)',
303 code => '$h{foo}',
304 },
305 'expr::hash::lex_2const' => {
306 desc => 'lexical $hash{const}{const}',
307 setup => 'my %h = (foo => { bar => 1 })',
308 code => '$h{foo}{bar}',
309 },
310 'expr::hash::lex_2var' => {
311 desc => 'lexical $hash{$k1}{$k2}',
312 setup => 'my ($k1,$k2) = qw(foo bar); my %h = ($k1 => { $k2 => 1 })',
313 code => '$h{$k1}{$k2}',
314 },
315 'expr::hash::ref_lex_2var' => {
316 desc => 'lexical $hashref->{$k1}{$k2}',
317 setup => 'my ($k1,$k2) = qw(foo bar); my $r = {$k1 => { $k2 => 1 }}',
318 code => '$r->{$k1}{$k2}',
319 },
320 'expr::hash::ref_lex_3const' => {
321 desc => 'lexical $hashref->{const}{const}{const}',
322 setup => 'my $r = {foo => { bar => { baz => 1 }}}',
323 code => '$r->{foo}{bar}{baz}',
324 },
325 'expr::hash::ref_expr_lex_3const' => {
326 desc => '(lexical expr)->{const}{const}{const}',
327 setup => 'my $r = {foo => { bar => { baz => 1 }}}',
92792a1c 328 code => '($r||0)->{foo}{bar}{baz}',
fedf30e1
DM
329 },
330
fedf30e1
DM
331 'expr::hash::pkg_1const' => {
332 desc => 'package $hash{const}',
92792a1c 333 setup => '%h = ("foo" => 1)',
fedf30e1
DM
334 code => '$h{foo}',
335 },
336 'expr::hash::pkg_2const' => {
337 desc => 'package $hash{const}{const}',
92792a1c 338 setup => '%h = (foo => { bar => 1 })',
fedf30e1
DM
339 code => '$h{foo}{bar}',
340 },
341 'expr::hash::pkg_2var' => {
342 desc => 'package $hash{$k1}{$k2}',
92792a1c 343 setup => '($k1,$k2) = qw(foo bar); %h = ($k1 => { $k2 => 1 })',
fedf30e1
DM
344 code => '$h{$k1}{$k2}',
345 },
346 'expr::hash::ref_pkg_2var' => {
347 desc => 'package $hashref->{$k1}{$k2}',
92792a1c 348 setup => '($k1,$k2) = qw(foo bar); $r = {$k1 => { $k2 => 1 }}',
fedf30e1
DM
349 code => '$r->{$k1}{$k2}',
350 },
351 'expr::hash::ref_pkg_3const' => {
352 desc => 'package $hashref->{const}{const}{const}',
92792a1c 353 setup => '$r = {foo => { bar => { baz => 1 }}}',
fedf30e1
DM
354 code => '$r->{foo}{bar}{baz}',
355 },
356 'expr::hash::ref_expr_pkg_3const' => {
357 desc => '(package expr)->{const}{const}{const}',
92792a1c
DM
358 setup => '$r = {foo => { bar => { baz => 1 }}}',
359 code => '($r||0)->{foo}{bar}{baz}',
fedf30e1
DM
360 },
361
362
363 'expr::hash::exists_lex_2var' => {
364 desc => 'lexical exists $hash{$k1}{$k2}',
365 setup => 'my ($k1,$k2) = qw(foo bar); my %h = ($k1 => { $k2 => 1 });',
366 code => 'exists $h{$k1}{$k2}',
367 },
36f9501c 368
7adc03cc
DM
369 'expr::hash::bool_empty' => {
370 desc => 'empty lexical hash in boolean context',
371 setup => 'my %h;',
372 code => '!%h',
373 },
775f2c07
DM
374 'expr::hash::bool_empty_unknown' => {
375 desc => 'empty lexical hash in unknown context',
376 setup => 'my ($i, %h); sub f { if (%h) { $i++ }}',
377 code => 'f()',
378 },
7adc03cc
DM
379 'expr::hash::bool_full' => {
380 desc => 'non-empty lexical hash in boolean context',
381 setup => 'my %h = 1..10;',
382 code => '!%h',
383 },
384
385
36f9501c
YO
386 (
387 map {
388 sprintf('expr::hash::notexists_lex_keylen%04d',$_) => {
389 desc => 'exists on non-key of length '. $_,
390 setup => 'my %h; my $key = "A" x ' . $_ . '; $h{$key."x"} = 1;',
391 code => 'exists $h{$key}',
392 },
393 } (
394 1 .. 24,
395 # 1,2,3,7,8,9,14,15,16,20,24,
396 50,
397 100,
398 1000,
399 )
400 ),
401 (
402 map {
403 sprintf('expr::hash::exists_lex_keylen%04d',$_) => {
404 desc => 'exists on existing key of length '. $_,
405 setup => 'my %h; my $key = "A" x ' . $_ . '; $h{$key} = 1;',
406 code => 'exists $h{$key}',
407 },
408 } (
409 1 .. 24,
410 # 1,2,3,7,8,9,14,15,16,20,24,
411 50,
412 100,
413 1000,
414 )
415 ),
416
fedf30e1
DM
417 'expr::hash::delete_lex_2var' => {
418 desc => 'lexical delete $hash{$k1}{$k2}',
419 setup => 'my ($k1,$k2) = qw(foo bar); my %h = ($k1 => { $k2 => 1 });',
420 code => 'delete $h{$k1}{$k2}',
421 },
422
423
a5f48505
DM
424 # list assign, OP_AASSIGN
425
426
427 # (....) = ()
428
429 'expr::aassign::ma_empty' => {
430 desc => 'my array assigned empty',
431 setup => '',
432 code => 'my @a = ()',
433 },
434 'expr::aassign::lax_empty' => {
435 desc => 'non-empty lexical array assigned empty',
436 setup => 'my @a = 1..3;',
437 code => '@a = ()',
438 },
439 'expr::aassign::llax_empty' => {
440 desc => 'non-empty lexical var and array assigned empty',
441 setup => 'my ($x, @a) = 1..4;',
442 code => '($x, @a) = ()',
443 },
8b0c3377
DM
444 'expr::aassign::mh_empty' => {
445 desc => 'my hash assigned empty',
446 setup => '',
447 code => 'my %h = ()',
448 },
449 'expr::aassign::lhx_empty' => {
450 desc => 'non-empty lexical hash assigned empty',
451 setup => 'my %h = 1..4;',
452 code => '%h = ()',
453 },
454 'expr::aassign::llhx_empty' => {
455 desc => 'non-empty lexical var and hash assigned empty',
456 setup => 'my ($x, %h) = 1..5;',
457 code => '($x, %h) = ()',
458 },
a5f48505
DM
459 'expr::aassign::3m_empty' => {
460 desc => 'three my vars assigned empty',
461 setup => '',
462 code => 'my ($x,$y,$z) = ()',
463 },
464 'expr::aassign::3l_empty' => {
465 desc => 'three lexical vars assigned empty',
466 setup => 'my ($x,$y,$z)',
467 code => '($x,$y,$z) = ()',
468 },
e03e82a0
DM
469 'expr::aassign::3lref_empty' => {
470 desc => 'three lexical ref vars assigned empty',
471 setup => 'my ($x,$y,$z); my $r = []; ',
472 code => '($x,$y,$z) = ($r,$r,$r); ($x,$y,$z) = ()',
473 },
a5f48505
DM
474 'expr::aassign::pa_empty' => {
475 desc => 'package array assigned empty',
476 setup => '',
477 code => '@a = ()',
478 },
479 'expr::aassign::pax_empty' => {
480 desc => 'non-empty package array assigned empty',
481 setup => '@a = (1,2,3)',
482 code => '@a = ()',
483 },
484 'expr::aassign::3p_empty' => {
485 desc => 'three package vars assigned empty',
486 setup => '($x,$y,$z) = 1..3;',
487 code => '($x,$y,$z) = ()',
488 },
489
490 # (....) = (1,2,3)
491
492 'expr::aassign::ma_3c' => {
493 desc => 'my array assigned 3 consts',
494 setup => '',
495 code => 'my @a = (1,2,3)',
496 },
497 'expr::aassign::lax_3c' => {
498 desc => 'non-empty lexical array assigned 3 consts',
499 setup => 'my @a = 1..3;',
500 code => '@a = (1,2,3)',
501 },
502 'expr::aassign::llax_3c' => {
503 desc => 'non-empty lexical var and array assigned 3 consts',
504 setup => 'my ($x, @a) = 1..4;',
505 code => '($x, @a) = (1,2,3)',
506 },
8b0c3377
DM
507 'expr::aassign::mh_4c' => {
508 desc => 'my hash assigned 4 consts',
509 setup => '',
510 code => 'my %h = qw(a 1 b 2)',
511 },
512 'expr::aassign::lhx_4c' => {
513 desc => 'non-empty lexical hash assigned 4 consts',
514 setup => 'my %h = qw(a 1 b 2);',
515 code => '%h = qw(c 3 d 4)',
516 },
517 'expr::aassign::llhx_5c' => {
518 desc => 'non-empty lexical var and array assigned 5 consts',
519 setup => 'my ($x, %h) = (1, qw(a 1 b 2));',
520 code => '($x, %h) = (10, qw(c 3 d 4))',
521 },
a5f48505
DM
522 'expr::aassign::3m_3c' => {
523 desc => 'three my vars assigned 3 consts',
524 setup => '',
525 code => 'my ($x,$y,$z) = (1,2,3)',
526 },
527 'expr::aassign::3l_3c' => {
528 desc => 'three lexical vars assigned 3 consts',
529 setup => 'my ($x,$y,$z)',
530 code => '($x,$y,$z) = (1,2,3)',
531 },
532 'expr::aassign::pa_3c' => {
533 desc => 'package array assigned 3 consts',
534 setup => '',
535 code => '@a = (1,2,3)',
536 },
537 'expr::aassign::pax_3c' => {
538 desc => 'non-empty package array assigned 3 consts',
539 setup => '@a = (1,2,3)',
540 code => '@a = (1,2,3)',
541 },
542 'expr::aassign::3p_3c' => {
543 desc => 'three package vars assigned 3 consts',
544 setup => '($x,$y,$z) = 1..3;',
545 code => '($x,$y,$z) = (1,2,3)',
546 },
547
548 # (....) = @lexical
549
550 'expr::aassign::ma_la' => {
551 desc => 'my array assigned lexical array',
552 setup => 'my @init = 1..3;',
553 code => 'my @a = @init',
554 },
555 'expr::aassign::lax_la' => {
556 desc => 'non-empty lexical array assigned lexical array',
557 setup => 'my @init = 1..3; my @a = 1..3;',
558 code => '@a = @init',
559 },
560 'expr::aassign::llax_la' => {
561 desc => 'non-empty lexical var and array assigned lexical array',
562 setup => 'my @init = 1..3; my ($x, @a) = 1..4;',
563 code => '($x, @a) = @init',
564 },
565 'expr::aassign::3m_la' => {
566 desc => 'three my vars assigned lexical array',
567 setup => 'my @init = 1..3;',
568 code => 'my ($x,$y,$z) = @init',
569 },
570 'expr::aassign::3l_la' => {
571 desc => 'three lexical vars assigned lexical array',
572 setup => 'my @init = 1..3; my ($x,$y,$z)',
573 code => '($x,$y,$z) = @init',
574 },
575 'expr::aassign::pa_la' => {
576 desc => 'package array assigned lexical array',
577 setup => 'my @init = 1..3;',
578 code => '@a = @init',
579 },
580 'expr::aassign::pax_la' => {
581 desc => 'non-empty package array assigned lexical array',
582 setup => 'my @init = 1..3; @a = @init',
583 code => '@a = @init',
584 },
585 'expr::aassign::3p_la' => {
586 desc => 'three package vars assigned lexical array',
587 setup => 'my @init = 1..3; ($x,$y,$z) = 1..3;',
588 code => '($x,$y,$z) = @init',
589 },
590
591 # (....) = @package
592
593 'expr::aassign::ma_pa' => {
594 desc => 'my array assigned package array',
595 setup => '@init = 1..3;',
596 code => 'my @a = @init',
597 },
598 'expr::aassign::lax_pa' => {
599 desc => 'non-empty lexical array assigned package array',
600 setup => '@init = 1..3; my @a = 1..3;',
601 code => '@a = @init',
602 },
603 'expr::aassign::llax_pa' => {
604 desc => 'non-empty lexical var and array assigned package array',
605 setup => '@init = 1..3; my ($x, @a) = 1..4;',
606 code => '($x, @a) = @init',
607 },
608 'expr::aassign::3m_pa' => {
609 desc => 'three my vars assigned package array',
610 setup => '@init = 1..3;',
611 code => 'my ($x,$y,$z) = @init',
612 },
613 'expr::aassign::3l_pa' => {
614 desc => 'three lexical vars assigned package array',
615 setup => '@init = 1..3; my ($x,$y,$z)',
616 code => '($x,$y,$z) = @init',
617 },
618 'expr::aassign::pa_pa' => {
619 desc => 'package array assigned package array',
620 setup => '@init = 1..3;',
621 code => '@a = @init',
622 },
623 'expr::aassign::pax_pa' => {
624 desc => 'non-empty package array assigned package array',
625 setup => '@init = 1..3; @a = @init',
626 code => '@a = @init',
627 },
628 'expr::aassign::3p_pa' => {
629 desc => 'three package vars assigned package array',
630 setup => '@init = 1..3; ($x,$y,$z) = 1..3;',
631 code => '($x,$y,$z) = @init',
632 },
633
634 # (....) = @_;
635
636 'expr::aassign::ma_defary' => {
637 desc => 'my array assigned @_',
638 setup => '@_ = 1..3;',
639 code => 'my @a = @_',
640 },
641 'expr::aassign::lax_defary' => {
642 desc => 'non-empty lexical array assigned @_',
643 setup => '@_ = 1..3; my @a = 1..3;',
644 code => '@a = @_',
645 },
646 'expr::aassign::llax_defary' => {
647 desc => 'non-empty lexical var and array assigned @_',
648 setup => '@_ = 1..3; my ($x, @a) = 1..4;',
649 code => '($x, @a) = @_',
650 },
651 'expr::aassign::3m_defary' => {
652 desc => 'three my vars assigned @_',
653 setup => '@_ = 1..3;',
654 code => 'my ($x,$y,$z) = @_',
655 },
656 'expr::aassign::3l_defary' => {
657 desc => 'three lexical vars assigned @_',
658 setup => '@_ = 1..3; my ($x,$y,$z)',
659 code => '($x,$y,$z) = @_',
660 },
661 'expr::aassign::pa_defary' => {
662 desc => 'package array assigned @_',
663 setup => '@_ = 1..3;',
664 code => '@a = @_',
665 },
666 'expr::aassign::pax_defary' => {
667 desc => 'non-empty package array assigned @_',
668 setup => '@_ = 1..3; @a = @_',
669 code => '@a = @_',
670 },
671 'expr::aassign::3p_defary' => {
672 desc => 'three package vars assigned @_',
673 setup => '@_ = 1..3; ($x,$y,$z) = 1..3;',
674 code => '($x,$y,$z) = @_',
675 },
676
af3b1cba
DM
677 # (....) = %lexical
678
679 'expr::aassign::ma_lh' => {
680 desc => 'my array assigned lexical hash',
681 setup => 'my %h = qw(aardvark 1 banana 2 cucumber 3)',
682 code => 'my @a = %h',
683 },
684
a5f48505
DM
685
686 # (....) = ($lex1,$lex2,$lex3);
687
688 'expr::aassign::ma_3l' => {
689 desc => 'my array assigned lexicals',
690 setup => 'my ($v1,$v2,$v3) = 1..3;',
691 code => 'my @a = ($v1,$v2,$v3)',
692 },
693 'expr::aassign::lax_3l' => {
694 desc => 'non-empty lexical array assigned lexicals',
695 setup => 'my ($v1,$v2,$v3) = 1..3; my @a = 1..3;',
696 code => '@a = ($v1,$v2,$v3)',
697 },
698 'expr::aassign::llax_3l' => {
699 desc => 'non-empty lexical var and array assigned lexicals',
700 setup => 'my ($v1,$v2,$v3) = 1..3; my ($x, @a) = 1..4;',
701 code => '($x, @a) = ($v1,$v2,$v3)',
702 },
703 'expr::aassign::3m_3l' => {
704 desc => 'three my vars assigned lexicals',
705 setup => 'my ($v1,$v2,$v3) = 1..3;',
706 code => 'my ($x,$y,$z) = ($v1,$v2,$v3)',
707 },
708 'expr::aassign::3l_3l' => {
709 desc => 'three lexical vars assigned lexicals',
710 setup => 'my ($v1,$v2,$v3) = 1..3; my ($x,$y,$z)',
711 code => '($x,$y,$z) = ($v1,$v2,$v3)',
712 },
713 'expr::aassign::pa_3l' => {
714 desc => 'package array assigned lexicals',
715 setup => 'my ($v1,$v2,$v3) = 1..3;',
716 code => '@a = ($v1,$v2,$v3)',
717 },
718 'expr::aassign::pax_3l' => {
719 desc => 'non-empty package array assigned lexicals',
720 setup => 'my ($v1,$v2,$v3) = 1..3; @a = @_',
721 code => '@a = ($v1,$v2,$v3)',
722 },
723 'expr::aassign::3p_3l' => {
724 desc => 'three package vars assigned lexicals',
725 setup => 'my ($v1,$v2,$v3) = 1..3; ($x,$y,$z) = 1..3;',
726 code => '($x,$y,$z) = ($v1,$v2,$v3)',
727 },
728
729
730 # (....) = ($pkg1,$pkg2,$pkg3);
731
732 'expr::aassign::ma_3p' => {
733 desc => 'my array assigned 3 package vars',
734 setup => '($v1,$v2,$v3) = 1..3;',
735 code => 'my @a = ($v1,$v2,$v3)',
736 },
737 'expr::aassign::lax_3p' => {
738 desc => 'non-empty lexical array assigned 3 package vars',
739 setup => '($v1,$v2,$v3) = 1..3; my @a = 1..3;',
740 code => '@a = ($v1,$v2,$v3)',
741 },
742 'expr::aassign::llax_3p' => {
743 desc => 'non-empty lexical var and array assigned 3 package vars',
744 setup => '($v1,$v2,$v3) = 1..3; my ($x, @a) = 1..4;',
745 code => '($x, @a) = ($v1,$v2,$v3)',
746 },
747 'expr::aassign::3m_3p' => {
748 desc => 'three my vars assigned 3 package vars',
749 setup => '($v1,$v2,$v3) = 1..3;',
750 code => 'my ($x,$y,$z) = ($v1,$v2,$v3)',
751 },
752 'expr::aassign::3l_3p' => {
753 desc => 'three lexical vars assigned 3 package vars',
754 setup => '($v1,$v2,$v3) = 1..3; my ($x,$y,$z)',
755 code => '($x,$y,$z) = ($v1,$v2,$v3)',
756 },
757 'expr::aassign::pa_3p' => {
758 desc => 'package array assigned 3 package vars',
759 setup => '($v1,$v2,$v3) = 1..3;',
760 code => '@a = ($v1,$v2,$v3)',
761 },
762 'expr::aassign::pax_3p' => {
763 desc => 'non-empty package array assigned 3 package vars',
764 setup => '($v1,$v2,$v3) = 1..3; @a = @_',
765 code => '@a = ($v1,$v2,$v3)',
766 },
767 'expr::aassign::3p_3p' => {
768 desc => 'three package vars assigned 3 package vars',
769 setup => '($v1,$v2,$v3) = 1..3; ($x,$y,$z) = 1..3;',
770 code => '($x,$y,$z) = ($v1,$v2,$v3)',
771 },
772
773
774 # (....) = (1,2,$shared);
775
776 'expr::aassign::llax_2c1s' => {
777 desc => 'non-empty lexical var and array assigned 2 consts and 1 shared var',
778 setup => 'my ($x, @a) = 1..4;',
779 code => '($x, @a) = (1,2,$x)',
780 },
781 'expr::aassign::3l_2c1s' => {
782 desc => 'three lexical vars assigned 2 consts and 1 shared var',
783 setup => 'my ($x,$y,$z) = 1..3;',
784 code => '($x,$y,$z) = (1,2,$x)',
785 },
786 'expr::aassign::3p_2c1s' => {
787 desc => 'three package vars assigned 2 consts and 1 shared var',
788 setup => '($x,$y,$z) = 1..3;',
789 code => '($x,$y,$z) = (1,2,$x)',
790 },
791
792
793 # ($a,$b) = ($b,$a);
794
795 'expr::aassign::2l_swap' => {
796 desc => 'swap two lexical vars',
797 setup => 'my ($a,$b) = (1,2)',
798 code => '($a,$b) = ($b,$a)',
799 },
800 'expr::aassign::2p_swap' => {
801 desc => 'swap two package vars',
802 setup => '($a,$b) = (1,2)',
803 code => '($a,$b) = ($b,$a)',
804 },
805 'expr::aassign::2laelem_swap' => {
806 desc => 'swap two lexical vars',
807 setup => 'my @a = (1,2)',
808 code => '($a[0],$a[1]) = ($a[1],$a[0])',
809 },
810
811 # misc list assign
812
813 'expr::aassign::5l_4l1s' => {
814 desc => 'long list of lexical vars, 1 shared',
815 setup => 'my ($a,$b,$c,$d,$e) = 1..5',
816 code => '($a,$b,$c,$d,$e) = ($a,$a,$c,$d,$e)',
817 },
818
819 'expr::aassign::5p_4p1s' => {
820 desc => 'long list of package vars, 1 shared',
821 setup => '($a,$b,$c,$d,$e) = 1..5',
822 code => '($a,$b,$c,$d,$e) = ($a,$a,$c,$d,$e)',
823 },
824 'expr::aassign::5l_defary' => {
825 desc => 'long list of lexical vars to assign @_ to',
826 setup => '@_ = 1..5',
827 code => 'my ($a,$b,$c,$d,$e) = @_',
828 },
829 'expr::aassign::5l1la_defary' => {
830 desc => 'long list of lexical vars plus long slurp to assign @_ to',
831 setup => '@_ = 1..20',
832 code => 'my ($a,$b,$c,$d,$e,@rest) = @_',
833 },
808ce557
DM
834 'expr::aassign::1l_2l' => {
835 desc => 'single lexical LHS',
836 setup => 'my $x = 1;',
837 code => '(undef,$x) = ($x,$x)',
838 },
839 'expr::aassign::2l_1l' => {
840 desc => 'single lexical RHS',
841 setup => 'my $x = 1;',
9ae0115f
DM
842 code => '($x,$x) = ($x)',
843 },
844 'expr::aassign::2l_1ul' => {
845 desc => 'undef and single lexical RHS',
846 setup => 'my $x = 1;',
808ce557
DM
847 code => '($x,$x) = (undef, $x)',
848 },
a5f48505 849
90303eef
DM
850 'expr::aassign::2list_lex' => {
851 desc => 'lexical ($x, $y) = (1, 2)',
852 setup => 'my ($x, $y)',
853 code => '($x, $y) = (1, 2)',
854 },
855
d24e3eb1
DM
856 'expr::aassign::lex_rv' => {
857 desc => 'lexical ($ref1, $ref2) = ($ref3, $ref4)',
858 setup => 'my ($r1, $r2, $r3, $r4);
859 ($r1, $r2) = (($r3, $r4) = ([], []));',
860 code => '($r1, $r2) = ($r3, $r4)',
861 },
862
863 'expr::aassign::lex_rv1' => {
864 desc => 'lexical ($ref1, $ref2) = ($ref3, $ref4) where ref1,2 are freed',
865 setup => 'my ($r1, $r2);',
866 code => '($r1, $r2) = ([], []);',
867 },
868
7b394f12
DM
869 'expr::aassign::boolean' => {
870 desc => '!(@a = @b)',
871 setup => 'my ($s,@a, @b); @b = (1,2)',
872 code => '!(@a = @b);',
873 },
874 'expr::aassign::scalar' => {
875 desc => '$scalar = (@a = @b)',
876 setup => 'my ($s, @a, @b); @b = (1,2)',
877 code => '$s = (@a = @b);',
878 },
879
8b0c3377
DM
880 # array assign of strings
881
882 'expr::aassign::la_3s' => {
883 desc => 'assign 3 strings to empty lexical array',
884 setup => 'my @a',
885 code => '@a = (); @a = qw(abc defg hijkl);',
886 },
887 'expr::aassign::la_3ts' => {
888 desc => 'assign 3 temp strings to empty lexical array',
889 setup => 'my @a',
890 code => '@a = (); @a = map $_, qw(abc defg hijkl);',
891 },
892 'expr::aassign::lan_3s' => {
893 desc => 'assign 3 strings to non-empty lexical array',
894 setup => 'my @a = qw(abc defg hijkl)',
895 code => '@a = qw(abc defg hijkl);',
896 },
897 'expr::aassign::lan_3ts' => {
898 desc => 'assign 3 temp strings to non-empty lexical array',
899 setup => 'my @a = qw(abc defg hijkl)',
900 code => '@a = map $_, qw(abc defg hijkl);',
901 },
902
903 # hash assign of strings
904
905 'expr::aassign::lh_2s' => {
906 desc => 'assign 2 strings to empty lexical hash',
907 setup => 'my %h',
908 code => '%h = (); %h = qw(k1 abc k2 defg);',
909 },
910 'expr::aassign::lh_2ts' => {
911 desc => 'assign 2 temp strings to empty lexical hash',
912 setup => 'my %h',
913 code => '%h = (); %h = map $_, qw(k1 abc k2 defg);',
914 },
915 'expr::aassign::lhn_2s' => {
916 desc => 'assign 2 strings to non-empty lexical hash',
917 setup => 'my %h = qw(k1 abc k2 defg);',
918 code => '%h = qw(k1 abc k2 defg);',
919 },
920 'expr::aassign::lhn_2ts' => {
921 desc => 'assign 2 temp strings to non-empty lexical hash',
922 setup => 'my %h = qw(k1 abc k2 defg);',
923 code => '%h = map $_, qw(k1 abc k2 defg);',
924 },
925
a5f48505 926
230ee21f
DM
927 'expr::arith::add_lex_ii' => {
928 desc => 'add two integers and assign to a lexical var',
929 setup => 'my ($x,$y,$z) = 1..3;',
930 code => '$z = $x + $y',
931 },
932 'expr::arith::add_pkg_ii' => {
933 desc => 'add two integers and assign to a package var',
934 setup => 'my ($x,$y) = 1..2; $z = 3;',
935 code => '$z = $x + $y',
936 },
937 'expr::arith::add_lex_nn' => {
938 desc => 'add two NVs and assign to a lexical var',
939 setup => 'my ($x,$y,$z) = (1.1, 2.2, 3.3);',
940 code => '$z = $x + $y',
941 },
942 'expr::arith::add_pkg_nn' => {
943 desc => 'add two NVs and assign to a package var',
944 setup => 'my ($x,$y); ($x,$y,$z) = (1.1, 2.2, 3.3);',
945 code => '$z = $x + $y',
946 },
947 'expr::arith::add_lex_ni' => {
948 desc => 'add an int and an NV and assign to a lexical var',
949 setup => 'my ($x,$y,$z) = (1, 2.2, 3.3);',
950 code => '$z = $x + $y',
951 },
952 'expr::arith::add_pkg_ni' => {
953 desc => 'add an int and an NV and assign to a package var',
954 setup => 'my ($x,$y); ($x,$y,$z) = (1, 2.2, 3.3);',
955 code => '$z = $x + $y',
956 },
80e5abf2
DM
957 'expr::arith::add_lex_ss' => {
958 desc => 'add two short strings and assign to a lexical var',
959 setup => 'my ($x,$y,$z) = ("1", "2", 1);',
960 code => '$z = $x + $y; $x = "1"; ',
961 },
962
963 'expr::arith::add_lex_ll' => {
964 desc => 'add two long strings and assign to a lexical var',
965 setup => 'my ($x,$y,$z) = ("12345", "23456", 1);',
966 code => '$z = $x + $y; $x = "12345"; ',
967 },
230ee21f
DM
968
969 'expr::arith::sub_lex_ii' => {
970 desc => 'subtract two integers and assign to a lexical var',
971 setup => 'my ($x,$y,$z) = 1..3;',
972 code => '$z = $x - $y',
973 },
974 'expr::arith::sub_pkg_ii' => {
975 desc => 'subtract two integers and assign to a package var',
976 setup => 'my ($x,$y) = 1..2; $z = 3;',
977 code => '$z = $x - $y',
978 },
979 'expr::arith::sub_lex_nn' => {
980 desc => 'subtract two NVs and assign to a lexical var',
981 setup => 'my ($x,$y,$z) = (1.1, 2.2, 3.3);',
982 code => '$z = $x - $y',
983 },
984 'expr::arith::sub_pkg_nn' => {
985 desc => 'subtract two NVs and assign to a package var',
986 setup => 'my ($x,$y); ($x,$y,$z) = (1.1, 2.2, 3.3);',
987 code => '$z = $x - $y',
988 },
989 'expr::arith::sub_lex_ni' => {
990 desc => 'subtract an int and an NV and assign to a lexical var',
991 setup => 'my ($x,$y,$z) = (1, 2.2, 3.3);',
992 code => '$z = $x - $y',
993 },
994 'expr::arith::sub_pkg_ni' => {
995 desc => 'subtract an int and an NV and assign to a package var',
996 setup => 'my ($x,$y); ($x,$y,$z) = (1, 2.2, 3.3);',
997 code => '$z = $x - $y',
998 },
999
1000 'expr::arith::mult_lex_ii' => {
1001 desc => 'multiply two integers and assign to a lexical var',
1002 setup => 'my ($x,$y,$z) = 1..3;',
1003 code => '$z = $x * $y',
1004 },
1005 'expr::arith::mult_pkg_ii' => {
1006 desc => 'multiply two integers and assign to a package var',
1007 setup => 'my ($x,$y) = 1..2; $z = 3;',
1008 code => '$z = $x * $y',
1009 },
1010 'expr::arith::mult_lex_nn' => {
1011 desc => 'multiply two NVs and assign to a lexical var',
1012 setup => 'my ($x,$y,$z) = (1.1, 2.2, 3.3);',
1013 code => '$z = $x * $y',
1014 },
1015 'expr::arith::mult_pkg_nn' => {
1016 desc => 'multiply two NVs and assign to a package var',
1017 setup => 'my ($x,$y); ($x,$y,$z) = (1.1, 2.2, 3.3);',
1018 code => '$z = $x * $y',
1019 },
1020 'expr::arith::mult_lex_ni' => {
1021 desc => 'multiply an int and an NV and assign to a lexical var',
1022 setup => 'my ($x,$y,$z) = (1, 2.2, 3.3);',
1023 code => '$z = $x * $y',
1024 },
1025 'expr::arith::mult_pkg_ni' => {
1026 desc => 'multiply an int and an NV and assign to a package var',
1027 setup => 'my ($x,$y); ($x,$y,$z) = (1, 2.2, 3.3);',
1028 code => '$z = $x * $y',
1029 },
1030
775f2c07
DM
1031 # use '!' to test SvTRUE on various classes of value
1032
1033 'expr::arith::not_PL_undef' => {
1034 desc => '!undef (using PL_sv_undef)',
1035 setup => 'my $x',
1036 code => '$x = !undef',
1037 },
1038 'expr::arith::not_PL_no' => {
1039 desc => '!($x == $y) (using PL_sv_no)',
1040 setup => 'my ($x, $y) = (1,2); my $z;',
1041 code => '$z = !($x == $y)',
1042 },
1043 'expr::arith::not_PL_zero' => {
1044 desc => '!%h (using PL_sv_zero)',
1045 setup => 'my ($x, %h)',
1046 code => '$x = !%h',
1047 },
1048 'expr::arith::not_PL_yes' => {
1049 desc => '!($x == $y) (using PL_sv_yes)',
1050 setup => 'my ($x, $y) = (1,1); my $z;',
1051 code => '$z = !($x == $y)',
1052 },
1053 'expr::arith::not_undef' => {
1054 desc => '!$y where $y is undef',
1055 setup => 'my ($x, $y)',
1056 code => '$x = !$y',
1057 },
1058 'expr::arith::not_0' => {
1059 desc => '!$x where $x is 0',
1060 setup => 'my ($x, $y) = (0, 0)',
1061 code => '$y = !$x',
1062 },
1063 'expr::arith::not_1' => {
1064 desc => '!$x where $x is 1',
1065 setup => 'my ($x, $y) = (1, 0)',
1066 code => '$y = !$x',
1067 },
1068 'expr::arith::not_string' => {
1069 desc => '!$x where $x is "foo"',
1070 setup => 'my ($x, $y) = ("foo", 0)',
1071 code => '$y = !$x',
1072 },
1073 'expr::arith::not_ref' => {
1074 desc => '!$x where $s is an array ref',
1075 setup => 'my ($x, $y) = ([], 0)',
1076 code => '$y = !$x',
1077 },
1078
4c2c3128 1079 'expr::arith::preinc' => {
4c2c3128
DM
1080 setup => 'my $x = 1;',
1081 code => '++$x',
1082 },
1083 'expr::arith::predec' => {
4c2c3128
DM
1084 setup => 'my $x = 1;',
1085 code => '--$x',
1086 },
1087 'expr::arith::postinc' => {
1088 desc => '$x++',
1089 setup => 'my $x = 1; my $y',
1090 code => '$y = $x++', # scalar context so not optimised to ++$x
1091 },
1092 'expr::arith::postdec' => {
1093 desc => '$x--',
1094 setup => 'my $x = 1; my $y',
1095 code => '$y = $x--', # scalar context so not optimised to --$x
b52de964
DM
1096 },
1097
84721d61 1098
5012eebe 1099
90303eef
DM
1100 # scalar assign, OP_SASSIGN
1101
1102
1103 'expr::sassign::scalar_lex_int' => {
1104 desc => 'lexical $x = 1',
1105 setup => 'my $x',
1106 code => '$x = 1',
1107 },
1108 'expr::sassign::scalar_lex_str' => {
1109 desc => 'lexical $x = "abc"',
1110 setup => 'my $x',
1111 code => '$x = "abc"',
1112 },
1113 'expr::sassign::scalar_lex_strint' => {
1114 desc => 'lexical $x = 1 where $x was previously a string',
1115 setup => 'my $x = "abc"',
1116 code => '$x = 1',
1117 },
1118 'expr::sassign::scalar_lex_intstr' => {
1119 desc => 'lexical $x = "abc" where $x was previously an int',
1120 setup => 'my $x = 1;',
1121 code => '$x = "abc"',
1122 },
a0833292
DM
1123 'expr::sassign::lex_rv' => {
1124 desc => 'lexical $ref1 = $ref2;',
1125 setup => 'my $r1 = []; my $r = $r1;',
1126 code => '$r = $r1;',
1127 },
1128 'expr::sassign::lex_rv1' => {
1129 desc => 'lexical $ref1 = $ref2; where $$ref1 gets freed',
1130 setup => 'my $r1 = []; my $r',
1131 code => '$r = []; $r = $r1;',
1132 },
90303eef
DM
1133
1134
7b394f12
DM
1135 'func::grep::bool0' => {
1136 desc => 'grep returning 0 items in boolean context',
1137 setup => 'my @a;',
1138 code => '!grep $_, @a;',
1139 },
1140 'func::grep::bool1' => {
1141 desc => 'grep returning 1 item in boolean context',
1142 setup => 'my @a =(1);',
1143 code => '!grep $_, @a;',
1144 },
1145 'func::grep::scalar0' => {
1146 desc => 'returning 0 items in scalar context',
1147 setup => 'my $g; my @a;',
1148 code => '$g = grep $_, @a;',
1149 },
1150 'func::grep::scalar1' => {
1151 desc => 'returning 1 item in scalar context',
1152 setup => 'my $g; my @a =(1);',
1153 code => '$g = grep $_, @a;',
1154 },
90303eef 1155
7e8d786b
DM
1156 # (index() == -1) and variants optimise away the op_const and op_eq
1157 # and any assignment to a lexical var
1158 'func::index::bool' => {
1159 desc => '(index() == -1) for match',
1160 setup => 'my $x = "aaaab"',
1161 code => 'index($x, "b") == -1',
1162 },
1163 'func::index::bool_fail' => {
1164 desc => '(index() == -1) for no match',
1165 setup => 'my $x = "aaaab"',
1166 code => 'index($x, "c") == -1',
1167 },
1168 'func::index::lex_bool' => {
1169 desc => '$lex = (index() == -1) for match',
1170 setup => 'my $r; my $x = "aaaab"',
1171 code => '$r = index($x, "b") == -1',
1172 },
1173 'func::index::lex_bool_fail' => {
1174 desc => '$lex = (index() == -1) for no match',
1175 setup => 'my $r; my $x = "aaaab"',
1176 code => '$r = index($x, "c") == -1',
1177 },
1178
d670485e
DM
1179 # using a const string as second arg to index triggers using FBM.
1180 # the FBM matcher special-cases 1,2-byte strings.
1181 #
1182 'func::index::short_const1' => {
1183 desc => 'index of a short string against a 1 char const substr',
1184 setup => 'my $x = "aaaab"',
1185 code => 'index $x, "b"',
1186 },
1187 'func::index::long_const1' => {
1188 desc => 'index of a long string against a 1 char const substr',
1189 setup => 'my $x = "a" x 1000 . "b"',
1190 code => 'index $x, "b"',
1191 },
1192 'func::index::short_const2aabc_bc' => {
1193 desc => 'index of a short string against a 2 char const substr',
1194 setup => 'my $x = "aaaabc"',
1195 code => 'index $x, "bc"',
1196 },
1197 'func::index::long_const2aabc_bc' => {
1198 desc => 'index of a long string against a 2 char const substr',
1199 setup => 'my $x = "a" x 1000 . "bc"',
1200 code => 'index $x, "bc"',
1201 },
1202 'func::index::long_const2aa_ab' => {
1203 desc => 'index of a long string aaa.. against const substr "ab"',
1204 setup => 'my $x = "a" x 1000',
1205 code => 'index $x, "ab"',
1206 },
1207 'func::index::long_const2bb_ab' => {
1208 desc => 'index of a long string bbb.. against const substr "ab"',
1209 setup => 'my $x = "b" x 1000',
1210 code => 'index $x, "ab"',
1211 },
1212 'func::index::long_const2aa_bb' => {
1213 desc => 'index of a long string aaa.. against const substr "bb"',
1214 setup => 'my $x = "a" x 1000',
1215 code => 'index $x, "bb"',
1216 },
1217 # this one is designed to be pathological
1218 'func::index::long_const2ab_aa' => {
1219 desc => 'index of a long string abab.. against const substr "aa"',
1220 setup => 'my $x = "ab" x 500',
1221 code => 'index $x, "aa"',
1222 },
1223 # near misses with gaps, 1st letter
1224 'func::index::long_const2aaxx_xy' => {
1225 desc => 'index of a long string with "xx"s against const substr "xy"',
1226 setup => 'my $x = "aaaaaaaaxx" x 100',
1227 code => 'index $x, "xy"',
1228 },
1229 # near misses with gaps, 2nd letter
1230 'func::index::long_const2aayy_xy' => {
1231 desc => 'index of a long string with "yy"s against const substr "xy"',
1232 setup => 'my $x = "aaaaaaaayy" x 100',
1233 code => 'index $x, "xy"',
1234 },
1235 # near misses with gaps, duplicate letter
1236 'func::index::long_const2aaxy_xx' => {
1237 desc => 'index of a long string with "xy"s against const substr "xx"',
1238 setup => 'my $x = "aaaaaaaaxy" x 100',
1239 code => 'index $x, "xx"',
1240 },
1241 # alternating near misses with gaps
1242 'func::index::long_const2aaxxaayy_xy' => {
1243 desc => 'index of a long string with "xx/yy"s against const substr "xy"',
1244 setup => 'my $x = "aaaaaaaaxxbbbbbbbbyy" x 50',
1245 code => 'index $x, "xy"',
1246 },
1247 'func::index::short_const3aabcd_bcd' => {
1248 desc => 'index of a short string against a 3 char const substr',
1249 setup => 'my $x = "aaaabcd"',
1250 code => 'index $x, "bcd"',
1251 },
1252 'func::index::long_const3aabcd_bcd' => {
1253 desc => 'index of a long string against a 3 char const substr',
1254 setup => 'my $x = "a" x 1000 . "bcd"',
1255 code => 'index $x, "bcd"',
1256 },
1257 'func::index::long_const3ab_abc' => {
1258 desc => 'index of a long string of "ab"s against a 3 char const substr "abc"',
1259 setup => 'my $x = "ab" x 500',
1260 code => 'index $x, "abc"',
1261 },
1262 'func::index::long_const3bc_abc' => {
1263 desc => 'index of a long string of "bc"s against a 3 char const substr "abc"',
1264 setup => 'my $x = "bc" x 500',
1265 code => 'index $x, "abc"',
1266 },
1267 'func::index::utf8_position_1' => {
1268 desc => 'index of a utf8 string, matching at position 1',
1269 setup => 'my $x = "abc". chr(0x100); chop $x',
1270 code => 'index $x, "b"',
1271 },
1272
8dc9003f 1273
6f2dc9a6
DM
1274 'func::keys::lex::void_cxt_empty' => {
1275 desc => ' keys() on an empty lexical hash in void context',
1276 setup => 'my %h = ()',
1277 code => 'keys %h',
1278 },
1279 'func::keys::lex::void_cxt' => {
1280 desc => ' keys() on a non-empty lexical hash in void context',
1281 setup => 'my %h = qw(aardvark 1 banana 2 cucumber 3)',
1282 code => 'keys %h',
1283 },
cd5acddb
DM
1284 'func::keys::lex::bool_cxt_empty' => {
1285 desc => ' keys() on an empty lexical hash in bool context',
1286 setup => 'my %h = ()',
1287 code => '!keys %h',
1288 },
1289 'func::keys::lex::bool_cxt' => {
1290 desc => ' keys() on a non-empty lexical hash in bool context',
1291 setup => 'my %h = qw(aardvark 1 banana 2 cucumber 3)',
1292 code => '!keys %h',
1293 },
6f2dc9a6
DM
1294 'func::keys::lex::scalar_cxt_empty' => {
1295 desc => ' keys() on an empty lexical hash in scalar context',
8dc9003f
DM
1296 setup => 'my $k; my %h = ()',
1297 code => '$k = keys %h',
1298 },
6f2dc9a6
DM
1299 'func::keys::lex::scalar_cxt' => {
1300 desc => ' keys() on a non-empty lexical hash in scalar context',
8dc9003f
DM
1301 setup => 'my $k; my %h = qw(aardvark 1 banana 2 cucumber 3)',
1302 code => '$k = keys %h',
1303 },
6f2dc9a6
DM
1304 'func::keys::lex::list_cxt_empty' => {
1305 desc => ' keys() on an empty lexical hash in list context',
8dc9003f
DM
1306 setup => 'my %h = ()',
1307 code => '() = keys %h',
1308 },
6f2dc9a6
DM
1309 'func::keys::lex::list_cxt' => {
1310 desc => ' keys() on a non-empty lexical hash in list context',
8dc9003f
DM
1311 setup => 'my %h = qw(aardvark 1 banana 2 cucumber 3)',
1312 code => '() = keys %h',
1313 },
1314
6f2dc9a6
DM
1315 'func::keys::pkg::void_cxt_empty' => {
1316 desc => ' keys() on an empty package hash in void context',
1317 setup => 'our %h = ()',
1318 code => 'keys %h',
1319 },
1320 'func::keys::pkg::void_cxt' => {
1321 desc => ' keys() on a non-empty package hash in void context',
1322 setup => 'our %h = qw(aardvark 1 banana 2 cucumber 3)',
1323 code => 'keys %h',
1324 },
cd5acddb
DM
1325 'func::keys::pkg::bool_cxt_empty' => {
1326 desc => ' keys() on an empty package hash in bool context',
1327 setup => 'our %h = ()',
1328 code => '!keys %h',
1329 },
1330 'func::keys::pkg::bool_cxt' => {
1331 desc => ' keys() on a non-empty package hash in bool context',
1332 setup => 'our %h = qw(aardvark 1 banana 2 cucumber 3)',
1333 code => '!keys %h',
1334 },
6f2dc9a6
DM
1335 'func::keys::pkg::scalar_cxt_empty' => {
1336 desc => ' keys() on an empty package hash in scalar context',
1337 setup => 'my $k; our %h = ()',
1338 code => '$k = keys %h',
1339 },
1340 'func::keys::pkg::scalar_cxt' => {
1341 desc => ' keys() on a non-empty package hash in scalar context',
1342 setup => 'my $k; our %h = qw(aardvark 1 banana 2 cucumber 3)',
1343 code => '$k = keys %h',
1344 },
1345 'func::keys::pkg::list_cxt_empty' => {
1346 desc => ' keys() on an empty package hash in list context',
1347 setup => 'our %h = ()',
1348 code => '() = keys %h',
1349 },
1350 'func::keys::pkg::list_cxt' => {
1351 desc => ' keys() on a non-empty package hash in list context',
1352 setup => 'our %h = qw(aardvark 1 banana 2 cucumber 3)',
1353 code => '() = keys %h',
1354 },
1355
8dc9003f 1356
7b394f12
DM
1357 'func::length::bool0' => {
1358 desc => 'length==0 in boolean context',
1359 setup => 'my $s = "";',
1360 code => '!length($s);',
1361 },
1362 'func::length::bool10' => {
1363 desc => 'length==10 in boolean context',
1364 setup => 'my $s = "abcdefghijk";',
1365 code => '!length($s);',
1366 },
1367 'func::length::scalar10' => {
1368 desc => 'length==10 in scalar context',
1369 setup => 'my $p; my $s = "abcdefghijk";',
1370 code => '$p = length($s);',
1371 },
1372 'func::length::bool0_utf8' => {
1373 desc => 'utf8 string length==0 in boolean context',
1374 setup => 'my $s = "\x{100}"; chop $s;',
1375 code => '!length($s);',
1376 },
1377 'func::length::bool10_utf8' => {
1378 desc => 'utf8 string length==10 in boolean context',
1379 setup => 'my $s = "abcdefghij\x{100}";',
1380 code => '!length($s);',
1381 },
1382 'func::length::scalar10_utf8' => {
1383 desc => 'utf8 string length==10 in scalar context',
1384 setup => 'my $p; my $s = "abcdefghij\x{100}";',
1385 code => '$p = length($s);',
1386 },
d670485e 1387
7b394f12
DM
1388 'func::pos::bool0' => {
1389 desc => 'pos==0 in boolean context',
1390 setup => 'my $s = "abc"; pos($s) = 0',
1391 code => '!pos($s);',
1392 },
1393 'func::pos::bool10' => {
1394 desc => 'pos==10 in boolean context',
1395 setup => 'my $s = "abcdefghijk"; pos($s) = 10',
1396 code => '!pos($s);',
1397 },
1398 'func::pos::scalar10' => {
1399 desc => 'pos==10 in scalar context',
1400 setup => 'my $p; my $s = "abcdefghijk"; pos($s) = 10',
1401 code => '$p = pos($s);',
1402 },
d670485e 1403
ba75e9a4
DM
1404 'func::ref::notaref_bool' => {
1405 desc => 'ref($notaref) in boolean context',
1406 setup => 'my $r = "boo"',
1407 code => '!ref $r',
1408 },
1409 'func::ref::ref_bool' => {
1410 desc => 'ref($ref) in boolean context',
1411 setup => 'my $r = []',
1412 code => '!ref $r',
1413 },
1414 'func::ref::blessedref_bool' => {
1415 desc => 'ref($blessed_ref) in boolean context',
1416 setup => 'my $r = bless []',
1417 code => '!ref $r',
1418 },
1419
1420 'func::ref::notaref' => {
1421 desc => 'ref($notaref) in scalar context',
1422 setup => 'my $x; my $r = "boo"',
1423 code => '$x = ref $r',
1424 },
1425 'func::ref::ref' => {
1426 desc => 'ref($ref) in scalar context',
1427 setup => 'my $x; my $r = []',
1428 code => '$x = ref $r',
1429 },
1430 'func::ref::blessedref' => {
1431 desc => 'ref($blessed_ref) in scalar context',
1432 setup => 'my $x; my $r = bless []',
1433 code => '$x = ref $r',
1434 },
1435
1436
1437
84721d61
DM
1438 'func::sort::num' => {
1439 desc => 'plain numeric sort',
1440 setup => 'my (@a, @b); @a = reverse 1..10;',
1441 code => '@b = sort { $a <=> $b } @a',
1442 },
1443 'func::sort::num_block' => {
1444 desc => 'codeblock numeric sort',
1445 setup => 'my (@a, @b); @a = reverse 1..10;',
1446 code => '@b = sort { $a + 1 <=> $b + 1 } @a',
1447 },
1448 'func::sort::num_fn' => {
1449 desc => 'function numeric sort',
1450 setup => 'sub f { $a + 1 <=> $b + 1 } my (@a, @b); @a = reverse 1..10;',
1451 code => '@b = sort f @a',
1452 },
1453 'func::sort::str' => {
1454 desc => 'plain string sort',
1455 setup => 'my (@a, @b); @a = reverse "a".."j";',
1456 code => '@b = sort { $a cmp $b } @a',
1457 },
1458 'func::sort::str_block' => {
1459 desc => 'codeblock string sort',
1460 setup => 'my (@a, @b); @a = reverse "a".."j";',
1461 code => '@b = sort { ($a . "") cmp ($b . "") } @a',
1462 },
1463 'func::sort::str_fn' => {
1464 desc => 'function string sort',
1465 setup => 'sub f { ($a . "") cmp ($b . "") } my (@a, @b); @a = reverse "a".."j";',
1466 code => '@b = sort f @a',
1467 },
1468
1469 'func::sort::num_inplace' => {
1470 desc => 'plain numeric sort in-place',
1471 setup => 'my @a = reverse 1..10;',
1472 code => '@a = sort { $a <=> $b } @a',
1473 },
1474 'func::sort::num_block_inplace' => {
1475 desc => 'codeblock numeric sort in-place',
1476 setup => 'my @a = reverse 1..10;',
1477 code => '@a = sort { $a + 1 <=> $b + 1 } @a',
1478 },
1479 'func::sort::num_fn_inplace' => {
1480 desc => 'function numeric sort in-place',
1481 setup => 'sub f { $a + 1 <=> $b + 1 } my @a = reverse 1..10;',
1482 code => '@a = sort f @a',
1483 },
1484 'func::sort::str_inplace' => {
1485 desc => 'plain string sort in-place',
1486 setup => 'my @a = reverse "a".."j";',
1487 code => '@a = sort { $a cmp $b } @a',
1488 },
1489 'func::sort::str_block_inplace' => {
1490 desc => 'codeblock string sort in-place',
1491 setup => 'my @a = reverse "a".."j";',
1492 code => '@a = sort { ($a . "") cmp ($b . "") } @a',
1493 },
1494 'func::sort::str_fn_inplace' => {
1495 desc => 'function string sort in-place',
1496 setup => 'sub f { ($a . "") cmp ($b . "") } my @a = reverse "a".."j";',
1497 code => '@a = sort f @a',
1498 },
1499
1500
5012eebe
DM
1501 'func::split::vars' => {
1502 desc => 'split into two lexical vars',
1503 setup => 'my $s = "abc:def";',
1504 code => 'my ($x, $y) = split /:/, $s, 2;',
1505 },
1506
1507 'func::split::array' => {
1508 desc => 'split into a lexical array',
1509 setup => 'my @a; my $s = "abc:def";',
1510 code => '@a = split /:/, $s, 2;',
1511 },
5012eebe
DM
1512 'func::split::myarray' => {
1513 desc => 'split into a lexical array declared in the assign',
1514 setup => 'my $s = "abc:def";',
1515 code => 'my @a = split /:/, $s, 2;',
1516 },
692044df
DM
1517 'func::split::arrayexpr' => {
1518 desc => 'split into an @{$expr} ',
1519 setup => 'my $s = "abc:def"; my $r = []',
1520 code => '@$r = split /:/, $s, 2;',
1521 },
47a8f19b
DM
1522 'func::split::arraylist' => {
1523 desc => 'split into an array with extra arg',
1524 setup => 'my @a; my $s = "abc:def";',
1525 code => '@a = (split(/:/, $s, 2), 1);',
1526 },
5012eebe
DM
1527
1528
e85981ca
DM
1529 'func::sprintf::d' => {
1530 desc => '%d',
1531 setup => 'my $s; my $a1 = 1234;',
1532 code => '$s = sprintf "%d", $a1',
1533 },
1534 'func::sprintf::d8' => {
1535 desc => '%8d',
1536 setup => 'my $s; my $a1 = 1234;',
1537 code => '$s = sprintf "%8d", $a1',
1538 },
1539 'func::sprintf::foo_d8' => {
1540 desc => 'foo=%8d',
1541 setup => 'my $s; my $a1 = 1234;',
1542 code => '$s = sprintf "foo=%8d", $a1',
1543 },
1544
1545 'func::sprintf::f0' => {
1546 # "%.0f" is very special-cased
1547 desc => 'sprintf "%.0f"',
1548 setup => 'my $s; my $a1 = 123.456;',
1549 code => '$s = sprintf "%.0f", $a1',
1550 },
1551 'func::sprintf::foo_f0' => {
1552 # "...%.0f..." is special-cased
1553 desc => 'sprintf "foo=%.0f"',
1554 setup => 'my $s; my $a1 = 123.456;',
1555 code => '$s = sprintf "foo=%.0f\n", $a1',
1556 },
1557 'func::sprintf::foo_f93' => {
1558 desc => 'foo=%9.3f',
1559 setup => 'my $s; my $a1 = 123.456;',
1560 code => '$s = sprintf "foo=%9.3f\n", $a1',
1561 },
1562
1563 'func::sprintf::g9' => {
1564 # "...%.NNNg..." is special-cased
1565 desc => '%.9g',
1566 setup => 'my $s; my $a1 = 123.456;',
1567 code => '$s = sprintf "%.9g", $a1',
1568 },
1569 'func::sprintf::foo_g9' => {
1570 # "...%.NNNg..." is special-cased
1571 desc => 'foo=%.9g',
1572 setup => 'my $s; my $a1 = 123.456;',
1573 code => '$s = sprintf "foo=%.9g\n", $a1',
1574 },
1575 'func::sprintf::foo_g93' => {
1576 desc => 'foo=%9.3g',
1577 setup => 'my $s; my $a1 = 123.456;',
1578 code => '$s = sprintf "foo=%9.3g\n", $a1',
1579 },
1580
1581 'func::sprintf::s' => {
1582 desc => '%s',
1583 setup => 'my $s; my $a1 = "abcd";',
1584 code => '$s = sprintf "%s", $a1',
1585 },
1586 'func::sprintf::foo_s' => {
1587 desc => 'foo=%s',
1588 setup => 'my $s; my $a1 = "abcd";',
1589 code => '$s = sprintf "foo=%s", $a1',
1590 },
1591 'func::sprintf::mixed_utf8_s' => {
1592 desc => 'foo=%s bar=%s baz=%s',
1593 setup => 'my $s;',
1594 code => '$s = sprintf "foo=%s", "ab\x{100}cd", "efg", "h\x{101}ij"',
1595 },
1596
7b394f12
DM
1597 'func::subst::bool' => {
1598 desc => 's/// in boolean context',
1599 setup => '',
1600 code => '$_ = "aaa"; !s/./x/g;'
1601 },
1602
e85981ca 1603
8dc9003f
DM
1604 'func::values::scalar_cxt_empty' => {
1605 desc => ' values() on an empty hash in scalar context',
1606 setup => 'my $k; my %h = ()',
1607 code => '$k = values %h',
1608 },
1609 'func::values::scalar_cxt' => {
1610 desc => ' values() on a non-empty hash in scalar context',
1611 setup => 'my $k; my %h = qw(aardvark 1 banana 2 cucumber 3)',
1612 code => '$k = values %h',
1613 },
1614 'func::values::list_cxt_empty' => {
1615 desc => ' values() on an empty hash in list context',
1616 setup => 'my %h = ()',
1617 code => '() = values %h',
1618 },
1619 'func::values::list_cxt' => {
1620 desc => ' values() on a non-empty hash in list context',
1621 setup => 'my %h = qw(aardvark 1 banana 2 cucumber 3)',
1622 code => '() = values %h',
1623 },
1624
1625
1626
aedeb7c2
DM
1627 'loop::block' => {
1628 desc => 'empty basic loop',
84721d61 1629 setup => '',
aedeb7c2
DM
1630 code => '{1;}',
1631 },
1632
1633 'loop::do' => {
1634 desc => 'basic do block',
1635 setup => 'my $x; my $y = 2;',
1636 code => '$x = do {1; $y}', # the ';' stops the do being optimised
1637 },
1638
1639 'loop::for::my_range1' => {
1640 desc => 'empty for loop with my var and 1 integer range',
1641 setup => '',
1642 code => 'for my $x (1..1) {}',
1643 },
1644 'loop::for::lex_range1' => {
1645 desc => 'empty for loop with lexical var and 1 integer range',
1646 setup => 'my $x;',
1647 code => 'for $x (1..1) {}',
1648 },
1649 'loop::for::pkg_range1' => {
1650 desc => 'empty for loop with package var and 1 integer range',
1651 setup => '$x = 1;',
1652 code => 'for $x (1..1) {}',
1653 },
1654 'loop::for::defsv_range1' => {
1655 desc => 'empty for loop with $_ and integer 1 range',
1656 setup => ';',
1657 code => 'for (1..1) {}',
1658 },
1659 'loop::for::my_range4' => {
1660 desc => 'empty for loop with my var and 4 integer range',
1661 setup => '',
1662 code => 'for my $x (1..4) {}',
1663 },
1664 'loop::for::lex_range4' => {
1665 desc => 'empty for loop with lexical var and 4 integer range',
1666 setup => 'my $x;',
1667 code => 'for $x (1..4) {}',
1668 },
1669 'loop::for::pkg_range4' => {
1670 desc => 'empty for loop with package var and 4 integer range',
1671 setup => '$x = 1;',
1672 code => 'for $x (1..4) {}',
1673 },
1674 'loop::for::defsv_range4' => {
1675 desc => 'empty for loop with $_ and integer 4 range',
1676 setup => ';',
1677 code => 'for (1..4) {}',
1678 },
4c2c3128 1679
aedeb7c2
DM
1680 'loop::for::my_list1' => {
1681 desc => 'empty for loop with my var and 1 integer list',
b52de964 1682 setup => '',
aedeb7c2
DM
1683 code => 'for my $x (1) {}',
1684 },
1685 'loop::for::lex_list1' => {
1686 desc => 'empty for loop with lexical var and 1 integer list',
1687 setup => 'my $x;',
1688 code => 'for $x (1) {}',
1689 },
1690 'loop::for::pkg_list1' => {
1691 desc => 'empty for loop with package var and 1 integer list',
1692 setup => '$x = 1;',
1693 code => 'for $x (1) {}',
1694 },
1695 'loop::for::defsv_list1' => {
1696 desc => 'empty for loop with $_ and integer 1 list',
1697 setup => ';',
1698 code => 'for (1) {}',
1699 },
1700 'loop::for::my_list4' => {
1701 desc => 'empty for loop with my var and 4 integer list',
1702 setup => '',
1703 code => 'for my $x (1,2,3,4) {}',
1704 },
1705 'loop::for::lex_list4' => {
1706 desc => 'empty for loop with lexical var and 4 integer list',
1707 setup => 'my $x;',
1708 code => 'for $x (1,2,3,4) {}',
1709 },
1710 'loop::for::pkg_list4' => {
1711 desc => 'empty for loop with package var and 4 integer list',
1712 setup => '$x = 1;',
1713 code => 'for $x (1,2,3,4) {}',
1714 },
1715 'loop::for::defsv_list4' => {
1716 desc => 'empty for loop with $_ and integer 4 list',
1717 setup => '',
1718 code => 'for (1,2,3,4) {}',
1719 },
1720
0724084c
DM
1721 'loop::for::my_array1' => {
1722 desc => 'empty for loop with my var and 1 integer array',
1723 setup => 'my @a = (1);',
1724 code => 'for my $x (@a) {}',
1725 },
1726 'loop::for::lex_array1' => {
1727 desc => 'empty for loop with lexical var and 1 integer array',
1728 setup => 'my $x; my @a = (1);',
1729 code => 'for $x (@a) {}',
1730 },
1731 'loop::for::pkg_array1' => {
1732 desc => 'empty for loop with package var and 1 integer array',
1733 setup => '$x = 1; my @a = (1);',
1734 code => 'for $x (@a) {}',
1735 },
1736 'loop::for::defsv_array1' => {
1737 desc => 'empty for loop with $_ and integer 1 array',
1738 setup => 'my @a = (@a);',
1739 code => 'for (1) {}',
1740 },
1741 'loop::for::my_array4' => {
1742 desc => 'empty for loop with my var and 4 integer array',
1743 setup => 'my @a = (1..4);',
1744 code => 'for my $x (@a) {}',
1745 },
1746 'loop::for::lex_array4' => {
1747 desc => 'empty for loop with lexical var and 4 integer array',
1748 setup => 'my $x; my @a = (1..4);',
1749 code => 'for $x (@a) {}',
1750 },
1751 'loop::for::pkg_array4' => {
1752 desc => 'empty for loop with package var and 4 integer array',
1753 setup => '$x = 1; my @a = (1..4);',
1754 code => 'for $x (@a) {}',
1755 },
1756 'loop::for::defsv_array4' => {
1757 desc => 'empty for loop with $_ and integer 4 array',
1758 setup => 'my @a = (1..4);',
1759 code => 'for (@a) {}',
1760 },
1761
cd97dc8d
DM
1762 'loop::for::next4' => {
1763 desc => 'for loop containing only next with my var and integer 4 array',
1764 setup => 'my @a = (1..4);',
1765 code => 'for my $x (@a) {next}',
1766 },
1767
56e049ca
DM
1768 'loop::grep::expr_3int' => {
1769 desc => 'grep $_ > 0, 1,2,3',
1770 setup => 'my @a',
1771 code => '@a = grep $_ > 0, 1,2,3',
1772 },
1773
1774 'loop::grep::block_3int' => {
1775 desc => 'grep { 1; $_ > 0} 1,2,3',
1776 setup => 'my @a',
1777 code => '@a = grep { 1; $_ > 0} 1,2,3',
1778 },
1779
1780 'loop::map::expr_3int' => {
1781 desc => 'map $_+1, 1,2,3',
1782 setup => 'my @a',
1783 code => '@a = map $_+1, 1,2,3',
1784 },
1785
1786 'loop::map::block_3int' => {
1787 desc => 'map { 1; $_+1} 1,2,3',
1788 setup => 'my @a',
1789 code => '@a = map { 1; $_+1} 1,2,3',
1790 },
1791
aedeb7c2
DM
1792 'loop::while::i1' => {
1793 desc => 'empty while loop 1 iteration',
1794 setup => 'my $i = 0;',
1795 code => 'while (++$i % 2) {}',
1796 },
1797 'loop::while::i4' => {
1798 desc => 'empty while loop 4 iterations',
1799 setup => 'my $i = 0;',
1800 code => 'while (++$i % 4) {}',
4c2c3128 1801 },
1451f692
DM
1802
1803
1804 'regex::anyof_plus::anchored' => {
1451f692
DM
1805 setup => '$_ = "a" x 100;',
1806 code => '/^[acgt]+/',
1807 },
1808 'regex::anyof_plus::floating' => {
1809 desc => '/[acgt]+where match starts at position 0 for 100 chars/',
1810 setup => '$_ = "a" x 100;',
1811 code => '/[acgt]+/',
1812 },
1813 'regex::anyof_plus::floating_away' => {
1814 desc => '/[acgt]+/ where match starts at position 100 for 100 chars',
1815 setup => '$_ = ("0" x 100) . ("a" x 100);',
1816 code => '/[acgt]+/',
1817 },
77584140
DM
1818
1819 'regex::whilem::min_captures_fail' => {
1820 desc => '/WHILEM with anon-greedy match and captures that fails',
1821 setup => '$_ = ("a" x 20)',
1822 code => '/^(?:(.)(.))*?[XY]/',
1823 },
1824 'regex::whilem::max_captures_fail' => {
1825 desc => '/WHILEM with a greedy match and captures that fails',
1826 setup => '$_ = ("a" x 20)',
1827 code => '/^(?:(.)(.))*[XY]/',
1828 },
fedf30e1 1829];