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