(module main)

(fn parse_u32 ((text string)) -> (result u32 i32)
  (std.string.parse_u32_result text))

(fn parsed_text ((text string)) -> string
  (std.num.u32_to_string (std.result.unwrap_ok (parse_u32 text))))

(test "parse u32 zero ok"
  (= (parsed_text "0") "0"))

(test "parse u32 high ok"
  (= (parsed_text "4294967295") "4294967295"))

(test "parse u32 empty err"
  (let value (result u32 i32) (parse_u32 ""))
  (if (std.result.is_err value)
    (= (std.result.unwrap_err value) 1)
    false))

(test "parse u32 plus err"
  (let value (result u32 i32) (parse_u32 "+1"))
  (if (std.result.is_err value)
    (= (std.result.unwrap_err value) 1)
    false))

(test "parse u32 negative err"
  (let value (result u32 i32) (parse_u32 "-1"))
  (if (std.result.is_err value)
    (= (std.result.unwrap_err value) 1)
    false))

(test "parse u32 above range err"
  (let value (result u32 i32) (parse_u32 "4294967296"))
  (if (std.result.is_err value)
    (= (std.result.unwrap_err value) 1)
    false))

(fn main () -> i32
  (let value (result u32 i32) (parse_u32 "42"))
  (if (std.result.is_ok value)
    (if (= (std.num.u32_to_string (std.result.unwrap_ok value)) "42")
      0
      1)
    (std.result.unwrap_err value)))
