1#!perl
2BEGIN {
3    chdir 't' if -d 't';
4    @INC = "../lib";
5    require './test.pl';
6}
7
8use Config qw(%Config);
9
10$ENV{PERL_TEST_MEMORY} >= 2
11    or skip_all("Need ~2Gb for this test");
12$Config{ptrsize} >= 8
13    or skip_all("Need 64-bit pointers for this test");
14
15plan(6);
16
17# [perl #116907]
18# ${\2} to defeat constant folding, which in this case actually slows
19# things down
20my $x=" "x(${\2}**31) . "abcdefg";
21ok $x =~ /./, 'match against long string succeeded';
22is "$-[0]-$+[0]", '0-1', '@-/@+ after match against long string';
23
24pos $x = 2**31-1;
25my $result;
26for(1..5) {
27    $x =~ /./g;
28    $result .= "$&-";
29}
30is $result," -a-b-c-d-", 'scalar //g hopping past the 2**31 threshold';
31pos $x = 2**31+3;
32$x =~ /./g;
33is "$'", 'efg', q "$' after match against long string";
34is "$-[0],$+[0]", '2147483651,2147483652',
35   '@- and @+ after matches past 2**31';
36
37# Substring optimisations
38is $x =~ /(?:(?:.{32766}){32766}){2}(?:.{32766}){8}.{8}ef/, 1,
39  'anchored substr past 2**31';
40