(module main)

(import std.net (tcp_connect_loopback_result tcp_listen_loopback_result tcp_bound_port_result tcp_accept_result tcp_read_all_result tcp_write_text_result tcp_close_result tcp_write_text_ok tcp_close_ok))

(fn i32_err_one ((value (result i32 i32))) -> bool
  (match value
    ((ok payload)
      false)
    ((err code)
      (= code 1))))

(fn string_err_one ((value (result string i32))) -> bool
  (match value
    ((ok payload)
      false)
    ((err code)
      (= code 1))))

(fn imported_connect_invalid_port_err () -> bool
  (i32_err_one (tcp_connect_loopback_result 0)))

(fn imported_listen_invalid_port_err () -> bool
  (i32_err_one (tcp_listen_loopback_result -1)))

(fn imported_bound_port_invalid_handle_err () -> bool
  (i32_err_one (tcp_bound_port_result -1)))

(fn imported_accept_invalid_listener_err () -> bool
  (i32_err_one (tcp_accept_result -1)))

(fn imported_read_invalid_handle_err () -> bool
  (string_err_one (tcp_read_all_result -1)))

(fn imported_write_invalid_handle_err () -> bool
  (i32_err_one (tcp_write_text_result -1 "ping")))

(fn imported_close_invalid_handle_err () -> bool
  (i32_err_one (tcp_close_result -1)))

(fn imported_helper_invalids_false () -> bool
  (if (tcp_write_text_ok -1 "ping")
    false
    (if (tcp_close_ok -1)
      false
      true)))

(fn imported_invalid_paths_ok () -> bool
  (if (imported_connect_invalid_port_err)
    (if (imported_listen_invalid_port_err)
      (if (imported_bound_port_invalid_handle_err)
        (if (imported_accept_invalid_listener_err)
          (if (imported_read_invalid_handle_err)
            (if (imported_write_invalid_handle_err)
              (if (imported_close_invalid_handle_err)
                (imported_helper_invalids_false)
                false)
              false)
            false)
          false)
        false)
      false)
    false))

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

(test "explicit std net invalid connect facade"
  (imported_connect_invalid_port_err))

(test "explicit std net invalid listen facade"
  (imported_listen_invalid_port_err))

(test "explicit std net invalid bound port facade"
  (imported_bound_port_invalid_handle_err))

(test "explicit std net invalid accept facade"
  (imported_accept_invalid_listener_err))

(test "explicit std net invalid read facade"
  (imported_read_invalid_handle_err))

(test "explicit std net invalid write facade"
  (imported_write_invalid_handle_err))

(test "explicit std net invalid close facade"
  (imported_close_invalid_handle_err))

(test "explicit std net helper invalids facade"
  (imported_helper_invalids_false))

(test "explicit std net facade all"
  (= (main) 42))
