aboutsummaryrefslogtreecommitdiff
path: root/test/proplutils_test.erl
blob: c14c84b225e301a824132c38e80a6df247d804fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
-module(proplutils_test).
-include_lib("eunit/include/eunit.hrl").

% Test descriptions
delete_test_() ->
    [{"Using a atom should work as proplist:delete/2",
      check_delete_atom_arg()},
     {"Using a list should remove all keys in the list",
      check_delete_list_arg()}
    ].

delete_except_test_() ->
    [{"Using an atom should remove everything except keys"
      "matching that atom",
      check_delete_except_atom_arg()},
     {"Using a list should remove all keys except keys"
      "matching the atoms in the list",
      check_delete_except_list_arg()}
    ].

% Tests
check_delete_atom_arg() ->
    PL = [{foo, "doesnot"}, {bar, "matter"}],
    Ret = proplutils:delete(foo, PL),
    [?_assertEqual(Ret, [{bar, "matter"}])].

check_delete_list_arg() ->
    PL = [{foo, "doesnot"}, {bar, "matter"}, {baz, "really"}],
    Ret = proplutils:delete([foo, baz], PL),
    [?_assertEqual(Ret, [{bar, "matter"}])].

check_delete_except_atom_arg() ->
    PL = [{foo, "doesnot"}, {bar, "matter"}, {baz, "really"}],
    Ret = proplutils:delete_except(bar, PL),
    [?_assertEqual(Ret, [{bar, "matter"}])].

check_delete_except_list_arg() ->
    PL = [{foo, "doesnot"}, {bar, "matter"}, {baz, "really"}],
    Ret = proplutils:delete_except([foo, bar], PL),
    [?_assertEqual(Ret,[{foo, "doesnot"}, {bar, "matter"}])].