(module main)

(import std.option (some_i32 none_i32 is_some_i32 is_none_i32 unwrap_some_i32 unwrap_or_i32 some_or_err_i32 some_u32 none_u32 is_some_u32 is_none_u32 unwrap_some_u32 unwrap_or_u32 some_or_err_u32 some_i64 none_i64 is_some_i64 is_none_i64 unwrap_some_i64 unwrap_or_i64 some_or_err_i64 some_u64 none_u64 is_some_u64 is_none_u64 unwrap_some_u64 unwrap_or_u64 some_or_err_u64 some_f64 none_f64 is_some_f64 is_none_f64 unwrap_some_f64 unwrap_or_f64 some_or_err_f64 some_bool none_bool is_some_bool is_none_bool unwrap_some_bool unwrap_or_bool some_or_err_bool some_string none_string is_some_string is_none_string unwrap_some_string unwrap_or_string some_or_err_string))

(fn some_value_i32 ((value i32)) -> (option i32)
  (some_i32 value))

(fn none_value_i32 () -> (option i32)
  (none_i32))

(fn some_value_i64 ((value i64)) -> (option i64)
  (some_i64 value))

(fn none_value_i64 () -> (option i64)
  (none_i64))

(fn some_value_u32 ((value u32)) -> (option u32)
  (some_u32 value))

(fn none_value_u32 () -> (option u32)
  (none_u32))

(fn some_value_u64 ((value u64)) -> (option u64)
  (some_u64 value))

(fn none_value_u64 () -> (option u64)
  (none_u64))

(fn some_value_f64 ((value f64)) -> (option f64)
  (some_f64 value))

(fn none_value_f64 () -> (option f64)
  (none_f64))

(fn some_value_bool ((value bool)) -> (option bool)
  (some_bool value))

(fn none_value_bool () -> (option bool)
  (none_bool))

(fn some_value_string ((value string)) -> (option string)
  (some_string value))

(fn none_value_string () -> (option string)
  (none_string))

(fn imported_option_i32_observation_ok () -> bool
  (if (is_some_i32 (some_value_i32 42))
    (is_none_i32 (none_value_i32))
    false))

(fn imported_option_i32_unwrap_some_score () -> i32
  (+ (unwrap_some_i32 (some_value_i32 20)) (unwrap_some_i32 (some_value_i32 22))))

(fn imported_option_i32_unwrap_or_score () -> i32
  (+ (unwrap_or_i32 (some_value_i32 40) 0) (unwrap_or_i32 (none_value_i32) 2)))

(fn imported_option_i32_some_or_err_ok () -> bool
  (match (some_or_err_i32 (some_value_i32 42) 5)
    ((ok payload)
      (= payload 42))
    ((err code)
      false)))

(fn imported_option_i32_some_or_err_err () -> bool
  (match (some_or_err_i32 (none_value_i32) 5)
    ((ok payload)
      false)
    ((err code)
      (= code 5))))

(fn imported_option_i64_observation_ok () -> bool
  (if (is_some_i64 (some_value_i64 2147483648i64))
    (is_none_i64 (none_value_i64))
    false))

(fn imported_option_i64_unwrap_some_score () -> i64
  (+ (unwrap_some_i64 (some_value_i64 2147483648i64)) (unwrap_some_i64 (some_value_i64 12i64))))

(fn imported_option_i64_unwrap_or_score () -> i64
  (+ (unwrap_or_i64 (some_value_i64 40i64) 0i64) (unwrap_or_i64 (none_value_i64) 2i64)))

(fn imported_option_i64_some_or_err_ok () -> bool
  (match (some_or_err_i64 (some_value_i64 2147483648i64) 6)
    ((ok payload)
      (= payload 2147483648i64))
    ((err code)
      false)))

(fn imported_option_i64_some_or_err_err () -> bool
  (match (some_or_err_i64 (none_value_i64) 6)
    ((ok payload)
      false)
    ((err code)
      (= code 6))))

(fn imported_option_u32_observation_ok () -> bool
  (if (is_some_u32 (some_value_u32 42u32))
    (is_none_u32 (none_value_u32))
    false))

(fn imported_option_u32_unwrap_some_score () -> u32
  (+ (unwrap_some_u32 (some_value_u32 20u32)) (unwrap_some_u32 (some_value_u32 22u32))))

(fn imported_option_u32_unwrap_or_score () -> u32
  (+ (unwrap_or_u32 (some_value_u32 40u32) 0u32) (unwrap_or_u32 (none_value_u32) 2u32)))

(fn imported_option_u32_some_or_err_ok () -> bool
  (match (some_or_err_u32 (some_value_u32 42u32) 10)
    ((ok payload)
      (= payload 42u32))
    ((err code)
      false)))

(fn imported_option_u32_some_or_err_err () -> bool
  (match (some_or_err_u32 (none_value_u32) 10)
    ((ok payload)
      false)
    ((err code)
      (= code 10))))

