Skip to content

Commit aa42c83

Browse files
authored
Correct tests of (over|under)flow and assignment (#254)
Previously they checked that assigning a literal more than max or less than min would (over|under)flow. However, the correct behavior is to throw in those cases, but (over|under)flow if modifying the variable.
1 parent fa228b0 commit aa42c83

File tree

1 file changed

+34
-17
lines changed

1 file changed

+34
-17
lines changed

S02-types/int-uint.t

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ unless @inttypes {
1717
exit;
1818
}
1919

20-
plan 9 * @inttypes + 3;
20+
plan 11 * @inttypes + 3;
2121

2222
for @inttypes -> $type {
2323
my ($minval,$maxval) = ::($type).Range.int-bounds;
@@ -35,28 +35,45 @@ for @inttypes -> $type {
3535
"$type can be $minval";
3636

3737
if $type eq "uint64" {
38-
#?rakudo.moar 2 skip 'Cannot unbox 65 bit wide bigint into native integer'
39-
is EVAL("my $type \$var = {$maxval+1}; \$var"), $minval,
38+
is EVAL("my $type \$var = $maxval; \$var++; \$var"), $minval,
4039
"$type overflows to $minval";
41-
42-
#?rakudo.jvm 1 todo "expected: '18446744073709551615' got: '-1'"
43-
is EVAL("my $type \$var = {$minval-1}; \$var"), $maxval,
44-
"$type underflows to $maxval";
45-
} elsif $type eq 'int64' {
46-
is EVAL("my $type \$var = {$maxval+1}; \$var"), $minval,
40+
} elsif $type eq "int64" {
41+
is EVAL("my $type \$var = $maxval; \$var++; \$var"), $minval,
4742
"$type overflows to $minval";
48-
49-
is EVAL("my $type \$var = {$minval-1}; \$var"), $maxval,
50-
"$type underflows to $maxval";
5143
} else {
52-
#?rakudo.jvm todo 'wrong overflow'
53-
is EVAL("my $type \$var = {$maxval+1}; \$var"), $minval,
44+
#?rakudo.jvm todo 'max overflow to min'
45+
is EVAL("my $type \$var = $maxval; \$var++; \$var"), $minval,
5446
"$type overflows to $minval";
47+
}
5548

56-
#?rakudo.jvm todo 'wrong underflow'
57-
is EVAL("my $type \$var = {$minval-1}; \$var"), $maxval,
49+
if $type eq "uint64" {
50+
#?rakudo todo 'getting -1 instead of 0'
51+
is EVAL("my $type \$var = $minval; \$var--; \$var"), $maxval,
5852
"$type underflows to $maxval";
59-
}
53+
} elsif $type eq "int64" {
54+
is EVAL("my $type \$var = $minval; \$var--; \$var"), $maxval,
55+
"$type underflows to $maxval";
56+
} else {
57+
#?rakudo.jvm todo 'underflow to max'
58+
is EVAL("my $type \$var = $minval; \$var--; \$var"), $maxval,
59+
"$type underflows to $maxval";
60+
}
61+
62+
if $type eq "uint64" {
63+
#?rakudo.jvm todo 'setting to more than max'
64+
throws-like { EVAL "my $type \$var = {$maxval+1}" },
65+
Exception,
66+
"setting $type to more than $maxval throws";
67+
} else {
68+
#?rakudo todo 'setting more than max throws'
69+
throws-like { EVAL "my $type \$var = {$maxval+1}" },
70+
Exception,
71+
"setting $type to more than $maxval throws";
72+
}
73+
#?rakudo todo 'setting less than min throws'
74+
throws-like { EVAL "my $type \$var = {$minval-1}" },
75+
Exception,
76+
"setting $type to less than $minval throws";
6077

6178
throws-like { EVAL "my $type \$var = 'foo'" },
6279
Exception,

0 commit comments

Comments
 (0)