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

260 lines
6.1 KiB
Plaintext

program main
fn maybe_value(value: i32) -> (option i32)
some i32
var value
fn maybe_empty() -> (option i32)
none i32
fn maybe_wide_value(value: i64) -> (option i64)
some i64
var value
fn maybe_wide_empty() -> (option i64)
none i64
fn maybe_float_value(value: f64) -> (option f64)
some f64
var value
fn maybe_float_empty() -> (option f64)
none f64
fn maybe_flag_value(value: bool) -> (option bool)
some bool
var value
fn maybe_flag_empty() -> (option bool)
none bool
fn maybe_string_value(value: string) -> (option string)
some string
var value
fn maybe_string_empty() -> (option string)
none string
fn result_ok_value(value: i32) -> (result i32 i32)
ok i32 i32
var value
fn result_err_value(code: i32) -> (result i32 i32)
err i32 i32
var code
fn option_value_or(value: (option i32), fallback: i32) -> i32
match
subject
var value
arm some payload
var payload
arm none
var fallback
fn option_bump_or_zero(value: (option i32)) -> i32
match
subject
var value
arm some payload
local let bumped: i32
binary +
var payload
int 1
var bumped
arm none
int 0
fn option_wide_value_or(value: (option i64), fallback: i64) -> i64
match
subject
var value
arm some payload
var payload
arm none
var fallback
fn option_wide_bump_or_zero(value: (option i64)) -> i64
match
subject
var value
arm some payload
local let bumped: i64
binary +
var payload
i64 1
var bumped
arm none
i64 0
fn option_float_value_or(value: (option f64), fallback: f64) -> f64
match
subject
var value
arm some payload
var payload
arm none
var fallback
fn option_float_bump_or_zero(value: (option f64)) -> f64
match
subject
var value
arm some payload
local let bumped: f64
binary +
var payload
float 1
var bumped
arm none
float 0
fn option_flag_value_or(value: (option bool), fallback: bool) -> bool
match
subject
var value
arm some payload
var payload
arm none
var fallback
fn option_flag_selected_or(value: (option bool), fallback: bool) -> bool
match
subject
var value
arm some payload
if
var payload
bool true
bool false
var payload
arm none
var fallback
fn option_string_value_or(value: (option string), fallback: string) -> string
match
subject
var value
arm some payload
var payload
arm none
var fallback
fn option_string_selected_or(value: (option string), fallback: string) -> string
match
subject
var value
arm some payload
local let chosen: string
var payload
var chosen
arm none
var fallback
fn result_value_or_code(value: (result i32 i32)) -> i32
match
subject
var value
arm ok payload
var payload
arm err code
var code
fn result_score(value: (result i32 i32)) -> i32
match
subject
var value
arm ok payload
binary +
var payload
int 10
arm err code
var code
fn main() -> i32
int 0
test "option match some payload"
binary =
call option_value_or
call maybe_value
int 42
int 0
int 42
test "option match none fallback"
binary =
call option_value_or
call maybe_empty
int 7
int 7
test "option match multi expression arm"
binary =
call option_bump_or_zero
call maybe_value
int 8
int 9
test "option i64 match some payload"
binary =
call option_wide_value_or
call maybe_wide_value
i64 2147483648
i64 0
i64 2147483648
test "option i64 match none fallback"
binary =
call option_wide_value_or
call maybe_wide_empty
i64 7
i64 7
test "option i64 match multi expression arm"
binary =
call option_wide_bump_or_zero
call maybe_wide_value
i64 8
i64 9
test "option f64 match some payload"
binary =
call option_float_value_or
call maybe_float_value
float 42.5
float 0
float 42.5
test "option f64 match none fallback"
binary =
call option_float_value_or
call maybe_float_empty
float 7
float 7
test "option f64 match multi expression arm"
binary =
call option_float_bump_or_zero
call maybe_float_value
float 8.5
float 9.5
test "option bool match some payload"
call option_flag_value_or
call maybe_flag_value
bool true
bool false
test "option bool match none fallback"
call option_flag_value_or
call maybe_flag_empty
bool true
test "option bool match multi expression arm"
call option_flag_selected_or
call maybe_flag_value
bool true
bool false
test "option string match some payload"
binary =
call option_string_value_or
call maybe_string_value
string "slovo"
string "fallback"
string "slovo"
test "option string match none fallback"
binary =
call option_string_value_or
call maybe_string_empty
string "fallback"
string "fallback"
test "option string match multi expression arm"
binary =
call option_string_selected_or
call maybe_string_value
string "oak"
string "fallback"
string "oak"
test "result match ok payload"
binary =
call result_value_or_code
call result_ok_value
int 30
int 30
test "result match err payload"
binary =
call result_value_or_code
call result_err_value
int 5
int 5
test "result match computed arm"
binary =
call result_score
call result_ok_value
int 2
int 12