-t_set_new(Cfg) ->
- {some, DictModule} = hope_kv_list:get(Cfg, ?DICT_MODULE),
- Key = key,
- ValExpected = bar,
- ListInitial = DictModule:empty(),
- ListResulting = DictModule:set(ListInitial, Key, ValExpected),
- {some, ValResulting} = DictModule:get(ListResulting, Key),
- ValResulting = ValExpected.
-
-t_set_existing(Cfg) ->
- {some, DictModule} = hope_kv_list:get(Cfg, ?DICT_MODULE),
- Key = key,
- ValInitial = foo,
- ValExpected = bar,
- ListInitial = [{donald, duck}, {Key, ValInitial}],
- ListResulting = DictModule:set(ListInitial, Key, ValExpected),
- {some, ValResulting} = DictModule:get(ListResulting, Key),
- ValResulting = ValExpected.
-
-t_pop(Cfg) ->
- {some, DictModule} = hope_kv_list:get(Cfg, ?DICT_MODULE),
- KVList = [{a, 1}, {b, 2}, {c, 3}],
- Dict1 = DictModule:of_kv_list(KVList),
- {{some, 1} , Dict2} = DictModule:pop(Dict1, a),
- {none , Dict3} = DictModule:pop(Dict2, a),
- {{some, 2} , Dict4} = DictModule:pop(Dict3, b),
- {none , Dict5} = DictModule:pop(Dict4, b),
- {{some, 3} , Dict6} = DictModule:pop(Dict5, c),
- {none , Dict7} = DictModule:pop(Dict6, c),
- [] = DictModule:to_kv_list(Dict7).
+t_validate_unique_presence(_Cfg) ->
+ KeysRequired = [a, b, c],
+ DictOk = [{a, 1}, {b, 2}, {c, 3}],
+ DictUnsup = [{a, 1}, {b, 2}, {c, 3}, {d, 4}],
+ DictDups = [{a, 1}, {b, 2}, {c, 3}, {a, 4}],
+ DictMissing = [{a, 1}, {b, 2}],
+
+ {ok, DictOk} =
+ hope_kv_list:validate_unique_presence(DictOk, KeysRequired),
+ #hope_kv_list_presence_violations
+ { keys_missing = []
+ , keys_duplicated = []
+ , keys_unsupported = []
+ } =
+ hope_kv_list:find_unique_presence_violations(DictOk, KeysRequired),
+
+ {error, [{keys_unsupported, [d]}]} =
+ hope_kv_list:validate_unique_presence(DictUnsup, KeysRequired),
+ #hope_kv_list_presence_violations
+ { keys_missing = []
+ , keys_duplicated = []
+ , keys_unsupported = [d]
+ } =
+ hope_kv_list:find_unique_presence_violations(DictUnsup, KeysRequired),
+
+ {error, [{keys_duplicated, [a]}]} =
+ hope_kv_list:validate_unique_presence(DictDups, KeysRequired),
+ #hope_kv_list_presence_violations
+ { keys_missing = []
+ , keys_duplicated = [a]
+ , keys_unsupported = []
+ } =
+ hope_kv_list:find_unique_presence_violations(DictDups, KeysRequired),
+
+ {error, [{keys_missing, [c]}]} =
+ hope_kv_list:validate_unique_presence(DictMissing, KeysRequired),
+ #hope_kv_list_presence_violations
+ { keys_missing = [c]
+ , keys_duplicated = []
+ , keys_unsupported = []
+ } =
+ hope_kv_list:find_unique_presence_violations(DictMissing, KeysRequired).