-module(mockth). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([unload_all/0, mocked/0, validate/1, unload/1, expect0/3, expect1/3, expect2/3, expect3/3, expect4/3, expect5/3]). -spec module_atoms_to_strings(list(gleam@erlang@atom:atom_())) -> list(binary()). module_atoms_to_strings(Module_atoms) -> _pipe = Module_atoms, _pipe@1 = gleam@list:map(_pipe, fun erlang:atom_to_binary/1), gleam@list:map( _pipe@1, fun(_capture) -> gleam@string:replace(_capture, <<"@"/utf8>>, <<"/"/utf8>>) end ). -spec unload_all() -> list(binary()). unload_all() -> _pipe = meck:unload(), module_atoms_to_strings(_pipe). -spec mocked() -> list(binary()). mocked() -> _pipe = meck:mocked(), module_atoms_to_strings(_pipe). -spec is_ok_atom(gleam@erlang@atom:atom_()) -> {ok, boolean()} | {error, binary()}. is_ok_atom(A) -> Ok = gleam_erlang_ffi:atom_from_string(<<"ok"/utf8>>), case Ok of {ok, Ok@1} -> case Ok@1 =:= A of true -> {ok, true}; false -> {error, <<"Failed to expect"/utf8>>} end; {error, _} -> {error, <<"Failed to expect"/utf8>>} end. -spec to_function_atom(binary()) -> {ok, gleam@erlang@atom:atom_()} | {error, binary()}. to_function_atom(Function) -> _pipe = gleam_erlang_ffi:atom_from_string(Function), gleam@result:map_error( _pipe, fun(_) -> <<"Failed to find function "/utf8, Function/binary>> end ). -spec to_module_atom(binary()) -> {ok, gleam@erlang@atom:atom_()} | {error, binary()}. to_module_atom(Module) -> Module@1 = gleam@string:replace(Module, <<"/"/utf8>>, <<"@"/utf8>>), _pipe = gleam_erlang_ffi:atom_from_string(Module@1), gleam@result:map_error( _pipe, fun(_) -> <<"Failed to find module "/utf8, Module@1/binary>> end ). -spec validate(binary()) -> boolean(). validate(Module) -> case to_module_atom(Module) of {ok, Module@1} -> meck:validate(Module@1); {error, _} -> false end. -spec unload(binary()) -> {ok, boolean()} | {error, binary()}. unload(Module) -> _pipe = Module, _pipe@1 = to_module_atom(_pipe), gleam@result:then(_pipe@1, fun(Module@1) -> _pipe@2 = meck:unload(Module@1), is_ok_atom(_pipe@2) end). -spec load_expect_atoms(binary(), binary()) -> {ok, {gleam@erlang@atom:atom_(), gleam@erlang@atom:atom_()}} | {error, binary()}. load_expect_atoms(Module, Function) -> _pipe = to_module_atom(Module), gleam@result:then( _pipe, fun(Module@1) -> _pipe@1 = to_function_atom(Function), gleam@result:map( _pipe@1, fun(Function@1) -> {Module@1, Function@1} end ) end ). -spec expect0(binary(), binary(), fun(() -> any())) -> {ok, boolean()} | {error, binary()}. expect0(Module, Function, Fun) -> gleam@result:then( load_expect_atoms(Module, Function), fun(_use0) -> {Module@1, Function@1} = _use0, _pipe = meck:expect(Module@1, Function@1, Fun), is_ok_atom(_pipe) end ). -spec expect1(binary(), binary(), fun((any()) -> any())) -> {ok, boolean()} | {error, binary()}. expect1(Module, Function, Fun) -> gleam@result:then( load_expect_atoms(Module, Function), fun(_use0) -> {Module@1, Function@1} = _use0, _pipe = meck:expect(Module@1, Function@1, Fun), is_ok_atom(_pipe) end ). -spec expect2(binary(), binary(), fun((any(), any()) -> any())) -> {ok, boolean()} | {error, binary()}. expect2(Module, Function, Fun) -> gleam@result:then( load_expect_atoms(Module, Function), fun(_use0) -> {Module@1, Function@1} = _use0, _pipe = meck:expect(Module@1, Function@1, Fun), is_ok_atom(_pipe) end ). -spec expect3(binary(), binary(), fun((any(), any(), any()) -> any())) -> {ok, boolean()} | {error, binary()}. expect3(Module, Function, Fun) -> gleam@result:then( load_expect_atoms(Module, Function), fun(_use0) -> {Module@1, Function@1} = _use0, _pipe = meck:expect(Module@1, Function@1, Fun), is_ok_atom(_pipe) end ). -spec expect4(binary(), binary(), fun((any(), any(), any(), any()) -> any())) -> {ok, boolean()} | {error, binary()}. expect4(Module, Function, Fun) -> gleam@result:then( load_expect_atoms(Module, Function), fun(_use0) -> {Module@1, Function@1} = _use0, _pipe = meck:expect(Module@1, Function@1, Fun), is_ok_atom(_pipe) end ). -spec expect5( binary(), binary(), fun((any(), any(), any(), any(), any()) -> any()) ) -> {ok, boolean()} | {error, binary()}. expect5(Module, Function, Fun) -> gleam@result:then( load_expect_atoms(Module, Function), fun(_use0) -> {Module@1, Function@1} = _use0, _pipe = meck:expect(Module@1, Function@1, Fun), is_ok_atom(_pipe) end ).