Make hope_kv_list tests generic for any dictionary.
[hope.git] / test / hope_kv_list_SUITE.erl
1 -module(hope_kv_list_SUITE).
2
3 %% Callbacks
4 -export(
5 [ all/0
6 , groups/0
7 , init_per_group/2
8 , end_per_group/2
9 ]).
10
11 %% Test cases
12 -export(
13 [ t_set_new/1
14 , t_set_existing/1
15 , t_pop/1
16 ]).
17
18
19 -define(DICT_MODULE , dict_module).
20 -define(DICT_MODULE_KV_LIST , hope_kv_list).
21
22
23 %% ============================================================================
24 %% Common Test callbacks
25 %% ============================================================================
26
27 all() ->
28 [{group, ?DICT_MODULE_KV_LIST}].
29
30 groups() ->
31 Tests =
32 [ t_set_new
33 , t_set_existing
34 , t_pop
35 ],
36 Properties = [],
37 [{?DICT_MODULE_KV_LIST, Properties, Tests}].
38
39 init_per_group(DictModule, Cfg) ->
40 hope_kv_list:set(Cfg, ?DICT_MODULE, DictModule).
41
42 end_per_group(_DictModule, _Cfg) ->
43 ok.
44
45
46 %% =============================================================================
47 %% Test cases
48 %% =============================================================================
49
50 t_set_new(Cfg) ->
51 {some, DictModule} = hope_kv_list:get(Cfg, ?DICT_MODULE),
52 Key = key,
53 ValExpected = bar,
54 ListInitial = DictModule:empty(),
55 ListResulting = DictModule:set(ListInitial, Key, ValExpected),
56 {some, ValResulting} = DictModule:get(ListResulting, Key),
57 ValResulting = ValExpected.
58
59 t_set_existing(Cfg) ->
60 {some, DictModule} = hope_kv_list:get(Cfg, ?DICT_MODULE),
61 Key = key,
62 ValInitial = foo,
63 ValExpected = bar,
64 ListInitial = [{donald, duck}, {Key, ValInitial}],
65 ListResulting = DictModule:set(ListInitial, Key, ValExpected),
66 {some, ValResulting} = DictModule:get(ListResulting, Key),
67 ValResulting = ValExpected.
68
69 t_pop(Cfg) ->
70 {some, DictModule} = hope_kv_list:get(Cfg, ?DICT_MODULE),
71 KVList = [{a, 1}, {b, 2}, {c, 3}],
72 Dict1 = DictModule:of_kv_list(KVList),
73 {{some, 1} , Dict2} = DictModule:pop(Dict1, a),
74 {none , Dict3} = DictModule:pop(Dict2, a),
75 {{some, 2} , Dict4} = DictModule:pop(Dict3, b),
76 {none , Dict5} = DictModule:pop(Dict4, b),
77 {{some, 3} , Dict6} = DictModule:pop(Dict5, c),
78 {none , Dict7} = DictModule:pop(Dict6, c),
79 [] = DictModule:to_kv_list(Dict7).
This page took 0.0449 seconds and 4 git commands to generate.