on master help sign in
Add test for handle.
commita94dc1278c294752daca005f4417a696315a0f4c authorpranaysashank <pranaysashank@composewell.com> dateThu 26 Nov 2020, 13:47 (6 years ago) parent2701894
1 file changed+17
test/Streamly/Test/Prelude/Common.hs+17
test/Streamly/Test/Prelude/Common.hs+17
@@ -1529,6 +1529,22 @@ onExceptionProp t =
15291529 refValue <- run $ readIORef ioRef
15301530 assert $ refValue == 1
15311531
1532+handleProp ::
1533+ IsStream t
1534+ => (t IO Int -> SerialT IO Int)
1535+ -> [Int]
1536+ -> Property
1537+handleProp t vec =
1538+ withMaxSuccess maxTestCount $
1539+ monadicIO $ do
1540+ res <-
1541+ run $
1542+ S.toList . t $
1543+ S.handle
1544+ (\(ExampleException i) -> read i `S.cons` S.fromList vec)
1545+ (S.serially $ S.fromList vec <> throwM (ExampleException "0"))
1546+ assert $ res == vec ++ [0] ++ vec
1547+
15321548exceptionOps ::
15331549 (IsStream t, MonadThrow (t IO))
15341550 => String
@@ -1544,6 +1560,7 @@ exceptionOps desc t = do
15441560 prop (desc <> " finally end of stream") $ finallyProp t
15451561 -- prop (desc <> " finally partial stream") $ finallyPartialStreamProp t
15461562 prop (desc <> " finally exception in stream") $ finallyExceptionProp t
1563+ prop (desc <> " handle") $ handleProp t
15471564
15481565-------------------------------------------------------------------------------
15491566-- Compose with MonadThrow