X-Git-Url: https://git.xandkar.net/?a=blobdiff_plain;f=test%2Fhope_result_SUITE.erl;h=9e60e855683b46065e26248d308caeec3009eeb4;hb=ff793acf03456b6bd4c12ea330a9311f7e94cc77;hp=9587345099ebc34521933ef37b2cbd0bc0e5ddf7;hpb=371e63336e774865c4746b0a9a849eb44f10f98a;p=hope.git diff --git a/test/hope_result_SUITE.erl b/test/hope_result_SUITE.erl index 9587345..9e60e85 100644 --- a/test/hope_result_SUITE.erl +++ b/test/hope_result_SUITE.erl @@ -17,12 +17,15 @@ , t_pipe_error/1 , t_hope_result_specs/1 , t_lift_exn/1 + , t_return/1 + , t_map/1 ]). -define(GROUP_PIPE, result_pipe). -define(GROUP_SPEC, result_spec). -define(GROUP_LIFT, result_lift_exn). +-define(GROUP_OTHER, result_other). %% ============================================================================ @@ -33,6 +36,7 @@ all() -> [ {group, ?GROUP_PIPE} , {group, ?GROUP_SPEC} , {group, ?GROUP_LIFT} + , {group, ?GROUP_OTHER} ]. groups() -> @@ -46,29 +50,28 @@ groups() -> LiftTests = [ t_lift_exn ], + OtherTests = + [ t_return + , t_map + ], Properties = [parallel], [ {?GROUP_PIPE, Properties, PipeTests} , {?GROUP_SPEC, Properties, SpecTests} , {?GROUP_LIFT, Properties, LiftTests} + , {?GROUP_OTHER, Properties, OtherTests} ]. -init_per_group(?GROUP_LIFT, Cfg) -> - Cfg; -init_per_group(?GROUP_SPEC, Cfg) -> - Cfg; init_per_group(?GROUP_PIPE, Cfg) -> Steps = [ fun (0) -> {ok, 1}; (X) -> {error, X} end , fun (1) -> {ok, 2}; (X) -> {error, X} end , fun (2) -> {ok, 3}; (X) -> {error, X} end ], - hope_kv_list:set(Cfg, steps, Steps). + hope_kv_list:set(Cfg, steps, Steps); +init_per_group(_, Cfg) -> + Cfg. -end_per_group(?GROUP_LIFT, _Cfg) -> - ok; -end_per_group(?GROUP_SPEC, _Cfg) -> - ok; -end_per_group(?GROUP_PIPE, _Cfg) -> +end_per_group(_, _Cfg) -> ok. @@ -90,6 +93,20 @@ t_hope_result_specs(_) -> t_lift_exn(_Cfg) -> Class = throw, Reason = foofoo, + Label = bar, F = fun (ok) -> apply(erlang, Class, [Reason]) end, G = hope_result:lift_exn(F), - {error, {Class, Reason}} = G(ok). + H = hope_result:lift_exn(F, Label), + {error, {Class, Reason}} = G(ok), + {error, {Label, {Class, Reason}}} = H(ok). + +t_return(_Cfg) -> + X = foo, + {ok, X} = hope_result:return(X). + +t_map(_Cfg) -> + X = foo, + Y = bar, + F = fun (foo) -> Y end, + {ok, Y} = hope_result:map({ok, X}, F), + {error, X} = hope_result:map({error, X}, F).