X-Git-Url: https://git.xandkar.net/?a=blobdiff_plain;f=test%2Fhope_option_SUITE.erl;h=d2a73a31eda9fdef61c327dfb6955565ecfecc53;hb=4744fed98ce752dde11c03aeaf8d90983efe5ea6;hp=2b3dab0005f073efe0d165270a2ca56b3b688281;hpb=2dc71691ff8d7494f80a2af26994c186779d6898;p=hope.git diff --git a/test/hope_option_SUITE.erl b/test/hope_option_SUITE.erl index 2b3dab0..d2a73a3 100644 --- a/test/hope_option_SUITE.erl +++ b/test/hope_option_SUITE.erl @@ -9,10 +9,13 @@ %% Test cases -export( [ t_of_result/1 + , t_of_undefined/1 , t_put/1 , t_get/1 , t_map/1 , t_iter/1 + , t_pipe/1 + , t_validate/1 ]). @@ -30,10 +33,13 @@ all() -> groups() -> Tests = [ t_of_result + , t_of_undefined , t_put , t_get , t_map , t_iter + , t_pipe + , t_validate ], Properties = [parallel], [ {?GROUP, Properties, Tests} @@ -60,12 +66,12 @@ t_map(_Cfg) -> t_iter(_Cfg) -> Key = key, - Put = fun (Val) -> _ = put(Key, Val), ok end, + Put = fun (Val) -> put(Key, Val) end, Get = fun () -> get(Key) end, Val = foo, - ok = hope_option:iter(none , Put), + {} = hope_option:iter(none , Put), undefined = Get(), - ok = hope_option:iter({some, Val}, Put), + {} = hope_option:iter({some, Val}, Put), Val = Get(). t_of_result(_Cfg) -> @@ -75,3 +81,29 @@ t_of_result(_Cfg) -> ResultError = {error, Bar}, {some, Foo} = hope_option:of_result(ResultOk), none = hope_option:of_result(ResultError). + +t_pipe(_Cfg) -> + Steps = + [ fun (0) -> hope_option:return(1); (_) -> none end + , fun (1) -> hope_option:return(2); (_) -> none end + , fun (2) -> hope_option:return(3); (_) -> none end + ], + {some, 3} = hope_option:pipe(Steps, 0), + none = hope_option:pipe(Steps, 1), + none = hope_option:pipe(Steps, 2), + none = hope_option:pipe(Steps, 3). + +t_of_undefined(_Cfg) -> + Foo = foo, + Bar = bar, + Baz = baz, + {some, Foo} = hope_option:of_undefined(Foo), + {some, Bar} = hope_option:of_undefined(Bar), + {some, Baz} = hope_option:of_undefined(Baz), + none = hope_option:of_undefined(undefined). + +t_validate(_Cfg) -> + IsFoo = fun (X) -> X =:= foo end, + none = hope_option:validate(none, IsFoo), + none = hope_option:validate({some, bar}, IsFoo), + {some, foo} = hope_option:validate({some, foo}, IsFoo).