slovo/tests/checked-i64-to-i32-conversion.checked.lower
2026-05-22 08:38:43 +02:00

90 lines
2.6 KiB
Plaintext

program main
fn narrow(value: i64) -> (result i32 i32)
call std.num.i64_to_i32_result : (result i32 i32)
var value : i64
fn low_ok() -> (result i32 i32)
call narrow : (result i32 i32)
i64 -2147483648 : i64
fn high_ok() -> (result i32 i32)
call narrow : (result i32 i32)
i64 2147483647 : i64
fn negative_ok() -> (result i32 i32)
call narrow : (result i32 i32)
i64 -7 : i64
fn below_low_err() -> (result i32 i32)
call narrow : (result i32 i32)
i64 -2147483649 : i64
fn above_high_err() -> (result i32 i32)
call narrow : (result i32 i32)
i64 2147483648 : i64
fn main() -> i32
local let value : unit
call negative_ok : (result i32 i32)
if : i32
std.result.is_ok : bool
var value : (result i32 i32)
if : i32
binary = : bool
std.result.unwrap_ok : i32
var value : (result i32 i32)
int -7 : i32
int 0 : i32
int 1 : i32
std.result.unwrap_err : i32
var value : (result i32 i32)
test "i64 low bound narrows to i32"
local let value : unit
call low_ok : (result i32 i32)
if : bool
std.result.is_ok : bool
var value : (result i32 i32)
binary = : bool
std.result.unwrap_ok : i32
var value : (result i32 i32)
int -2147483648 : i32
bool false : bool
test "i64 high bound narrows to i32"
local let value : unit
call high_ok : (result i32 i32)
if : bool
std.result.is_ok : bool
var value : (result i32 i32)
binary = : bool
std.result.unwrap_ok : i32
var value : (result i32 i32)
int 2147483647 : i32
bool false : bool
test "negative i64 narrows to i32"
local let value : unit
call negative_ok : (result i32 i32)
if : bool
std.result.is_ok : bool
var value : (result i32 i32)
binary = : bool
std.result.unwrap_ok : i32
var value : (result i32 i32)
int -7 : i32
bool false : bool
test "below i32 range returns err"
local let value : unit
call below_low_err : (result i32 i32)
if : bool
std.result.is_err : bool
var value : (result i32 i32)
binary = : bool
std.result.unwrap_err : i32
var value : (result i32 i32)
int 1 : i32
bool false : bool
test "above i32 range returns err"
local let value : unit
call above_high_err : (result i32 i32)
if : bool
std.result.is_err : bool
var value : (result i32 i32)
binary = : bool
std.result.unwrap_err : i32
var value : (result i32 i32)
int 1 : i32
bool false : bool