(module main)

(fn parse_u64 ((text string)) -> (result u64 i32)
  (std.string.parse_u64_result text))

(fn parsed_text ((text string)) -> string
  (std.num.u64_to_string (std.result.unwrap_ok (parse_u64 text))))

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

(test "parse u64 high ok"
  (= (parsed_text "18446744073709551615") "18446744073709551615"))

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

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

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

(test "parse u64 above range err"
  (let value (result u64 i32) (parse_u64 "18446744073709551616"))
  (if (std.result.is_err value)
    (= (std.result.unwrap_err value) 1)
    false))

(fn main () -> i32
  (let value (result u64 i32) (parse_u64 "42"))
  (if (std.result.is_ok value)
    (if (= (std.num.u64_to_string (std.result.unwrap_ok value)) "42")
      0
      1)
    (std.result.unwrap_err value)))
