@@ -12,7 +12,7 @@ module Streamly.Test.Prelude.Serial where
1212import Control.Concurrent ( threadDelay )
1313import Control.Monad ( when, forM_ )
1414import Data.Function ( (&) )
15−import Data.IORef ( newIORef, readIORef, writeIORef )
15+import Data.IORef ( newIORef, readIORef, writeIORef, modifyIORef' )
1616import Data.Int (Int64)
1717import Data.List (group, intercalate)
1818import Data.Maybe ( isJust, fromJust )
@@ -574,6 +574,18 @@ main = hspec
574574 serialOps $ eliminationOps folded "serially folded"
575575 serialOps $ eliminationOpsWord8 S.fromFoldable "serially"
576576 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)
577589
578590 -- XXX Add a test where we chain all transformation APIs and make sure that
579591 -- the state is being passed through all of them.