Test hope_option module.
authorSiraaj Khandkar <siraaj@khandkar.net>
Fri, 12 Dec 2014 05:30:28 +0000 (00:30 -0500)
committerSiraaj Khandkar <siraaj@khandkar.net>
Fri, 12 Dec 2014 05:30:28 +0000 (00:30 -0500)
test/hope_option_SUITE.erl [new file with mode: 0644]

diff --git a/test/hope_option_SUITE.erl b/test/hope_option_SUITE.erl
new file mode 100644 (file)
index 0000000..2b3dab0
--- /dev/null
@@ -0,0 +1,77 @@
+-module(hope_option_SUITE).
+
+%% Callbacks
+-export(
+    [ all/0
+    , groups/0
+    ]).
+
+%% Test cases
+-export(
+    [ t_of_result/1
+    , t_put/1
+    , t_get/1
+    , t_map/1
+    , t_iter/1
+    ]).
+
+
+-define(GROUP, option).
+
+
+%% ============================================================================
+%% Common Test callbacks
+%% ============================================================================
+
+all() ->
+    [ {group, ?GROUP}
+    ].
+
+groups() ->
+    Tests =
+        [ t_of_result
+        , t_put
+        , t_get
+        , t_map
+        , t_iter
+        ],
+    Properties = [parallel],
+    [ {?GROUP, Properties, Tests}
+    ].
+
+
+%% =============================================================================
+%%  Test cases
+%% =============================================================================
+
+t_put(_Cfg) ->
+    IsFoo = fun (foo) -> true; (_) -> false end,
+    {some, foo} = hope_option:put(foo, IsFoo),
+    none        = hope_option:put(bar, IsFoo).
+
+t_get(_Cfg) ->
+    foo = hope_option:get({some, foo}, bar),
+    bar = hope_option:get(none       , bar).
+
+t_map(_Cfg) ->
+    FooToBar = fun (foo) -> bar end,
+    {some, bar} = hope_option:map({some, foo}, FooToBar),
+    none        = hope_option:map(none       , FooToBar).
+
+t_iter(_Cfg) ->
+    Key = key,
+    Put = fun (Val) -> _ = put(Key, Val), ok end,
+    Get = fun () -> get(Key) end,
+    Val = foo,
+    ok = hope_option:iter(none       , Put),
+    undefined = Get(),
+    ok = hope_option:iter({some, Val}, Put),
+    Val = Get().
+
+t_of_result(_Cfg) ->
+    Foo = foo,
+    Bar = bar,
+    ResultOk = {ok, Foo},
+    ResultError = {error, Bar},
+    {some, Foo} = hope_option:of_result(ResultOk),
+    none        = hope_option:of_result(ResultError).
This page took 0.031088 seconds and 4 git commands to generate.