pipes-ordered-zip-1.1.0: test/Pipes/OrderedZipSpec.hs
module Pipes.OrderedZipSpec (spec) where
import Control.Foldl (list, purely)
import Test.Hspec
import Pipes (each, (>->))
import Pipes.Prelude (fold')
import Pipes.Safe (runSafeT)
import Pipes.OrderedZip (orderedZip, orderCheckPipe, WrongInputOrderException(..))
spec :: Spec
spec = do
testOrderedZip
testOrderCheckPipe
testOrderedZip :: Spec
testOrderedZip = describe "orderedZip" $ do
let a = each ([1,3,4,6,8] :: [Int])
b = each ([2,3,4,5,8] :: [Int])
mergedProd = orderedZip compare a b
it "should give correctly merged output" $
(fst <$> purely fold' list mergedProd) `shouldReturn` result
where
result = [(Just 1, Nothing),
(Nothing, Just 2),
(Just 3, Just 3),
(Just 4, Just 4),
(Nothing, Just 5),
(Just 6, Nothing),
(Just 8, Just 8)]
testOrderCheckPipe :: Spec
testOrderCheckPipe = describe "orderCheckPipe" $ do
let a = each ([1,4,3,6,8] :: [Int])
p = a >-> orderCheckPipe compare
it "should throw if invalid input order is given" $
runSafeT (purely fold' list p) `shouldThrow` (==WrongInputOrderException "ordering violated: 4 should come after 3")
it "should do nothing if input is ordered" $ do
let a' = each ([1,3,4,6,8] :: [Int])
p' = a' >-> orderCheckPipe compare
runSafeT (fst <$> purely fold' list p') `shouldReturn` [1, 3, 4, 6, 8]