Skip to content

Commit

Permalink
Moved ec_cnv tests into separate file
Browse files Browse the repository at this point in the history
Signed-off-by: Ariel Otilibili <[email protected]>
  • Loading branch information
Ariel Otilibili committed Aug 3, 2024
1 parent ead8381 commit dc68ede
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 33 deletions.
33 changes: 0 additions & 33 deletions src/ec_cnv.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
28 changes: 28 additions & 0 deletions test/ec_cnv_tests.erl
Original file line number Diff line number Diff line change
@@ -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)).

0 comments on commit dc68ede

Please sign in to comment.