1 -module(hope_option_SUITE).
22 -define(GROUP, option).
25 %% ============================================================================
26 %% Common Test callbacks
27 %% ============================================================================
44 Properties = [parallel],
45 [ {?GROUP, Properties, Tests}
49 %% =============================================================================
51 %% =============================================================================
54 IsFoo = fun (foo) -> true; (_) -> false end,
55 {some, foo} = hope_option:put(foo, IsFoo),
56 none = hope_option:put(bar, IsFoo).
59 foo = hope_option:get({some, foo}, bar),
60 bar = hope_option:get(none , bar).
63 FooToBar = fun (foo) -> bar end,
64 {some, bar} = hope_option:map({some, foo}, FooToBar),
65 none = hope_option:map(none , FooToBar).
69 Put = fun (Val) -> _ = put(Key, Val), ok end,
70 Get = fun () -> get(Key) end,
72 ok = hope_option:iter(none , Put),
74 ok = hope_option:iter({some, Val}, Put),
81 ResultError = {error, Bar},
82 {some, Foo} = hope_option:of_result(ResultOk),
83 none = hope_option:of_result(ResultError).
87 [ fun (0) -> hope_option:return(1); (_) -> none end
88 , fun (1) -> hope_option:return(2); (_) -> none end
89 , fun (2) -> hope_option:return(3); (_) -> none end
91 {some, 3} = hope_option:pipe(Steps, 0),
92 none = hope_option:pipe(Steps, 1),
93 none = hope_option:pipe(Steps, 2),
94 none = hope_option:pipe(Steps, 3).
96 t_of_undefined(_Cfg) ->
100 {some, Foo} = hope_option:of_undefined(Foo),
101 {some, Bar} = hope_option:of_undefined(Bar),
102 {some, Baz} = hope_option:of_undefined(Baz),
103 none = hope_option:of_undefined(undefined).
106 IsFoo = fun (X) -> X =:= foo end,
107 none = hope_option:validate(none, IsFoo),
108 none = hope_option:validate({some, bar}, IsFoo),
109 {some, foo} = hope_option:validate({some, foo}, IsFoo).