1 -module(hope_result_SUITE).
15 , t_hope_result_specs/1
24 -define(GROUP_PIPE, result_pipe).
25 -define(GROUP_SPEC, result_spec).
26 -define(GROUP_LIFT, result_lift_exn).
27 -define(GROUP_OTHER, result_other).
30 %% ============================================================================
31 %% Common Test callbacks
32 %% ============================================================================
35 [ {group, ?GROUP_PIPE}
36 , {group, ?GROUP_SPEC}
37 , {group, ?GROUP_LIFT}
38 , {group, ?GROUP_OTHER}
58 Properties = [parallel],
59 [ {?GROUP_PIPE, Properties, PipeTests}
60 , {?GROUP_SPEC, Properties, SpecTests}
61 , {?GROUP_LIFT, Properties, LiftTests}
62 , {?GROUP_OTHER, Properties, OtherTests}
65 init_per_group(?GROUP_PIPE, Cfg) ->
67 [ fun (0) -> {ok, 1}; (X) -> {error, X} end
68 , fun (1) -> {ok, 2}; (X) -> {error, X} end
69 , fun (2) -> {ok, 3}; (X) -> {error, X} end
71 hope_kv_list:set(Cfg, steps, Steps);
72 init_per_group(_, Cfg) ->
75 end_per_group(_, _Cfg) ->
79 %% =============================================================================
81 %% =============================================================================
84 {some, Steps} = hope_kv_list:get(Cfg, steps),
85 {ok, 3} = hope_result:pipe(Steps, 0).
88 {some, Steps} = hope_kv_list:get(Cfg, steps),
89 {error, 1} = hope_result:pipe(Steps, 1).
91 t_hope_result_specs(_) ->
92 [] = proper:check_specs(hope_result).
98 F = fun (ok) -> apply(erlang, Class, [Reason]) end,
99 G = hope_result:lift_exn(F),
100 H = hope_result:lift_exn(F, Label),
101 {error, {Class, Reason}} = G(ok),
102 {error, {Label, {Class, Reason}}} = H(ok).
106 {ok, X} = hope_result:return(X).
111 F = fun (foo) -> Y end,
112 {ok, Y} = hope_result:map({ok, X}, F),
113 {error, X} = hope_result:map({error, X}, F).
118 XtoY = fun (foo) -> Y end,
119 {ok , X} = hope_result:map_error({ok , X}, XtoY),
120 {error, Y} = hope_result:map_error({error, X}, XtoY).
125 {ok , X } = hope_result:tag_error({ok , X}, Tag),
126 {error, {Tag, X}} = hope_result:tag_error({error, X}, Tag).