5 @INC = ('../lib', '.');
7 # Avoid using eq_array below as it uses .. internally.
14 is(join(':',1..5), '1:2:3:4:5');
16 @foo = (1,2,3,4,5,6,7,8,9);
17 @foo[2..4] = ('c','d','e');
19 is(join(':',@foo[$foo[0]..5]), '2:c:d:e:6');
21 @bar[2..4] = ('c','d','e');
22 is(join(':',@bar[1..5]), ':c:d:e:');
24 ($a,@bcd[0..2],$e) = ('a','b','c','d','e');
25 is(join(':',$a,@bcd[0..2],$e), 'a:b:c:d:e');
39 $x = join('','a'..'z');
40 is($x, 'abcdefghijklmnopqrstuvwxyz');
43 is (scalar @x, 27 * 26);
45 @x = '09' .. '08'; # should produce '09', '10',... '99' (strange but true)
46 is(join(",", @x), join(",", map {sprintf "%02d",$_} 9..99));
48 # same test with foreach (which is a separate implementation)
50 foreach ('09'..'08') {
53 is(join(",", @y), join(",", @x));
56 if ($Config{ivsize} == 8) {
57 @a = eval "0x7ffffffffffffffe..0x7fffffffffffffff";
58 $a = "9223372036854775806 9223372036854775807";
59 @b = eval "-0x7fffffffffffffff..-0x7ffffffffffffffe";
60 $b = "-9223372036854775807 -9223372036854775806";
63 @a = eval "0x7ffffffe..0x7fffffff";
64 $a = "2147483646 2147483647";
65 @b = eval "-0x7fffffff..-0x7ffffffe";
66 $b = "-2147483647 -2147483646";
76 local $SIG{'__WARN__'} = sub { $bad = 1 };
78 $x =~ s/(\w)-(\w)/join ':', $1 .. $2/e;
82 # Should use magical autoinc only when both are strings
84 my $scalar = (() = "0"..-1);
95 # [#18165] Should allow "-4".."0", broken by #4730. (AMS 20021031)
96 is(join(":","-4".."0") , "-4:-3:-2:-1:0");
97 is(join(":","-4".."-0") , "-4:-3:-2:-1:0");
98 is(join(":","-4\n".."0\n") , "-4:-3:-2:-1:0");
99 is(join(":","-4\n".."-0\n"), "-4:-3:-2:-1:0");
101 # undef should be treated as 0 for numerical range
102 is(join(":",undef..2), '0:1:2');
103 is(join(":",-2..undef), '-2:-1:0');
104 is(join(":",undef..'2'), '0:1:2');
105 is(join(":",'-2'..undef), '-2:-1:0');
107 # undef should be treated as "" for magical range
108 is(join(":", map "[$_]", "".."B"), '[]');
109 is(join(":", map "[$_]", undef.."B"), '[]');
110 is(join(":", map "[$_]", "B"..""), '');
111 is(join(":", map "[$_]", "B"..undef), '');
113 # undef..undef used to segfault
114 is(join(":", map "[$_]", undef..undef), '[]');
116 # also test undef in foreach loops
117 @foo=(); push @foo, $_ for undef..2;
118 is(join(":", @foo), '0:1:2');
120 @foo=(); push @foo, $_ for -2..undef;
121 is(join(":", @foo), '-2:-1:0');
123 @foo=(); push @foo, $_ for undef..'2';
124 is(join(":", @foo), '0:1:2');
126 @foo=(); push @foo, $_ for '-2'..undef;
127 is(join(":", @foo), '-2:-1:0');
129 @foo=(); push @foo, $_ for undef.."B";
130 is(join(":", map "[$_]", @foo), '[]');
132 @foo=(); push @foo, $_ for "".."B";
133 is(join(":", map "[$_]", @foo), '[]');
135 @foo=(); push @foo, $_ for "B"..undef;
136 is(join(":", map "[$_]", @foo), '');
138 @foo=(); push @foo, $_ for "B".."";
139 is(join(":", map "[$_]", @foo), '');
141 @foo=(); push @foo, $_ for undef..undef;
142 is(join(":", map "[$_]", @foo), '[]');
147 @foo=(); push @foo, $_ for undef..$#a;
148 is(join(":", @foo), '0:1:2');
152 @foo=(); push @foo, $_ for $#a..undef;
153 is(join(":", @foo), '-1:0');
158 @foo=(); push @foo, $_ for undef..$1;
159 is(join(":", @foo), '0:1:2');
164 @foo=(); push @foo, $_ for $1..undef;
165 is(join(":", @foo), '-2:-1:0');
170 @foo=(); push @foo, $_ for undef..$1;
171 is(join(":", map "[$_]", @foo), '[]');
176 @foo=(); push @foo, $_ for ""..$1;
177 is(join(":", map "[$_]", @foo), '[]');
182 @foo=(); push @foo, $_ for $1..undef;
183 is(join(":", map "[$_]", @foo), '');
188 @foo=(); push @foo, $_ for $1.."";
189 is(join(":", map "[$_]", @foo), '');
192 # Test upper range limit
195 foreach my $ii (-3 .. 3) {
199 for ($MAX_INT-10 .. $MAX_INT+$ii) {
200 if (! defined($first)) {
204 last if ($lim++ > 100); # Protect against integer wrap
208 ok(! $@, 'Upper bound accepted: ' . ($MAX_INT+$ii));
209 is($first, $MAX_INT-10, 'Lower bound okay');
210 is($last, $MAX_INT+$ii, 'Upper bound okay');
212 ok($@, 'Upper bound rejected: ' . ($MAX_INT+$ii));
216 foreach my $ii (-3 .. 3) {
220 for ($MAX_INT+$ii .. $MAX_INT) {
221 if (! defined($first)) {
225 last if ($lim++ > 100);
229 ok(! $@, 'Lower bound accepted: ' . ($MAX_INT+$ii));
230 is($first, $MAX_INT+$ii, 'Lower bound okay');
231 is($last, $MAX_INT, 'Upper bound okay');
233 ok($@, 'Lower bound rejected: ' . ($MAX_INT+$ii));
241 for ($MAX_INT .. $MAX_INT-1) {
242 if (! defined($first)) {
246 last if ($lim++ > 100);
249 ok(! $@, 'Range accepted');
250 ok(! defined($first), 'Range ineffectual');
253 foreach my $ii (~0, ~0+1, ~0+(~0>>4)) {
256 for ($MAX_INT-10 .. $ii) {
257 last if ($lim++ > 100);
260 ok($@, 'Upper bound rejected: ' . $ii);
263 # Test lower range limit
264 my $MIN_INT = -1-$MAX_INT;
266 if (! $Config{d_nv_preserves_uv}) {
267 # $MIN_INT needs adjustment when IV won't fit into an NV
268 my $NV = $MIN_INT - 1;
270 while (($NV + $OFFSET) == $MIN_INT) {
276 foreach my $ii (-3 .. 3) {
280 for ($MIN_INT+$ii .. $MIN_INT+10) {
281 if (! defined($first)) {
285 last if ($lim++ > 100);
289 ok(! $@, 'Lower bound accepted: ' . ($MIN_INT+$ii));
290 is($first, $MIN_INT+$ii, 'Lower bound okay');
291 is($last, $MIN_INT+10, 'Upper bound okay');
293 ok($@, 'Lower bound rejected: ' . ($MIN_INT+$ii));
297 foreach my $ii (-3 .. 3) {
301 for ($MIN_INT .. $MIN_INT+$ii) {
302 if (! defined($first)) {
306 last if ($lim++ > 100);
310 ok(! $@, 'Upper bound accepted: ' . ($MIN_INT+$ii));
311 is($first, $MIN_INT, 'Lower bound okay');
312 is($last, $MIN_INT+$ii, 'Upper bound okay');
314 ok($@, 'Upper bound rejected: ' . ($MIN_INT+$ii));
322 for ($MIN_INT+1 .. $MIN_INT) {
323 if (! defined($first)) {
327 last if ($lim++ > 100);
330 ok(! $@, 'Range accepted');
331 ok(! defined($first), 'Range ineffectual');
334 foreach my $ii (~0, ~0+1, ~0+(~0>>4)) {
337 for (-$ii .. $MIN_INT+10) {
338 last if ($lim++ > 100);
341 ok($@, 'Lower bound rejected: ' . -$ii);
344 # double/tripple magic tests
345 sub TIESCALAR { bless { value => $_[1], orig => $_[1] } }
346 sub STORE { $_[0]{store}++; $_[0]{value} = $_[1] }
347 sub FETCH { $_[0]{fetch}++; $_[0]{value} }
348 sub stores { tied($_[0])->{value} = tied($_[0])->{orig};
349 delete(tied($_[0])->{store}) || 0 }
350 sub fetches { delete(tied($_[0])->{fetch}) || 0 }
359 local $TODO = "test for double magic with range operator";
368 local $TODO = "test for double magic with range operator";
377 local $TODO = "test for double magic with range operator";
389 local $TODO = "test for double magic with range operator";
395 for (reverse 4 .. $x) {
401 local $TODO = "test for double magic with range operator";