@@ -66,6 +66,8 @@ module Streamly.Test.Prelude.Common
6666 , zipMonadic
6767 , zipAsyncApplicative
6868 , zipAsyncMonadic
69+ -- * Exception operations
70+ , exceptionOps
6971 -- * MonadThrow operations
7072 , composeWithMonadThrow
7173 -- * Cleanup tests
@@ -1372,6 +1374,33 @@ parallelCheck t f = do
13721374
13731375 where event n = S.yieldM (threadDelay (n * 200000)) >> return n
13741376
1377+-------------------------------------------------------------------------------
1378+-- Exception ops
1379+-------------------------------------------------------------------------------
1380+
1381+exceptionOps :: IsStream t => String -> (t IO Int -> SerialT IO Int) -> Spec
1382+exceptionOps desc t = do
1383+ prop (desc <> " before") $ beforeProp t
1384+ prop (desc <> " after") $ afterProp t
1385+
1386+beforeProp :: IsStream t => (t IO Int -> SerialT IO Int) -> [Int] -> Property
1387+beforeProp t vec = withMaxSuccess maxTestCount $
1388+ monadicIO $ do
1389+ ioRef <- run $ newIORef False
1390+ strm <- run $ S.toList . t $ S.before (writeIORef ioRef True) (S.fromList vec)
1391+ refValue <- run $ readIORef ioRef
1392+ assert refValue
1393+ assert $ sort strm == sort vec
1394+
1395+afterProp :: IsStream t => (t IO Int -> SerialT IO Int) -> [Int] -> Property
1396+afterProp t vec = withMaxSuccess maxTestCount $
1397+ monadicIO $ do
1398+ ioRef <- run $ newIORef False
1399+ strm <- run $ S.toList . t $ S.after (writeIORef ioRef True) (S.fromList vec)
1400+ refValue <- run $ readIORef ioRef
1401+ assert refValue
1402+ assert $ sort strm == sort vec
1403+
13751404-------------------------------------------------------------------------------
13761405-- Compose with MonadThrow
13771406-------------------------------------------------------------------------------