Expose setting recursion limit in the API.
[hope.git] / test / hope_option_SUITE.erl
CommitLineData
2dc71691
SK
1-module(hope_option_SUITE).
2
3%% Callbacks
4-export(
5 [ all/0
6 , groups/0
7 ]).
8
9%% Test cases
10-export(
11 [ t_of_result/1
12 , t_put/1
13 , t_get/1
14 , t_map/1
15 , t_iter/1
4af0774b 16 , t_pipe/1
2dc71691
SK
17 ]).
18
19
20-define(GROUP, option).
21
22
23%% ============================================================================
24%% Common Test callbacks
25%% ============================================================================
26
27all() ->
28 [ {group, ?GROUP}
29 ].
30
31groups() ->
32 Tests =
33 [ t_of_result
34 , t_put
35 , t_get
36 , t_map
37 , t_iter
4af0774b 38 , t_pipe
2dc71691
SK
39 ],
40 Properties = [parallel],
41 [ {?GROUP, Properties, Tests}
42 ].
43
44
45%% =============================================================================
46%% Test cases
47%% =============================================================================
48
49t_put(_Cfg) ->
50 IsFoo = fun (foo) -> true; (_) -> false end,
51 {some, foo} = hope_option:put(foo, IsFoo),
52 none = hope_option:put(bar, IsFoo).
53
54t_get(_Cfg) ->
55 foo = hope_option:get({some, foo}, bar),
56 bar = hope_option:get(none , bar).
57
58t_map(_Cfg) ->
59 FooToBar = fun (foo) -> bar end,
60 {some, bar} = hope_option:map({some, foo}, FooToBar),
61 none = hope_option:map(none , FooToBar).
62
63t_iter(_Cfg) ->
64 Key = key,
65 Put = fun (Val) -> _ = put(Key, Val), ok end,
66 Get = fun () -> get(Key) end,
67 Val = foo,
68 ok = hope_option:iter(none , Put),
69 undefined = Get(),
70 ok = hope_option:iter({some, Val}, Put),
71 Val = Get().
72
73t_of_result(_Cfg) ->
74 Foo = foo,
75 Bar = bar,
76 ResultOk = {ok, Foo},
77 ResultError = {error, Bar},
78 {some, Foo} = hope_option:of_result(ResultOk),
79 none = hope_option:of_result(ResultError).
4af0774b
SK
80
81t_pipe(_Cfg) ->
82 Steps =
83 [ fun (0) -> hope_option:return(1); (_) -> none end
84 , fun (1) -> hope_option:return(2); (_) -> none end
85 , fun (2) -> hope_option:return(3); (_) -> none end
86 ],
87 {some, 3} = hope_option:pipe(Steps, 0),
88 none = hope_option:pipe(Steps, 1),
89 none = hope_option:pipe(Steps, 2),
90 none = hope_option:pipe(Steps, 3).
This page took 0.035167 seconds and 4 git commands to generate.