program main
  fn parse_text(text: string) -> (result i32 i32)
    call std.string.parse_i32_result
      var text
  fn parse_stdin_text() -> (result i32 i32)
    local let input: (result string i32)
      call std.io.read_stdin_result
    match
      subject
        var input
      arm ok text
        call std.string.parse_i32_result
          var text
      arm err code
        err i32 i32
          var code
  fn main() -> i32
    local let value: (result i32 i32)
      call parse_stdin_text
    if
      is_ok
        var value
      unwrap_ok
        var value
      unwrap_err
        var value
  test "parse 42 ok"
    binary =
      unwrap_ok
        call parse_text
          string "42"
      int 42
  test "parse negative 7 ok"
    binary =
      unwrap_ok
        call parse_text
          string "-7"
      int -7
  test "parse empty err"
    binary =
      unwrap_err
        call parse_text
          string ""
      int 1
  test "parse trailing byte err"
    binary =
      unwrap_err
        call parse_text
          string "12x"
      int 1
  test "parse overflow err"
    binary =
      unwrap_err
        call parse_text
          string "2147483648"
      int 1
  test "parse stdin text structurally"
    local let value: (result i32 i32)
      call parse_stdin_text
    match
      subject
        var value
      arm ok parsed
        binary =
          var parsed
          var parsed
      arm err code
        binary =
          var code
          int 1
