File: savestack.t

package info (click to toggle)
perl 5.42.0-3
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 128,392 kB
  • sloc: perl: 534,963; ansic: 240,563; sh: 72,042; pascal: 6,934; xml: 2,428; yacc: 1,360; makefile: 1,197; cpp: 208; lisp: 1
file content (37 lines) | stat: -rw-r--r-- 1,135 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
#!perl -w

use strict;
use warnings;
use Test::More;

use XS::APItest;

my %ix;
sub showix {
    diag join ", ", map { $ix{$_} > 1 ? "$_ x $ix{$_}" : $_ } sort { $a <=> $b } keys %ix;
}
my $len = 100;
my $str= "a" x $len;
my $pat= join "|", map { "a" x $_ } 1 .. $len;

$str=~/^($pat)(??{ $ix{get_savestack_ix()}++; "(?!)" })/;
my $keys= 0+keys %ix;
cmp_ok($keys,">",0, "We expect at least one key in %ix for (??{ ... }) test");
cmp_ok($keys,"<=", 2, "We expect no more than two keys in %ix if (??{ ... }) does not leak")
    or showix();

%ix= ();
$str=~/^($pat)(?{ $ix{my $x=get_savestack_ix()}++; })(?!)/;
$keys= 0+keys %ix;
cmp_ok($keys,">",0, "We expect at least one key in %ix for (?{ ...  }) test");
cmp_ok($keys, "<=", 2, "We expect no more than two keys in %ix if (?{ ... }) does not leak")
    or showix();

%ix= ();
$str=~/^($pat)(?(?{ $ix{my $x=get_savestack_ix()}++; })x|y)(?!)/;
$keys= 0+keys %ix;
cmp_ok($keys,">",0, "We expect at least one key in %ix for (?(?{ ... })yes|no) test");
cmp_ok($keys, "<=", 2, "We expect no more than two keys in %ix if (?(?{ ... })yes|no) does not leak")
    or showix();

done_testing();