1N/A#!./perl
1N/A
1N/ABEGIN {
1N/A chdir 't' if -d 't';
1N/A @INC = '../lib';
1N/A}
1N/A
1N/Ause Config;
1N/A
1N/Aprint "1..37\n";
1N/A
1N/Aprint join(':',1..5) eq '1:2:3:4:5' ? "ok 1\n" : "not ok 1\n";
1N/A
1N/A@foo = (1,2,3,4,5,6,7,8,9);
1N/A@foo[2..4] = ('c','d','e');
1N/A
1N/Aprint join(':',@foo[$foo[0]..5]) eq '2:c:d:e:6' ? "ok 2\n" : "not ok 2\n";
1N/A
1N/A@bar[2..4] = ('c','d','e');
1N/Aprint join(':',@bar[1..5]) eq ':c:d:e:' ? "ok 3\n" : "not ok 3\n";
1N/A
1N/A($a,@bcd[0..2],$e) = ('a','b','c','d','e');
1N/Aprint join(':',$a,@bcd[0..2],$e) eq 'a:b:c:d:e' ? "ok 4\n" : "not ok 4\n";
1N/A
1N/A$x = 0;
1N/Afor (1..100) {
1N/A $x += $_;
1N/A}
1N/Aprint $x == 5050 ? "ok 5\n" : "not ok 5 $x\n";
1N/A
1N/A$x = 0;
1N/Afor ((100,2..99,1)) {
1N/A $x += $_;
1N/A}
1N/Aprint $x == 5050 ? "ok 6\n" : "not ok 6 $x\n";
1N/A
1N/A$x = join('','a'..'z');
1N/Aprint $x eq 'abcdefghijklmnopqrstuvwxyz' ? "ok 7\n" : "not ok 7 $x\n";
1N/A
1N/A@x = 'A'..'ZZ';
1N/Aprint @x == 27 * 26 ? "ok 8\n" : "not ok 8\n";
1N/A
1N/A@x = '09' .. '08'; # should produce '09', '10',... '99' (strange but true)
1N/Aprint "not " unless join(",", @x) eq
1N/A join(",", map {sprintf "%02d",$_} 9..99);
1N/Aprint "ok 9\n";
1N/A
1N/A# same test with foreach (which is a separate implementation)
1N/A@y = ();
1N/Aforeach ('09'..'08') {
1N/A push(@y, $_);
1N/A}
1N/Aprint "not " unless join(",", @y) eq join(",", @x);
1N/Aprint "ok 10\n";
1N/A
1N/A# check bounds
1N/Aif ($Config{ivsize} == 8) {
1N/A @a = eval "0x7ffffffffffffffe..0x7fffffffffffffff";
1N/A $a = "9223372036854775806 9223372036854775807";
1N/A @b = eval "-0x7fffffffffffffff..-0x7ffffffffffffffe";
1N/A $b = "-9223372036854775807 -9223372036854775806";
1N/A}
1N/Aelse {
1N/A @a = eval "0x7ffffffe..0x7fffffff";
1N/A $a = "2147483646 2147483647";
1N/A @b = eval "-0x7fffffff..-0x7ffffffe";
1N/A $b = "-2147483647 -2147483646";
1N/A}
1N/A
1N/Aprint "not " unless "@a" eq $a;
1N/Aprint "ok 11\n";
1N/A
1N/Aprint "not " unless "@b" eq $b;
1N/Aprint "ok 12\n";
1N/A
1N/A# check magic
1N/A{
1N/A my $bad = 0;
1N/A local $SIG{'__WARN__'} = sub { $bad = 1 };
1N/A my $x = 'a-e';
1N/A $x =~ s/(\w)-(\w)/join ':', $1 .. $2/e;
1N/A $bad = 1 unless $x eq 'a:b:c:d:e';
1N/A print $bad ? "not ok 13\n" : "ok 13\n";
1N/A}
1N/A
1N/A# Should use magical autoinc only when both are strings
1N/Aprint "not " unless 0 == (() = "0"..-1);
1N/Aprint "ok 14\n";
1N/A
1N/Afor my $x ("0"..-1) {
1N/A print "not ";
1N/A}
1N/Aprint "ok 15\n";
1N/A
1N/A# [#18165] Should allow "-4".."0", broken by #4730. (AMS 20021031)
1N/Aprint join(":","-4".."0") eq "-4:-3:-2:-1:0" ? "ok 16\n" : "not ok 16\n";
1N/Aprint join(":","-4".."-0") eq "-4:-3:-2:-1:0" ? "ok 17\n" : "not ok 17\n";
1N/Aprint join(":","-4\n".."0\n") eq "-4:-3:-2:-1:0" ? "ok 18\n" : "not ok 18\n";
1N/Aprint join(":","-4\n".."-0\n") eq "-4:-3:-2:-1:0" ? "ok 19\n" : "not ok 19\n";
1N/A
1N/A# undef should be treated as 0 for numerical range
1N/Aprint join(":",undef..2) eq '0:1:2' ? "ok 20\n" : "not ok 20\n";
1N/Aprint join(":",-2..undef) eq '-2:-1:0' ? "ok 21\n" : "not ok 21\n";
1N/Aprint join(":",undef..'2') eq '0:1:2' ? "ok 22\n" : "not ok 22\n";
1N/Aprint join(":",'-2'..undef) eq '-2:-1:0' ? "ok 23\n" : "not ok 23\n";
1N/A
1N/A# undef should be treated as "" for magical range
1N/Aprint join(":", map "[$_]", "".."B") eq '[]' ? "ok 24\n" : "not ok 24\n";
1N/Aprint join(":", map "[$_]", undef.."B") eq '[]' ? "ok 25\n" : "not ok 25\n";
1N/Aprint join(":", map "[$_]", "B".."") eq '' ? "ok 26\n" : "not ok 26\n";
1N/Aprint join(":", map "[$_]", "B"..undef) eq '' ? "ok 27\n" : "not ok 27\n";
1N/A
1N/A# undef..undef used to segfault
1N/Aprint join(":", map "[$_]", undef..undef) eq '[]' ? "ok 28\n" : "not ok 28\n";
1N/A
1N/A# also test undef in foreach loops
1N/A@foo=(); push @foo, $_ for undef..2;
1N/Aprint join(":", @foo) eq '0:1:2' ? "ok 29\n" : "not ok 29\n";
1N/A
1N/A@foo=(); push @foo, $_ for -2..undef;
1N/Aprint join(":", @foo) eq '-2:-1:0' ? "ok 30\n" : "not ok 30\n";
1N/A
1N/A@foo=(); push @foo, $_ for undef..'2';
1N/Aprint join(":", @foo) eq '0:1:2' ? "ok 31\n" : "not ok 31\n";
1N/A
1N/A@foo=(); push @foo, $_ for '-2'..undef;
1N/Aprint join(":", @foo) eq '-2:-1:0' ? "ok 32\n" : "not ok 32\n";
1N/A
1N/A@foo=(); push @foo, $_ for undef.."B";
1N/Aprint join(":", map "[$_]", @foo) eq '[]' ? "ok 33\n" : "not ok 33\n";
1N/A
1N/A@foo=(); push @foo, $_ for "".."B";
1N/Aprint join(":", map "[$_]", @foo) eq '[]' ? "ok 34\n" : "not ok 34\n";
1N/A
1N/A@foo=(); push @foo, $_ for "B"..undef;
1N/Aprint join(":", map "[$_]", @foo) eq '' ? "ok 35\n" : "not ok 35\n";
1N/A
1N/A@foo=(); push @foo, $_ for "B".."";
1N/Aprint join(":", map "[$_]", @foo) eq '' ? "ok 36\n" : "not ok 36\n";
1N/A
1N/A@foo=(); push @foo, $_ for undef..undef;
1N/Aprint join(":", map "[$_]", @foo) eq '[]' ? "ok 37\n" : "not ok 37\n";