Skip to content

Commit

Permalink
test foldrResult
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianHicks committed May 5, 2021
1 parent 37af72b commit d3aa0e8
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/List/ExtraTests.elm
@@ -1,6 +1,7 @@
module List.ExtraTests exposing (..)

import Expect
import Fuzz
import List.Extra exposing (..)
import Test exposing (..)

Expand All @@ -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)
]

0 comments on commit d3aa0e8

Please sign in to comment.