slovo/tests/result-helpers.surface.lower
2026-05-22 08:38:43 +02:00

94 lines
2.0 KiB
Plaintext

program main
fn i32_ok() -> (result i32 i32)
ok i32 i32
int 42
fn i32_err() -> (result i32 i32)
err i32 i32
int 7
fn text_ok() -> (result string i32)
ok string i32
string "value"
fn text_err() -> (result string i32)
err string i32
int 9
fn observe_i32_ok() -> bool
std.result.is_ok
call i32_ok
fn observe_i32_err() -> bool
std.result.is_err
call i32_err
fn unwrap_i32_ok() -> i32
std.result.unwrap_ok
call i32_ok
fn unwrap_i32_err() -> i32
std.result.unwrap_err
call i32_err
fn observe_text_ok() -> bool
std.result.is_ok
call text_ok
fn observe_text_err() -> bool
std.result.is_err
call text_err
fn unwrap_text_ok() -> string
std.result.unwrap_ok
call text_ok
fn unwrap_text_err() -> i32
std.result.unwrap_err
call text_err
fn legacy_i32_ok() -> bool
is_ok
call i32_ok
fn legacy_text_err() -> i32
unwrap_err
call text_err
fn main() -> i32
if
std.result.is_ok
call i32_ok
std.result.unwrap_ok
call i32_ok
std.result.unwrap_err
call i32_err
test "std result i32 observers"
if
std.result.is_ok
call i32_ok
std.result.is_err
call i32_err
bool false
test "std result i32 unwraps"
binary =
binary +
std.result.unwrap_ok
call i32_ok
std.result.unwrap_err
call i32_err
int 49
test "std result string observers"
if
std.result.is_ok
call text_ok
std.result.is_err
call text_err
bool false
test "std result string unwraps"
if
binary =
std.result.unwrap_ok
call text_ok
string "value"
binary =
std.result.unwrap_err
call text_err
int 9
bool false
test "legacy result helpers still work"
if
is_ok
call i32_ok
binary =
unwrap_err
call text_err
int 9
bool false