diff --git a/src/ec_cnv.erl b/src/ec_cnv.erl index 72700fb..bc3b3f3 100644 --- a/src/ec_cnv.erl +++ b/src/ec_cnv.erl @@ -212,36 +212,3 @@ to_atom(X) erlang:list_to_existing_atom(X); to_atom(X) -> to_atom(to_list(X)). - -%%%=================================================================== -%%% Tests -%%%=================================================================== - --ifdef(TEST). --include_lib("eunit/include/eunit.hrl"). - -to_integer_test() -> - ?assertError(badarg, to_integer(1.5, strict)). - -to_float_test() -> - ?assertError(badarg, to_float(10, strict)). - -to_atom_test() -> - ?assertMatch(true, to_atom("true")), - ?assertMatch(true, to_atom(<<"true">>)), - ?assertMatch(false, to_atom(<<"false">>)), - ?assertMatch(false, to_atom(false)), - ?assertError(badarg, to_atom("hello_foo_bar_baz")), - - S = erlang:list_to_atom("1"), - ?assertMatch(S, to_atom(1)). - -to_boolean_test()-> - ?assertMatch(true, to_boolean(<<"true">>)), - ?assertMatch(true, to_boolean("true")), - ?assertMatch(true, to_boolean(true)), - ?assertMatch(false, to_boolean(<<"false">>)), - ?assertMatch(false, to_boolean("false")), - ?assertMatch(false, to_boolean(false)). - --endif. diff --git a/test/ec_cnv_tests.erl b/test/ec_cnv_tests.erl new file mode 100644 index 0000000..6bbad6e --- /dev/null +++ b/test/ec_cnv_tests.erl @@ -0,0 +1,28 @@ +%%% @copyright 2024 Erlware, LLC. +-module(ec_cnv_tests). + +-include_lib("eunit/include/eunit.hrl"). + +to_integer_test() -> + ?assertError(badarg, ec_cnv:to_integer(1.5, strict)). + +to_float_test() -> + ?assertError(badarg, ec_cnv:to_float(10, strict)). + +to_atom_test() -> + ?assertMatch(true, ec_cnv:to_atom("true")), + ?assertMatch(true, ec_cnv:to_atom(<<"true">>)), + ?assertMatch(false, ec_cnv:to_atom(<<"false">>)), + ?assertMatch(false, ec_cnv:to_atom(false)), + ?assertError(badarg, ec_cnv:to_atom("hello_foo_bar_baz")), + + S = erlang:list_to_atom("1"), + ?assertMatch(S, ec_cnv:to_atom(1)). + +to_boolean_test()-> + ?assertMatch(true, ec_cnv:to_boolean(<<"true">>)), + ?assertMatch(true, ec_cnv:to_boolean("true")), + ?assertMatch(true, ec_cnv:to_boolean(true)), + ?assertMatch(false, ec_cnv:to_boolean(<<"false">>)), + ?assertMatch(false, ec_cnv:to_boolean("false")), + ?assertMatch(false, ec_cnv:to_boolean(false)).