From 80674ec44d0331ce1ce74fa94852c4253eec9886 Mon Sep 17 00:00:00 2001 From: Daniel Green Date: Thu, 16 Mar 2017 20:11:39 -0400 Subject: [PATCH] Porting the fix in aa42c8340b to 6.c-errata The quick overview is that the tests for (over|under)flow and assigning literals more than max or less than min were incorrect. --- S02-types/int-uint.t | 71 +++++++++++++++++++++++++++++++++----------- 1 file changed, 53 insertions(+), 18 deletions(-) diff --git a/S02-types/int-uint.t b/S02-types/int-uint.t index 88db71ac85..bac90c2a63 100644 --- a/S02-types/int-uint.t +++ b/S02-types/int-uint.t @@ -4,9 +4,10 @@ use Test; # L 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 @@ -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";