1#!perl -w
2
3use strict;
4use warnings;
5use Test::More;
6
7use XS::APItest;
8
9my %ix;
10sub showix {
11    diag join ", ", map { $ix{$_} > 1 ? "$_ x $ix{$_}" : $_ } sort { $a <=> $b } keys %ix;
12}
13my $len = 100;
14my $str= "a" x $len;
15my $pat= join "|", map { "a" x $_ } 1 .. $len;
16
17$str=~/^($pat)(??{ $ix{get_savestack_ix()}++; "(?!)" })/;
18my $keys= 0+keys %ix;
19cmp_ok($keys,">",0, "We expect at least one key in %ix for (??{ ... }) test");
20cmp_ok($keys,"<=", 2, "We expect no more than two keys in %ix if (??{ ... }) does not leak")
21    or showix();
22
23%ix= ();
24$str=~/^($pat)(?{ $ix{my $x=get_savestack_ix()}++; })(?!)/;
25$keys= 0+keys %ix;
26cmp_ok($keys,">",0, "We expect at least one key in %ix for (?{ ...  }) test");
27cmp_ok($keys, "<=", 2, "We expect no more than two keys in %ix if (?{ ... }) does not leak")
28    or showix();
29
30%ix= ();
31$str=~/^($pat)(?(?{ $ix{my $x=get_savestack_ix()}++; })x|y)(?!)/;
32$keys= 0+keys %ix;
33cmp_ok($keys,">",0, "We expect at least one key in %ix for (?(?{ ... })yes|no) test");
34cmp_ok($keys, "<=", 2, "We expect no more than two keys in %ix if (?(?{ ... })yes|no) does not leak")
35    or showix();
36
37done_testing();
38