(fn imported_option_u64_observation_ok () -> bool
  (if (is_some_u64 (some_value_u64 4294967296u64))
    (is_none_u64 (none_value_u64))
    false))

(fn imported_option_u64_unwrap_some_score () -> u64
  (+ (unwrap_some_u64 (some_value_u64 4294967296u64)) (unwrap_some_u64 (some_value_u64 12u64))))

(fn imported_option_u64_unwrap_or_score () -> u64
  (+ (unwrap_or_u64 (some_value_u64 40u64) 0u64) (unwrap_or_u64 (none_value_u64) 2u64)))

(fn imported_option_u64_some_or_err_ok () -> bool
  (match (some_or_err_u64 (some_value_u64 4294967296u64) 11)
    ((ok payload)
      (= payload 4294967296u64))
    ((err code)
      false)))

(fn imported_option_u64_some_or_err_err () -> bool
  (match (some_or_err_u64 (none_value_u64) 11)
    ((ok payload)
      false)
    ((err code)
      (= code 11))))

(fn imported_option_f64_observation_ok () -> bool
  (if (is_some_f64 (some_value_f64 42.5))
    (is_none_f64 (none_value_f64))
    false))

(fn imported_option_f64_unwrap_some_score () -> f64
  (+ (unwrap_some_f64 (some_value_f64 20.5)) (unwrap_some_f64 (some_value_f64 21.5))))

(fn imported_option_f64_unwrap_or_score () -> f64
  (+ (unwrap_or_f64 (some_value_f64 40.0) 0.0) (unwrap_or_f64 (none_value_f64) 2.0)))

(fn imported_option_f64_some_or_err_ok () -> bool
  (match (some_or_err_f64 (some_value_f64 42.5) 7)
    ((ok payload)
      (= payload 42.5))
    ((err code)
      false)))

(fn imported_option_f64_some_or_err_err () -> bool
  (match (some_or_err_f64 (none_value_f64) 7)
    ((ok payload)
      false)
    ((err code)
      (= code 7))))

(fn imported_option_bool_observation_ok () -> bool
  (if (is_some_bool (some_value_bool true))
    (is_none_bool (none_value_bool))
    false))

(fn imported_option_bool_unwrap_some_ok () -> bool
  (unwrap_some_bool (some_value_bool true)))

(fn imported_option_bool_unwrap_or_ok () -> bool
  (if (unwrap_or_bool (some_value_bool true) false)
    (unwrap_or_bool (none_value_bool) true)
    false))

(fn imported_option_bool_some_or_err_ok () -> bool
  (match (some_or_err_bool (some_value_bool true) 8)
    ((ok payload)
      payload)
    ((err code)
      false)))

(fn imported_option_bool_some_or_err_err () -> bool
  (match (some_or_err_bool (none_value_bool) 8)
    ((ok payload)
      false)
    ((err code)
      (= code 8))))

(fn imported_option_string_observation_ok () -> bool
  (if (is_some_string (some_value_string "slovo"))
    (is_none_string (none_value_string))
    false))

(fn imported_option_string_unwrap_some_ok () -> bool
  (= (unwrap_some_string (some_value_string "slovo")) "slovo"))

(fn imported_option_string_unwrap_or_ok () -> bool
  (if (= (unwrap_or_string (some_value_string "oak") "") "oak")
    (= (unwrap_or_string (none_value_string) "fallback") "fallback")
    false))

(fn imported_option_string_some_or_err_ok () -> bool
  (match (some_or_err_string (some_value_string "slovo") 9)
    ((ok payload)
      (= payload "slovo"))
    ((err code)
      false)))

(fn imported_option_string_some_or_err_err () -> bool
  (match (some_or_err_string (none_value_string) 9)
    ((ok payload)
      false)
    ((err code)
      (= code 9))))

