|
1 | 1 | use v6;
|
2 | 2 | use Test;
|
3 | 3 |
|
4 |
| -plan 52; |
| 4 | +plan 71; |
5 | 5 |
|
6 | 6 | {
|
7 | 7 | my int $x;
|
@@ -203,4 +203,74 @@ dies-ok { EVAL 'my str $x = Str;' }, '"my str $x = Str" dies';
|
203 | 203 | dies-ok { EVAL 'my $y = 42; want-num($y)' }, 'Passing Int to num parameter dies';
|
204 | 204 | }
|
205 | 205 |
|
| 206 | +{ |
| 207 | + my int64 $i64; |
| 208 | + is $i64, 0, 'int64 starts off as 0'; |
| 209 | + |
| 210 | + my int32 $i32; |
| 211 | + is $i32, 0, 'int32 starts off as 0'; |
| 212 | + |
| 213 | + my int16 $i16; |
| 214 | + is $i16, 0, 'int16 starts off as 0'; |
| 215 | + |
| 216 | + my int8 $i8; |
| 217 | + is $i8, 0, 'int8 starts off as 0'; |
| 218 | + |
| 219 | + $i8 = 42; |
| 220 | + is $i8, 42, 'can assign in-range value to int8'; |
| 221 | + $i8 = 131; |
| 222 | + isnt $i8 + 1, 132, 'assigning out-of-range value to int8 truncates'; |
| 223 | + |
| 224 | + $i16 = 342; |
| 225 | + is $i16, 342, 'can assign in-range value to int16'; |
| 226 | + $i16 = 32770; |
| 227 | + isnt $i16 + 1, 32771, 'assigning out-of-range value to int16 truncates'; |
| 228 | + |
| 229 | + $i32 = 32771; |
| 230 | + is $i32, 32771, 'can assign in-range value to int32'; |
| 231 | + $i32 = 2147483650; |
| 232 | + isnt $i32 + 1, 2147483651, 'assigning out-of-range value to int32 truncates'; |
| 233 | +} |
| 234 | + |
| 235 | +{ |
| 236 | + sub n64(num64 $i) { |
| 237 | + is $i, 4e2, 'called num64 sub successfully'; |
| 238 | + } |
| 239 | + sub n32(num32 $i) { |
| 240 | + is $i, 4e2, 'called num32 sub successfully'; |
| 241 | + } |
| 242 | + n64(4e2); |
| 243 | + n32(4e2); |
| 244 | + |
| 245 | + sub i64(int64 $i) { |
| 246 | + is $i, 42, 'called int64 sub successfully'; |
| 247 | + } |
| 248 | + sub i32(int32 $i) { |
| 249 | + is $i, 42, 'called int32 sub successfully'; |
| 250 | + } |
| 251 | + sub i16(int16 $i) { |
| 252 | + is $i, 42, 'called int16 sub successfully'; |
| 253 | + } |
| 254 | + sub i8(int8 $i) { |
| 255 | + is $i, 42, 'called int8 sub successfully'; |
| 256 | + } |
| 257 | + i64(42); |
| 258 | + i32(42); |
| 259 | + i16(42); |
| 260 | + i8(42); |
| 261 | + |
| 262 | + sub i32_o(int32 $i) { |
| 263 | + isnt $i, 2147483650, 'sub with int8 arg will see it truncated'; |
| 264 | + } |
| 265 | + sub i16_o(int16 $i) { |
| 266 | + isnt $i, 32770, 'sub with int8 arg will see it truncated'; |
| 267 | + } |
| 268 | + sub i8_o(int8 $i) { |
| 269 | + isnt $i, 257, 'sub with int8 arg will see it truncated'; |
| 270 | + } |
| 271 | + i32_o(2147483650); |
| 272 | + i16_o(32770); |
| 273 | + i8_o(257); |
| 274 | +} |
| 275 | + |
206 | 276 | # vim: ft=perl6
|
0 commit comments