diff --git a/tests/List/ExtraTests.elm b/tests/List/ExtraTests.elm index ba88a77..60d18c3 100644 --- a/tests/List/ExtraTests.elm +++ b/tests/List/ExtraTests.elm @@ -1,6 +1,7 @@ module List.ExtraTests exposing (..) import Expect +import Fuzz import List.Extra exposing (..) import Test exposing (..) @@ -24,3 +25,21 @@ indexOfTests = |> indexOf 2 |> Expect.equal Nothing ] + + +foldrResultTests : Test +foldrResultTests = + describe "foldrResult" + [ test "works like a foldr when the function always returns OK" <| + \_ -> + foldrResult (\a b -> Ok (a + b)) 0 [ 1, 2, 3 ] + |> Expect.equal (Ok (List.foldr (+) 0 [ 1, 2, 3 ])) + , test "returns an error when the provided function does" <| + \_ -> + foldrResult (\_ _ -> Err ()) () [ 1 ] + |> Expect.err + , fuzz Fuzz.int "always returns the initial value for an empty list" <| + \initial -> + foldrResult (\_ _ -> Err ()) initial [] + |> Expect.equal (Ok initial) + ]