(module main)

(fn parse_bool ((text string)) -> (result bool i32)
  (std.string.parse_bool_result text))

(fn bool_score ((text string)) -> i32
  (let value (result bool i32) (parse_bool text))
  (if (std.result.is_ok value)
    (if (std.result.unwrap_ok value)
      1
      0)
    (std.result.unwrap_err value)))

(test "parse bool true ok"
  (let value (result bool i32) (parse_bool "true"))
  (if (std.result.is_ok value)
    (std.result.unwrap_ok value)
    false))

(test "parse bool false ok"
  (let value (result bool i32) (parse_bool "false"))
  (if (std.result.is_ok value)
    (if (std.result.unwrap_ok value)
      false
      true)
    false))

(test "parse bool uppercase err"
  (let value (result bool i32) (parse_bool "TRUE"))
  (if (std.result.is_err value)
    (= (std.result.unwrap_err value) 1)
    false))

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

(test "parse bool whitespace err"
  (let value (result bool i32) (parse_bool " true"))
  (if (std.result.is_err value)
    (= (std.result.unwrap_err value) 1)
    false))

(test "parse bool helper flow"
  (= (+ (bool_score "true") (bool_score "false")) 1))

(fn main () -> i32
  (let value (result bool i32) (parse_bool "true"))
  (if (std.result.is_ok value)
    (if (std.result.unwrap_ok value)
      0
      1)
    (std.result.unwrap_err value)))
