| 1 | -module(hope_kv_list_SUITE). |
| 2 | |
| 3 | -include_lib("hope_kv_list.hrl"). |
| 4 | |
| 5 | %% Callbacks |
| 6 | -export( |
| 7 | [ all/0 |
| 8 | , groups/0 |
| 9 | ]). |
| 10 | |
| 11 | %% Test cases |
| 12 | -export( |
| 13 | [ t_validate_unique_presence/1 |
| 14 | ]). |
| 15 | |
| 16 | |
| 17 | -define(GROUP , hope_kv_list). |
| 18 | |
| 19 | |
| 20 | %% ============================================================================ |
| 21 | %% Common Test callbacks |
| 22 | %% ============================================================================ |
| 23 | |
| 24 | all() -> |
| 25 | [{group, ?GROUP}]. |
| 26 | |
| 27 | groups() -> |
| 28 | Tests = |
| 29 | [ t_validate_unique_presence |
| 30 | ], |
| 31 | Properties = [], |
| 32 | [{?GROUP, Properties, Tests}]. |
| 33 | |
| 34 | |
| 35 | %% ============================================================================= |
| 36 | %% Test cases |
| 37 | %% ============================================================================= |
| 38 | |
| 39 | t_validate_unique_presence(_Cfg) -> |
| 40 | KeysRequired = [a, b, c], |
| 41 | DictOk = [{a, 1}, {b, 2}, {c, 3}], |
| 42 | DictUnsup = [{a, 1}, {b, 2}, {c, 3}, {d, 4}], |
| 43 | DictDups = [{a, 1}, {b, 2}, {c, 3}, {a, 4}], |
| 44 | DictMissing = [{a, 1}, {b, 2}], |
| 45 | |
| 46 | {ok, DictOk} = |
| 47 | hope_kv_list:validate_unique_presence(DictOk, KeysRequired), |
| 48 | #hope_kv_list_presence_violations |
| 49 | { keys_missing = [] |
| 50 | , keys_duplicated = [] |
| 51 | , keys_unsupported = [] |
| 52 | } = |
| 53 | hope_kv_list:find_unique_presence_violations(DictOk, KeysRequired), |
| 54 | |
| 55 | {error, [{keys_unsupported, [d]}]} = |
| 56 | hope_kv_list:validate_unique_presence(DictUnsup, KeysRequired), |
| 57 | #hope_kv_list_presence_violations |
| 58 | { keys_missing = [] |
| 59 | , keys_duplicated = [] |
| 60 | , keys_unsupported = [d] |
| 61 | } = |
| 62 | hope_kv_list:find_unique_presence_violations(DictUnsup, KeysRequired), |
| 63 | |
| 64 | {error, [{keys_duplicated, [a]}]} = |
| 65 | hope_kv_list:validate_unique_presence(DictDups, KeysRequired), |
| 66 | #hope_kv_list_presence_violations |
| 67 | { keys_missing = [] |
| 68 | , keys_duplicated = [a] |
| 69 | , keys_unsupported = [] |
| 70 | } = |
| 71 | hope_kv_list:find_unique_presence_violations(DictDups, KeysRequired), |
| 72 | |
| 73 | {error, [{keys_missing, [c]}]} = |
| 74 | hope_kv_list:validate_unique_presence(DictMissing, KeysRequired), |
| 75 | #hope_kv_list_presence_violations |
| 76 | { keys_missing = [c] |
| 77 | , keys_duplicated = [] |
| 78 | , keys_unsupported = [] |
| 79 | } = |
| 80 | hope_kv_list:find_unique_presence_violations(DictMissing, KeysRequired). |