Implement hope_option:of_undefined/1
[hope.git] / test / hope_option_SUITE.erl
index 2b3dab0..370cf24 100644 (file)
@@ -9,10 +9,12 @@
 %% 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
     ]).
 
 
@@ -30,10 +32,12 @@ all() ->
 groups() ->
     Tests =
         [ t_of_result
+        , t_of_undefined
         , t_put
         , t_get
         , t_map
         , t_iter
+        , t_pipe
         ],
     Properties = [parallel],
     [ {?GROUP, Properties, Tests}
@@ -75,3 +79,23 @@ 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).
This page took 0.018518 seconds and 4 git commands to generate.