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

108 lines
2.6 KiB
Plaintext

program main
fn fixture_path() -> string
string "slovo-exp10-host-io-result.txt"
fn ok_text(value: string) -> (result string i32)
ok string i32
var value
fn err_text(code: i32) -> (result string i32)
err string i32
var code
fn result_text_or_error(value: (result string i32)) -> string
match
subject
var value
arm ok payload
var payload
arm err code
call std.io.print_i32
var code
string "error"
fn result_text_len_or_code(value: (result string i32)) -> i32
match
subject
var value
arm ok payload
call std.string.len
var payload
arm err code
var code
fn write_fixture_result() -> (result i32 i32)
call std.fs.write_text_result
call fixture_path
string "exp10 host io"
fn read_fixture_result() -> (result string i32)
call std.fs.write_text_result
call fixture_path
string "exp10 host io"
call std.fs.read_text_result
call fixture_path
fn missing_env_result() -> (result string i32)
call std.env.get_result
string "SLOVO_EXP10_MISSING_ENV"
fn first_arg_ok_score() -> i32
if
binary <
int 0
call std.process.argc
if
is_ok
call std.process.arg_result
int 0
int 1
int 0
int 0
fn read_unwrapped_text() -> string
unwrap_ok
call read_fixture_result
fn missing_env_code() -> i32
unwrap_err
call missing_env_result
fn main() -> i32
call std.io.eprint
string "exp-10 host io result"
if
is_ok
call write_fixture_result
unwrap_ok
call write_fixture_result
int 1
test "string result constructor ok"
binary =
call result_text_or_error
call ok_text
string "constructed"
string "constructed"
test "string result constructor err"
binary =
call result_text_len_or_code
call err_text
int 1
int 1
test "missing env returns err 1"
binary =
call missing_env_code
int 1
test "arg result is ok when argc is positive"
binary =
call first_arg_ok_score
if
binary <
int 0
call std.process.argc
int 1
int 0
test "write text result returns ok zero"
binary =
unwrap_ok
call write_fixture_result
int 0
test "read text result returns written text"
binary =
call read_unwrapped_text
string "exp10 host io"
test "read text result match observes string payload"
binary =
call result_text_len_or_code
call read_fixture_result
int 13