on master help sign in
Add test for drainWhile.
a6341eepranaysashank
test/Streamly/Test/Prelude/Serial.hs+13−1
@@ -12,7 +12,7 @@ module Streamly.Test.Prelude.Serial where
12import Control.Concurrent ( threadDelay )
12import Control.Concurrent ( threadDelay )
13import Control.Monad ( when, forM_ )
13import Control.Monad ( when, forM_ )
14import Data.Function ( (&) )
14import Data.Function ( (&) )
15−import Data.IORef ( newIORef, readIORef, writeIORef )
15+import Data.IORef ( newIORef, readIORef, writeIORef, modifyIORef' )
16import Data.Int (Int64)
16import Data.Int (Int64)
17import Data.List (group, intercalate)
17import Data.List (group, intercalate)
18import Data.Maybe ( isJust, fromJust )
18import Data.Maybe ( isJust, fromJust )
@@ -574,6 +574,18 @@ main = hspec
574 serialOps $ eliminationOps folded "serially folded"
574 serialOps $ eliminationOps folded "serially folded"
575 serialOps $ eliminationOpsWord8 S.fromFoldable "serially"
575 serialOps $ eliminationOpsWord8 S.fromFoldable "serially"
576 serialOps $ eliminationOpsWord8 folded "serially folded"
576 serialOps $ eliminationOpsWord8 folded "serially folded"
577+ serialOps $ \t ->
578+ prop "drainWhile (> 0)" $ \n ->
579+ withMaxSuccess maxTestCount $
580+ monadicIO $ do
581+ let xs = [1..n]
582+ ioRef <- run $ newIORef ([] :: [Int])
583+ run $
584+ S.drainWhile (> 0) . t $
585+ S.mapM (\a -> modifyIORef' ioRef (a :) >> return a) $
586+ S.fromList xs
587+ strm <- run $ readIORef ioRef
588+ listEquals (==) (reverse strm) (takeWhile (> 0) xs)
577
589
578 -- XXX Add a test where we chain all transformation APIs and make sure that
590 -- XXX Add a test where we chain all transformation APIs and make sure that
579 -- the state is being passed through all of them.
591 -- the state is being passed through all of them.