Skip to content

Commit

Permalink
Porting the fix in aa42c83 to 6.c-errata
Browse files Browse the repository at this point in the history
The quick overview is that the tests for (over|under)flow and assigning
literals more than max or less than min were incorrect.
  • Loading branch information
MasterDuke17 committed Mar 17, 2017
1 parent 6324959 commit 80674ec
Showing 1 changed file with 53 additions and 18 deletions.
71 changes: 53 additions & 18 deletions S02-types/int-uint.t
Expand Up @@ -4,9 +4,10 @@ use Test;
# L<S09/Sized types/Sized low-level types are named most generally by appending the number of bits to a generic low-level type name>

my @inttypes = <1 2 4 8 16 32 64>.map({
"int$_","uint$_"
|("int$_","uint$_")
}).grep: {
try EVAL "my $_ \$var; \$var.WHAT eq '($_)'"
use MONKEY-SEE-NO-EVAL;
try EVAL "my $_ \$var = 1; \$var"
};

# nothing to test, we're done
Expand All @@ -16,30 +17,64 @@ unless @inttypes {
exit;
}

plan 9 * @inttypes;
plan 11 * @inttypes;

for @inttypes -> $type {
my ($minval,$maxval) = ::($type).Range.int-bounds;

my $maxval; my $minval;
$type ~~ /(\d+)/;
my $len = $/[0]; # get the numeric value
if $type ~~ /^uint/ {
$maxval = 2**$len - 1;
$minval = 0;
} else { # /^int/
$maxval = 2**($len - 1) - 1;
$minval = -(2**($len - 1));
if $type eq "uint64" {
#?rakudo todo 'getting -1 instead of 18446744073709551615'
is EVAL("my $type \$var = $maxval; \$var"), $maxval,
"$type can be $maxval";
} else {
is EVAL("my $type \$var = $maxval; \$var"), $maxval,
"$type can be $maxval";
}

is(EVAL("my $type \$var = $maxval"), $maxval, "$type can be $maxval");
is(EVAL("my $type \$var = $minval"), $minval, "$type can be $minval");
is EVAL("my $type \$var = $minval; \$var"), $minval,
"$type can be $minval";

throws-like { EVAL "my $type \$var = {$maxval+1}" },
Exception,
"$type cannot be {$maxval+1}";
if $type eq "uint64" {
is EVAL("my $type \$var = $maxval; \$var++; \$var"), $minval,
"$type overflows to $minval";
} elsif $type eq "int64" {
is EVAL("my $type \$var = $maxval; \$var++; \$var"), $minval,
"$type overflows to $minval";
} else {
#?rakudo.jvm todo 'max overflow to min'
is EVAL("my $type \$var = $maxval; \$var++; \$var"), $minval,
"$type overflows to $minval";
}

if $type eq "uint64" {
#?rakudo todo 'getting -1 instead of 0'
is EVAL("my $type \$var = $minval; \$var--; \$var"), $maxval,
"$type underflows to $maxval";
} elsif $type eq "int64" {
is EVAL("my $type \$var = $minval; \$var--; \$var"), $maxval,
"$type underflows to $maxval";
} else {
#?rakudo.jvm todo 'underflow to max'
is EVAL("my $type \$var = $minval; \$var--; \$var"), $maxval,
"$type underflows to $maxval";
}

if $type eq "uint64" {
#?rakudo.jvm todo 'setting to more than max'
throws-like { EVAL "my $type \$var = {$maxval+1}" },
Exception,
"setting $type to more than $maxval throws";
} else {
#?rakudo todo 'setting more than max throws'
throws-like { EVAL "my $type \$var = {$maxval+1}" },
Exception,
"setting $type to more than $maxval throws";
}
#?rakudo todo 'setting less than min throws'
throws-like { EVAL "my $type \$var = {$minval-1}" },
Exception,
"$type cannot be {$minval-1}";
"setting $type to less than $minval throws";

throws-like { EVAL "my $type \$var = 'foo'" },
Exception,
"$type cannot be a string";
Expand Down

0 comments on commit 80674ec

Please sign in to comment.