(fn imported_option_helpers_ok () -> bool
  (if (imported_option_i32_observation_ok)
    (if (= (imported_option_i32_unwrap_some_score) 42)
      (if (= (imported_option_i32_unwrap_or_score) 42)
        (if (imported_option_i32_some_or_err_ok)
          (if (imported_option_i32_some_or_err_err)
            (if (imported_option_u32_observation_ok)
              (if (= (imported_option_u32_unwrap_some_score) 42u32)
                (if (= (imported_option_u32_unwrap_or_score) 42u32)
                  (if (imported_option_u32_some_or_err_ok)
                    (if (imported_option_u32_some_or_err_err)
                      (if (imported_option_i64_observation_ok)
                        (if (= (imported_option_i64_unwrap_some_score) 2147483660i64)
                          (if (= (imported_option_i64_unwrap_or_score) 42i64)
                            (if (imported_option_i64_some_or_err_ok)
                              (if (imported_option_i64_some_or_err_err)
                                (if (imported_option_u64_observation_ok)
                                  (if (= (imported_option_u64_unwrap_some_score) 4294967308u64)
                                    (if (= (imported_option_u64_unwrap_or_score) 42u64)
                                      (if (imported_option_u64_some_or_err_ok)
                                        (if (imported_option_u64_some_or_err_err)
                                          (if (imported_option_f64_observation_ok)
                                            (if (= (imported_option_f64_unwrap_some_score) 42.0)
                                              (if (= (imported_option_f64_unwrap_or_score) 42.0)
                                                (if (imported_option_f64_some_or_err_ok)
                                                  (if (imported_option_f64_some_or_err_err)
                                                    (if (imported_option_bool_observation_ok)
                                                      (if (imported_option_bool_unwrap_some_ok)
                                                        (if (imported_option_bool_unwrap_or_ok)
                                                          (if (imported_option_bool_some_or_err_ok)
                                                            (if (imported_option_bool_some_or_err_err)
                                                              (if (imported_option_string_observation_ok)
                                                                (if (imported_option_string_unwrap_some_ok)
                                                                  (if (imported_option_string_unwrap_or_ok)
                                                                    (if (imported_option_string_some_or_err_ok)
                                                                      (imported_option_string_some_or_err_err)
                                                                      false)
                                                                    false)
                                                                  false)
                                                                false)
                                                              false)
                                                            false)
                                                          false)
                                                        false)
                                                      false)
                                                    false)
                                                  false)
                                                false)
                                              false)
                                            false)
                                          false)
                                        false)
                                      false)
                                    false)
                                  false)
                                false)
                              false)
                            false)
                          false)
                        false)
                      false)
                    false)
                  false)
                false)
              false)
            false)
          false)
        false)
      false)
    false))

(fn main () -> i32
  (if (imported_option_helpers_ok)
    42
    1))

(test "explicit std option i32 observation"
  (imported_option_i32_observation_ok))

(test "explicit std option i32 unwrap_some"
  (= (imported_option_i32_unwrap_some_score) 42))

(test "explicit std option i32 unwrap_or"
  (= (imported_option_i32_unwrap_or_score) 42))

(test "explicit std option i32 some_or_err ok"
  (imported_option_i32_some_or_err_ok))

(test "explicit std option i32 some_or_err err"
  (imported_option_i32_some_or_err_err))

(test "explicit std option u32 observation"
  (imported_option_u32_observation_ok))

(test "explicit std option u32 unwrap_some"
  (= (imported_option_u32_unwrap_some_score) 42u32))

(test "explicit std option u32 unwrap_or"
  (= (imported_option_u32_unwrap_or_score) 42u32))

(test "explicit std option u32 some_or_err ok"
  (imported_option_u32_some_or_err_ok))

(test "explicit std option u32 some_or_err err"
  (imported_option_u32_some_or_err_err))

(test "explicit std option i64 observation"
  (imported_option_i64_observation_ok))

(test "explicit std option i64 unwrap_some"
  (= (imported_option_i64_unwrap_some_score) 2147483660i64))

(test "explicit std option i64 unwrap_or"
  (= (imported_option_i64_unwrap_or_score) 42i64))

(test "explicit std option i64 some_or_err ok"
  (imported_option_i64_some_or_err_ok))

(test "explicit std option i64 some_or_err err"
  (imported_option_i64_some_or_err_err))

(test "explicit std option u64 observation"
  (imported_option_u64_observation_ok))

(test "explicit std option u64 unwrap_some"
  (= (imported_option_u64_unwrap_some_score) 4294967308u64))

(test "explicit std option u64 unwrap_or"
  (= (imported_option_u64_unwrap_or_score) 42u64))

(test "explicit std option u64 some_or_err ok"
  (imported_option_u64_some_or_err_ok))

(test "explicit std option u64 some_or_err err"
  (imported_option_u64_some_or_err_err))

(test "explicit std option f64 observation"
  (imported_option_f64_observation_ok))

(test "explicit std option f64 unwrap_some"
  (= (imported_option_f64_unwrap_some_score) 42.0))

(test "explicit std option f64 unwrap_or"
  (= (imported_option_f64_unwrap_or_score) 42.0))

(test "explicit std option f64 some_or_err ok"
  (imported_option_f64_some_or_err_ok))

(test "explicit std option f64 some_or_err err"
  (imported_option_f64_some_or_err_err))

(test "explicit std option bool observation"
  (imported_option_bool_observation_ok))

(test "explicit std option bool unwrap_some"
  (imported_option_bool_unwrap_some_ok))

(test "explicit std option bool unwrap_or"
  (imported_option_bool_unwrap_or_ok))

(test "explicit std option bool some_or_err ok"
  (imported_option_bool_some_or_err_ok))

(test "explicit std option bool some_or_err err"
  (imported_option_bool_some_or_err_err))

(test "explicit std option string observation"
  (imported_option_string_observation_ok))

(test "explicit std option string unwrap_some"
  (imported_option_string_unwrap_some_ok))

(test "explicit std option string unwrap_or"
  (imported_option_string_unwrap_or_ok))

(test "explicit std option string some_or_err ok"
  (imported_option_string_some_or_err_ok))

(test "explicit std option string some_or_err err"
  (imported_option_string_some_or_err_err))

(test "explicit std option helpers all"
  (= (main) 42))
