(module main)

(fn parse_f64 ((text string)) -> (result f64 i32)
  (std.string.parse_f64_result text))

(test "parse f64 decimal ok"
  (let value (result f64 i32) (parse_f64 "12.5"))
  (if (std.result.is_ok value)
    (= (std.result.unwrap_ok value) 12.5)
    false))

(test "parse f64 negative decimal ok"
  (let value (result f64 i32) (parse_f64 "-0.25"))
  (if (std.result.is_ok value)
    (= (std.result.unwrap_ok value) (- 0.0 0.25))
    false))

(test "parse f64 text err"
  (let value (result f64 i32) (parse_f64 "abc"))
  (if (std.result.is_err value)
    (= (std.result.unwrap_err value) 1)
    false))

(test "parse f64 nan err"
  (let value (result f64 i32) (parse_f64 "nan"))
  (if (std.result.is_err value)
    (= (std.result.unwrap_err value) 1)
    false))

(fn main () -> i32
  (let value (result f64 i32) (parse_f64 "-0.25"))
  (if (std.result.is_ok value)
    (if (= (std.result.unwrap_ok value) (- 0.0 0.25))
      0
      1)
    (std.result.unwrap_err value)))
