on master help sign in
Modularize test cases (#1707)

* Modularize test cases * Make it build with test-core flag And several other changes. Co-authored-by: Harendra Kumar <harendra@composewell.com>

commitec760805c972dc0a6f4f7f07216e324eeb8e8b90 authorRanjeet Ranjan <ranjeetr@composewell.com> dateSat 20 Aug 2022, 00:45 (4 years ago) parentca76876
18 files changed+334−197
.hlint.ignore−1 benchmark/Streamly/Benchmark/Data/Unfold.hs−1 core/src/Streamly/Internal/Data/Stream/Bottom.hs−1 core/src/Streamly/Internal/Data/Unfold.hs+7 hie.yaml+2 src/Streamly/Data/Unfold.hs+1−1 streamly.cabal+1 test/Streamly/Test/Data/Array.hs+3−1 test/Streamly/Test/Data/Array/Stream/Foreign.hs+14−1 test/Streamly/Test/Data/Array/Unboxed.hs+2−31 test/Streamly/Test/Data/Array/Unboxed/Mut.hs+42 test/Streamly/Test/Data/Fold.hs+131−100 test/Streamly/Test/Data/Fold/Window.hs+5−4 test/Streamly/Test/Data/List.hs+16−16 test/Streamly/Test/Data/Parser.hs+14−10 test/Streamly/Test/Data/Parser/ParserD.hs+9−5 test/Streamly/Test/Data/Unfold.hs+4−6 test/streamly-tests.cabal+83−19
.hlint.ignore−1
@@ -3,7 +3,6 @@ core/src/Streamly/Internal/Data/Pipe/Type.hs
33src/Streamly/Internal/Data/SmallArray/Type.hs
44src/Streamly/Internal/Unicode/Stream.hs
55test/Streamly/Test/Data/Array.hs
6−test/Streamly/Test/Data/Array/Foreign.hs
76test/Streamly/Test/Data/Parser.hs
87test/Streamly/Test/Data/Parser/ParserD.hs
98test/Streamly/Test/Data/SmallArray.hs
benchmark/Streamly/Benchmark/Data/Unfold.hs−1
@@ -28,7 +28,6 @@ import System.IO (Handle, hClose)
2828import System.Random (randomRIO)
2929
3030import qualified Prelude
31−import qualified Streamly.Data.Unfold as UF
3231import qualified Streamly.FileSystem.Handle as FH
3332import qualified Streamly.Internal.Data.Fold as FL
3433import qualified Streamly.Internal.Data.Unfold as UF
core/src/Streamly/Internal/Data/Stream/Bottom.hs−1
@@ -84,7 +84,6 @@ import Streamly.Internal.Data.Stream.Type
8484-- >>> import System.IO.Unsafe (unsafePerformIO)
8585-- >>> import Streamly.Internal.Data.Stream as Stream
8686-- >>> import qualified Streamly.Data.Array.Unboxed as Array
87−-- >>> import qualified Streamly.Data.Unfold as Unfold
8887-- >>> import qualified Streamly.Internal.Data.Fold as Fold
8988-- >>> import qualified Streamly.Internal.Data.Parser as Parser
9089-- >>> import qualified Streamly.Internal.Data.Unfold as Unfold
core/src/Streamly/Internal/Data/Unfold.hs+7
@@ -180,8 +180,10 @@ module Streamly.Internal.Data.Unfold
180180 -- ** From Memory
181181 , fromPtr
182182
183+ -- ** From Stream
183184 , fromStreamK
184185 , fromStreamD
186+ , fromStream
185187
186188 -- * Combinators
187189 -- ** Mapping on Input
@@ -281,6 +283,7 @@ import qualified Data.Tuple as Tuple
281283import qualified Streamly.Internal.Data.Fold.Type as FL
282284import qualified Streamly.Internal.Data.Stream.StreamD.Type as D
283285import qualified Streamly.Internal.Data.Stream.StreamK.Type as K
286+import qualified Streamly.Internal.Data.Stream.Type as Stream
284287
285288import Streamly.Internal.Data.Unfold.Enumeration
286289import Streamly.Internal.Data.Unfold.Type
@@ -585,6 +588,10 @@ fromStreamK = Unfold step pure
585588 Just (x, xs) -> Yield x xs
586589 Nothing -> Stop) <$> K.uncons stream
587590
591+{-# INLINE fromStream #-}
592+fromStream :: Applicative m => Unfold m (Stream.Stream m a) a
593+fromStream = lmap Stream.toStreamK fromStreamK
594+
588595-------------------------------------------------------------------------------
589596-- Unfolds
590597-------------------------------------------------------------------------------
hie.yaml+2
@@ -74,6 +74,8 @@ cradle:
7474 component: "test:Data.Array"
7575 - path: "./test/Streamly/Test/Data/Array/Unboxed.hs"
7676 component: "test:Data.Array.Unboxed"
77+ - path: "./test/Streamly/Test/Data/Array/Unboxed/Mut.hs"
78+ component: "test:Data.Array.Unboxed.Mut"
7779 - path: "./test/Streamly/Test/Data/Array/Stream/Foreign.hs"
7880 component: "test:Data.Array.Stream.Foreign"
7981 - path: "./test/Streamly/Test/Data/Fold.hs"
src/Streamly/Data/Unfold.hs+1−1
@@ -213,7 +213,7 @@ import Prelude hiding
213213 , zipWith
214214 )
215215import Streamly.Internal.Data.Stream.IsStream.Type (IsStream)
216−import Streamly.Internal.Data.Unfold
216+import Streamly.Internal.Data.Unfold hiding (fromStream)
217217
218218import qualified Streamly.Internal.Data.Stream.IsStream.Type as IsStream
219219import qualified Streamly.Internal.Data.Unfold as Unfold
streamly.cabal+1
@@ -92,6 +92,7 @@ extra-source-files:
9292 test/Streamly/Test/Data/Array/CommonImports.hs
9393 test/Streamly/Test/Data/Array/Common.hs
9494 test/Streamly/Test/Data/Array/Unboxed.hs
95+ test/Streamly/Test/Data/Array/Unboxed/Mut.hs
9596 test/Streamly/Test/Data/Ring/Unboxed.hs
9697 test/Streamly/Test/Data/Array/Stream/Foreign.hs
9798 test/Streamly/Test/Data/Parser/ParserD.hs
test/Streamly/Test/Data/Array.hs+3−1
@@ -11,6 +11,8 @@ module Streamly.Test.Data.Array (main) where
1111#include "Streamly/Test/Data/Array/CommonImports.hs"
1212
1313import qualified Streamly.Internal.Data.Array as A
14+import qualified Streamly.Internal.Data.Fold as Fold
15+
1416type Array = A.Array
1517
1618moduleName :: String
@@ -30,7 +32,7 @@ testFromList =
3032 forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
3133 monadicIO $ do
3234 let arr = A.fromList list
33− xs <- run $ S.toList $ (S.unfold A.read) arr
35+ xs <- run $ S.fold Fold.toList $ S.unfold A.read arr
3436 assert (xs == list)
3537
3638testLengthFromStream :: Property
test/Streamly/Test/Data/Array/Stream/Foreign.hs+14−1
@@ -4,7 +4,7 @@ import Data.Word (Word8)
44import Streamly.Test.Common (listEquals, chooseInt)
55import Test.Hspec (hspec, describe, shouldBe)
66import Test.Hspec.QuickCheck
7−import Test.QuickCheck (forAll, Property, vectorOf, Gen)
7+import Test.QuickCheck (forAll, Property, vectorOf, Gen, Arbitrary (arbitrary))
88import Test.QuickCheck.Monadic (monadicIO, run)
99
1010import qualified Streamly.Internal.Data.Array.Unboxed as Array
@@ -71,6 +71,18 @@ splitOnSuffix sep inp out = do
7171moduleName :: String
7272moduleName = "Data.Array.Stream.Foreign"
7373
74+-- Instead of hard coding 10000 here we can have maxStreamLength for operations
75+-- that use stream of arrays.
76+
77+concatArrayW8 :: Property
78+concatArrayW8 =
79+ forAll (vectorOf 10000 (arbitrary :: Gen Word8))
80+ $ \w8List -> do
81+ let w8ArrList = Array.fromList . (: []) <$> w8List
82+ f2 <- Stream.toList $ ArrayStream.concat $ Stream.fromList w8ArrList
83+ w8List `shouldBe` f2
84+
85+
7486main :: IO ()
7587main =
7688 hspec $
@@ -79,6 +91,7 @@ main =
7991 describe moduleName $ do
8092 describe "Stream parsing" $ do
8193 prop "parseBreak" parseBreak
94+ prop "concatArrayW8" concatArrayW8
8295 describe "splifOnSuffix" $ do
8396 Hspec.it "splitOnSuffix 0 [1, 2, 0, 4, 0, 5, 6]"
8497 $ splitOnSuffix 0 [1, 2, 0, 4, 0, 5, 6]
test/Streamly/Test/Data/Array/Unboxed.hs+2−31
@@ -18,11 +18,10 @@ import Streamly.Internal.Data.Unboxed (Unboxed)
1818import Test.QuickCheck (chooseInt, listOf)
1919import GHC.Ptr (plusPtr)
2020
21−import qualified Streamly.Internal.Data.Fold as Fold
2221import qualified Streamly.Internal.Data.Array.Unboxed as A
2322import qualified Streamly.Internal.Data.Array.Unboxed.Type as A
2423import qualified Streamly.Internal.Data.Array.Unboxed.Mut.Type as MA
25−import qualified Streamly.Internal.Data.Array.Stream.Foreign as AS
24+import qualified Streamly.Internal.Data.Fold as Fold
2625
2726type Array = A.Array
2827
@@ -43,13 +42,12 @@ testFromList =
4342 forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
4443 monadicIO $ do
4544 let arr = A.fromList list
46− xs <- run $ S.toList $ S.unfold A.read arr
45+ xs <- run $ S.fold Fold.toList $ S.unfold A.read arr
4746 assert (xs == list)
4847
4948testLengthFromStream :: Property
5049testLengthFromStream = genericTestFrom (const A.fromStream)
5150
52−
5351unsafeWriteIndex :: [Int] -> Int -> Int -> IO Bool
5452unsafeWriteIndex xs i x = do
5553 arr <- MA.fromList xs
@@ -121,38 +119,12 @@ testStripNull = do
121119 x <- MA.toList dt'
122120 return $ x == ""
123121
124−-- Instead of hard coding 10000 here we can have maxStreamLength for operations
125−-- that use stream of arrays.
126−concatArrayW8 :: Property
127−concatArrayW8 =
128− forAll (vectorOf 10000 (arbitrary :: Gen Word8))
129− $ \w8List -> do
130− let w8ArrList = A.fromList . (: []) <$> w8List
131− f2 <- S.toList $ AS.concat $ S.fromList w8ArrList
132− w8List `shouldBe` f2
133−
134122unsafeSlice :: Int -> Int -> [Int] -> Bool
135123unsafeSlice i n list =
136124 let lst = take n $ drop i list
137125 arr = A.toList $ A.getSliceUnsafe i n $ A.fromList list
138126 in arr == lst
139127
140−{-
141−testAppend :: Property
142−testAppend =
143− forAll (listOf (chooseInt (-50, 100))) $ \ls0 ->
144− monadicIO $ action ls0
145−
146− where
147−
148− action ls = do
149− x <- S.fold
150− (MA.append (MA.newArray 0))
151− (S.fromList (ls::[Int]))
152− lst <- MA.toList x
153− assert (ls == lst)
154−-}
155−
156128testBubbleWith :: Bool -> Property
157129testBubbleWith asc =
158130 forAll (listOf (chooseInt (-50, 100))) $ \ls0 ->
@@ -257,7 +229,6 @@ main =
257229 prop "fromList" testFromList
258230 prop "foldMany with writeNUnsafe concats to original"
259231 (foldManyWith (\n -> Fold.take n (A.writeNUnsafe n)))
260− prop "AS.concat . (A.fromList . (:[]) <$>) === id" concatArrayW8
261232 describe "unsafeSlice" $ do
262233 it "partial" $ unsafeSlice 2 4 [1..10]
263234 it "none" $ unsafeSlice 10 0 [1..10]
test/Streamly/Test/Data/Array/Unboxed/Mut.hsnew file+42
@@ -0,0 +1,42 @@
1+module Streamly.Test.Data.Array.Unboxed.Mut (main) where
2+
3+import Test.QuickCheck (listOf)
4+
5+import Streamly.Test.Common (chooseInt)
6+import Test.Hspec (hspec, describe)
7+import Test.Hspec.QuickCheck
8+import Test.QuickCheck (forAll, Property)
9+import Test.QuickCheck.Monadic (monadicIO, assert)
10+
11+import qualified Streamly.Internal.Data.Array.Unboxed.Mut as MArray
12+import qualified Streamly.Internal.Data.Stream as Stream
13+import qualified Test.Hspec as Hspec
14+
15+maxTestCount :: Int
16+maxTestCount = 100
17+
18+moduleName :: String
19+moduleName = "Data.Array.Unboxed.Mut"
20+
21+testAppend :: Property
22+testAppend =
23+ forAll (listOf (chooseInt (-50, 100))) $ \ls0 ->
24+ monadicIO $ action ls0
25+
26+ where
27+
28+ action ls = do
29+ x <- Stream.fold
30+ (MArray.append (MArray.newArray 0))
31+ (Stream.fromList (ls::[Int]))
32+ lst <- MArray.toList x
33+ assert (ls == lst)
34+
35+main :: IO ()
36+main =
37+ hspec $
38+ Hspec.parallel $
39+ modifyMaxSuccess (const maxTestCount) $ do
40+ describe moduleName $ do
41+ describe "Stream Append" $ do
42+ prop "testAppend" testAppend
test/Streamly/Test/Data/Fold.hs+131−100
@@ -23,11 +23,9 @@ import Test.QuickCheck.Monadic (monadicIO, assert, run)
2323
2424import qualified Data.Map
2525import qualified Prelude
26−import qualified Streamly.Internal.Data.Fold as F
27−import qualified Streamly.Prelude as S
28−import qualified Streamly.Internal.Data.Array.Unboxed.Mut.Type as MA
29−import qualified Streamly.Internal.Data.Stream.IsStream as Stream
30−import qualified Streamly.Data.Fold as FL
26+import qualified Streamly.Internal.Data.Array.Unboxed.Mut as MArray
27+import qualified Streamly.Internal.Data.Fold as Fold
28+import qualified Streamly.Internal.Data.Stream as Stream
3129
3230import Prelude hiding
3331 (maximum, minimum, elem, notElem, null, product, sum, head, last, take)
@@ -62,26 +60,31 @@ rollingHashFirstN =
6260 forAll (choose (0, len)) $ \n ->
6361 forAll (vectorOf len (arbitrary :: Gen Int)) $ \vec ->
6462 monadicIO $ do
65− a <- run $ S.fold F.rollingHash $ S.take n $ S.fromList vec
66− b <- run $ S.fold (F.rollingHashFirstN n) $ S.fromList vec
63+ a <- run
64+ $ Stream.fold Fold.rollingHash
65+ $ Stream.take n
66+ $ Stream.fromList vec
67+ b <- run
68+ $ Stream.fold (Fold.rollingHashFirstN n)
69+ $ Stream.fromList vec
6770 assert $ a == b
6871
6972head :: [Int] -> Expectation
70−head ls = S.fold FL.head (S.fromList ls) `shouldReturn` headl ls
73+head ls = Stream.fold Fold.head (Stream.fromList ls) `shouldReturn` headl ls
7174
7275headl :: [a] -> Maybe a
7376headl [] = Nothing
7477headl (x:_) = Just x
7578
7679length :: [Int] -> Expectation
77−length ls = S.fold FL.length (S.fromList ls) `shouldReturn` Prelude.length ls
80+length ls = Stream.fold Fold.length (Stream.fromList ls) `shouldReturn` Prelude.length ls
7881
7982sum :: [Int] -> Expectation
80−sum ls = S.fold FL.sum (S.fromList ls) `shouldReturn` Prelude.sum ls
83+sum ls = Stream.fold Fold.sum (Stream.fromList ls) `shouldReturn` Prelude.sum ls
8184
8285product :: [Int] -> Expectation
8386product ls =
84− S.fold FL.product (S.fromList ls) `shouldReturn` Prelude.product ls
87+ Stream.fold Fold.product (Stream.fromList ls) `shouldReturn` Prelude.product ls
8588
8689lesser :: (a -> a -> Ordering) -> a -> a -> a
8790lesser f x y = if f x y == LT then x else y
@@ -97,29 +100,29 @@ foldMaybe f acc ls =
97100
98101maximumBy :: (Ord a, Show a) => a -> (a -> a -> Ordering) -> [a] -> Expectation
99102maximumBy genmin f ls =
100− S.fold (FL.maximumBy f) (S.fromList ls)
103+ Stream.fold (Fold.maximumBy f) (Stream.fromList ls)
101104 `shouldReturn` foldMaybe (greater f) genmin ls
102105
103106maximum :: (Show a, Ord a) => a -> [a] -> Expectation
104107maximum genmin ls =
105− S.fold FL.maximum (S.fromList ls)
108+ Stream.fold Fold.maximum (Stream.fromList ls)
106109 `shouldReturn` foldMaybe (greater compare) genmin ls
107110
108111minimumBy :: (Ord a, Show a) => a -> (a -> a -> Ordering) -> [a] -> Expectation
109112minimumBy genmax f ls =
110− S.fold (FL.minimumBy f) (S.fromList ls)
113+ Stream.fold (Fold.minimumBy f) (Stream.fromList ls)
111114 `shouldReturn` foldMaybe (lesser f) genmax ls
112115
113116minimum :: (Show a, Ord a) => a -> [a] -> Expectation
114117minimum genmax ls =
115− S.fold FL.minimum (S.fromList ls)
118+ Stream.fold Fold.minimum (Stream.fromList ls)
116119 `shouldReturn` foldMaybe (lesser compare) genmax ls
117120
118121toList :: [Int] -> Expectation
119−toList ls = S.fold FL.toList (S.fromList ls) `shouldReturn` ls
122+toList ls = Stream.fold Fold.toList (Stream.fromList ls) `shouldReturn` ls
120123
121124toListRev :: [Int] -> Expectation
122−toListRev ls = S.fold FL.toListRev (S.fromList ls) `shouldReturn` reverse ls
125+toListRev ls = Stream.fold Fold.toListRev (Stream.fromList ls) `shouldReturn` reverse ls
123126
124127safeLast :: [a] -> Maybe a
125128safeLast [] = Nothing
@@ -127,7 +130,7 @@ safeLast (x:[]) = Just x
127130safeLast (_:xs) = safeLast xs
128131
129132last :: [String] -> Expectation
130−last ls = S.fold FL.last (S.fromList ls) `shouldReturn` safeLast ls
133+last ls = Stream.fold Fold.last (Stream.fromList ls) `shouldReturn` safeLast ls
131134
132135mapMaybe :: [Int] -> Expectation
133136mapMaybe ls =
@@ -135,8 +138,8 @@ mapMaybe ls =
135138 if even x
136139 then Just x
137140 else Nothing
138− f = FL.mapMaybe maybeEven FL.toList
139− in S.fold f (S.fromList ls) `shouldReturn` filter even ls
141+ f = Fold.mapMaybe maybeEven Fold.toList
142+ in Stream.fold f (Stream.fromList ls) `shouldReturn` filter even ls
140143
141144nth :: Int -> [a] -> Maybe a
142145nth idx (x : xs)
@@ -147,18 +150,18 @@ nth _ [] = Nothing
147150
148151index :: Int -> [String] -> Expectation
149152index idx ls =
150− let x = S.fold (FL.index idx) (S.fromList ls)
153+ let x = Stream.fold (Fold.index idx) (Stream.fromList ls)
151154 in x `shouldReturn` nth idx ls
152155
153156find :: (Show a, Eq a) => (a -> Bool) -> [a] -> Expectation
154157find f ls = do
155− y <- S.fold (FL.findIndex f) (S.fromList ls)
158+ y <- Stream.fold (Fold.findIndex f) (Stream.fromList ls)
156159 case y of
157160 Nothing ->
158− let fld = S.fold (FL.find f) (S.fromList ls)
161+ let fld = Stream.fold (Fold.find f) (Stream.fromList ls)
159162 in fld `shouldReturn` Nothing
160163 Just idx ->
161− let fld = S.fold (FL.any f) (S.fromList $ Prelude.take idx ls)
164+ let fld = Stream.fold (Fold.any f) (Stream.fromList $ Prelude.take idx ls)
162165 in fld `shouldReturn` False
163166
164167neg :: (a -> Bool) -> a -> Bool
@@ -166,17 +169,17 @@ neg f x = not (f x)
166169
167170findIndex :: (a -> Bool) -> [a] -> Expectation
168171findIndex f ls = do
169− y <- S.fold (FL.findIndex f) (S.fromList ls)
172+ y <- Stream.fold (Fold.findIndex f) (Stream.fromList ls)
170173 case y of
171174 Nothing ->
172− let fld = S.fold (FL.all $ neg f) (S.fromList ls)
175+ let fld = Stream.fold (Fold.all $ neg f) (Stream.fromList ls)
173176 in fld `shouldReturn` True
174177 Just idx ->
175178 if idx == 0
176179 then
177− S.fold (FL.all f) (S.fromList []) `shouldReturn` True
180+ Stream.fold (Fold.all f) (Stream.fromList []) `shouldReturn` True
178181 else
179− S.fold (FL.all f) (S.fromList $ Prelude.take idx ls)
182+ Stream.fold (Fold.all f) (Stream.fromList $ Prelude.take idx ls)
180183 `shouldReturn` False
181184
182185predicate :: Int -> Bool
@@ -184,19 +187,21 @@ predicate x = x * x < 100
184187
185188elemIndex :: Int -> [Int] -> Expectation
186189elemIndex elm ls = do
187− y <- S.fold (FL.elemIndex elm) (S.fromList ls)
190+ y <- Stream.fold (Fold.elemIndex elm) (Stream.fromList ls)
188191 case y of
189192 Nothing ->
190− let fld = S.fold (FL.any (== elm)) (S.fromList ls)
193+ let fld = Stream.fold (Fold.any (== elm)) (Stream.fromList ls)
191194 in fld `shouldReturn` False
192195 Just idx ->
193196 let fld =
194− S.fold (FL.any (== elm)) (S.fromList $ Prelude.take idx ls)
197+ Stream.fold
198+ (Fold.any (== elm))
199+ (Stream.fromList $ Prelude.take idx ls)
195200 in fld `shouldReturn` False
196201
197202null :: [Int] -> Expectation
198203null ls =
199− S.fold FL.null (S.fromList ls)
204+ Stream.fold Fold.null (Stream.fromList ls)
200205 `shouldReturn`
201206 case ls of
202207 [] -> True
@@ -204,42 +209,42 @@ null ls =
204209
205210elem :: Int -> [Int] -> Expectation
206211elem elm ls = do
207− y <- S.fold (FL.elem elm) (S.fromList ls)
208− let fld = S.fold (FL.any (== elm)) (S.fromList ls)
212+ y <- Stream.fold (Fold.elem elm) (Stream.fromList ls)
213+ let fld = Stream.fold (Fold.any (== elm)) (Stream.fromList ls)
209214 fld `shouldReturn` y
210215
211216notElem :: Int -> [Int] -> Expectation
212217notElem elm ls = do
213− y <- S.fold (FL.notElem elm) (S.fromList ls)
214− let fld = S.fold (FL.any (== elm)) (S.fromList ls)
218+ y <- Stream.fold (Fold.notElem elm) (Stream.fromList ls)
219+ let fld = Stream.fold (Fold.any (== elm)) (Stream.fromList ls)
215220 fld `shouldReturn` not y
216221
217222all :: (a -> Bool) -> [a] -> Expectation
218223all f ls =
219− S.fold (FL.all f) (S.fromList ls) `shouldReturn` Prelude.all f ls
224+ Stream.fold (Fold.all f) (Stream.fromList ls) `shouldReturn` Prelude.all f ls
220225
221226any :: (a -> Bool) -> [a] -> Expectation
222−any f ls = S.fold (FL.any f) (S.fromList ls) `shouldReturn` Prelude.any f ls
227+any f ls = Stream.fold (Fold.any f) (Stream.fromList ls) `shouldReturn` Prelude.any f ls
223228
224229and :: [Bool] -> Expectation
225−and ls = S.fold FL.and (S.fromList ls) `shouldReturn` Prelude.and ls
230+and ls = Stream.fold Fold.and (Stream.fromList ls) `shouldReturn` Prelude.and ls
226231
227232or :: [Bool] -> Expectation
228−or ls = S.fold FL.or (S.fromList ls) `shouldReturn` Prelude.or ls
233+or ls = Stream.fold Fold.or (Stream.fromList ls) `shouldReturn` Prelude.or ls
229234
230235take :: [Int] -> Property
231236take ls =
232237 forAll (chooseInt (-1, Prelude.length ls + 2)) $ \n ->
233− S.fold (FL.take n FL.toList) (S.fromList ls)
238+ Stream.fold (Fold.take n Fold.toList) (Stream.fromList ls)
234239 `shouldReturn` Prelude.take n ls
235240
236241takeEndBy_ :: Property
237242takeEndBy_ =
238243 forAll (listOf (chooseInt (0, 1))) $ \ls ->
239244 let p = (== 1)
240− f = FL.takeEndBy_ p FL.toList
245+ f = Fold.takeEndBy_ p Fold.toList
241246 ys = Prelude.takeWhile (not . p) ls
242− in case S.fold f (S.fromList ls) of
247+ in case Stream.fold f (Stream.fromList ls) of
243248 Right xs -> checkListEqual xs ys
244249 Left _ -> property False
245250
@@ -248,9 +253,9 @@ takeEndByOrMax =
248253 forAll (chooseInt (min_value, max_value)) $ \n ->
249254 forAll (listOf (chooseInt (0, 1))) $ \ls ->
250255 let p = (== 1)
251− f = FL.takeEndBy_ p (FL.take n FL.toList)
256+ f = Fold.takeEndBy_ p (Fold.take n Fold.toList)
252257 ys = Prelude.take n (Prelude.takeWhile (not . p) ls)
253− in case S.fold f (S.fromList ls) of
258+ in case Stream.fold f (Stream.fromList ls) of
254259 Right xs -> checkListEqual xs ys
255260 Left _ -> property False
256261
@@ -258,10 +263,10 @@ chooseFloat :: (Float, Float) -> Gen Float
258263chooseFloat = choose
259264
260265drain :: [Int] -> Expectation
261−drain ls = S.fold FL.drain (S.fromList ls) `shouldReturn` ()
266+drain ls = Stream.fold Fold.drain (Stream.fromList ls) `shouldReturn` ()
262267
263268drainBy :: [Int] -> Expectation
264−drainBy ls = S.fold (FL.drainBy return) (S.fromList ls) `shouldReturn` ()
269+drainBy ls = Stream.fold (Fold.drainBy return) (Stream.fromList ls) `shouldReturn` ()
265270
266271mean :: Property
267272mean =
@@ -271,7 +276,7 @@ mean =
271276 where
272277
273278 action ls = do
274− v1 <- run $ S.fold FL.mean (S.fromList ls)
279+ v1 <- run $ Stream.fold Fold.mean (Stream.fromList ls)
275280 let v2 = Prelude.sum ls / fromIntegral (Prelude.length ls)
276281 assert (abs (v1 - v2) < 0.0001)
277282
@@ -283,7 +288,7 @@ stdDev =
283288 where
284289
285290 action ls = do
286− v1 <- run $ S.fold FL.stdDev (S.fromList ls)
291+ v1 <- run $ Stream.fold Fold.stdDev (Stream.fromList ls)
287292 let avg = Prelude.sum ls / fromIntegral (Prelude.length ls)
288293 se = Prelude.sum (fmap (\x -> (x - avg) * (x - avg)) ls)
289294 sd = sqrt $ se / fromIntegral (Prelude.length ls)
@@ -297,7 +302,7 @@ variance =
297302 where
298303
299304 action ls = do
300− v1 <- run $ S.fold FL.variance (S.fromList ls)
305+ v1 <- run $ Stream.fold Fold.variance (Stream.fromList ls)
301306 let avg = Prelude.sum ls / fromIntegral (Prelude.length ls)
302307 se = Prelude.sum (fmap (\x -> (x - avg) * (x - avg)) ls)
303308 vr = se / fromIntegral (Prelude.length ls)
@@ -311,7 +316,7 @@ mconcat =
311316 where
312317
313318 action ls = do
314− v1 <- run $ S.fold FL.mconcat (S.map Sum $ S.fromList ls)
319+ v1 <- run $ Stream.fold Fold.mconcat (fmap Sum $ Stream.fromList ls)
315320 let v2 = Prelude.sum ls
316321 assert (getSum v1 == v2)
317322
@@ -323,7 +328,7 @@ foldMap =
323328 where
324329
325330 action ls = do
326− v1 <- run $ S.fold (FL.foldMap Sum) $ S.fromList ls
331+ v1 <- run $ Stream.fold (Fold.foldMap Sum) $ Stream.fromList ls
327332 let v2 = Prelude.sum ls
328333 assert (getSum v1 == v2)
329334
@@ -335,7 +340,7 @@ foldMapM =
335340 where
336341
337342 action ls = do
338− v1 <- run $ S.fold (FL.foldMapM (return . Sum)) $ S.fromList ls
343+ v1 <- run $ Stream.fold (Fold.foldMapM (return . Sum)) $ Stream.fromList ls
339344 let v2 = Prelude.sum ls
340345 assert (getSum v1 == v2)
341346
@@ -352,7 +357,7 @@ lookup =
352357 , (8, "fifth+third"), (9, "fifth+fourth")
353358 , (10, "fifth+fifth")
354359 ]
355− v1 <- run $ S.fold (FL.lookup key) $ S.fromList ls
360+ v1 <- run $ Stream.fold (Fold.lookup key) $ Stream.fromList ls
356361 let v2 = Prelude.lookup key ls
357362 assert (v1 == v2)
358363
@@ -365,9 +370,9 @@ rmapM =
365370
366371 action ls = do
367372 let addLen x = return $ x + Prelude.length ls
368− fld = FL.rmapM addLen FL.sum
373+ fld = Fold.rmapM addLen Fold.sum
369374 v2 = foldl (+) (Prelude.length ls) ls
370− v1 <- run $ S.fold fld $ S.fromList ls
375+ v1 <- run $ Stream.fold fld $ Stream.fromList ls
371376 assert (v1 == v2)
372377
373378teeWithLength :: Property
@@ -378,7 +383,7 @@ teeWithLength =
378383 where
379384
380385 action ls = do
381− v1 <- run $ S.fold (FL.tee FL.sum FL.length) $ S.fromList ls
386+ v1 <- run $ Stream.fold (Fold.tee Fold.sum Fold.length) $ Stream.fromList ls
382387 let v2 = Prelude.sum ls
383388 v3 = Prelude.length ls
384389 assert (v1 == (v2, v3))
@@ -391,7 +396,10 @@ teeWithFstLength =
391396 where
392397
393398 action ls = do
394− v1 <- run $ S.fold (F.teeWithFst (,) (FL.take 5 FL.sum) FL.length) $ S.fromList ls
399+ v1 <-
400+ run
401+ $ Stream.fold (Fold.teeWithFst (,) (Fold.take 5 Fold.sum) Fold.length)
402+ $ Stream.fromList ls
395403 let v2 = Prelude.sum (Prelude.take 5 ls)
396404 v3 = Prelude.length (Prelude.take 5 ls)
397405 assert (v1 == (v2, v3))
@@ -405,7 +413,10 @@ partitionByM =
405413
406414 action ls = do
407415 let f = \x -> if odd x then return (Left x) else return (Right x)
408− v1 <- run $ S.fold (F.partitionByM f FL.length FL.length) $ S.fromList ls
416+ v1 <-
417+ run
418+ $ Stream.fold (Fold.partitionByM f Fold.length Fold.length)
419+ $ Stream.fromList ls
409420 let v2 = foldl (\b a -> if odd a then b+1 else b) 0 ls
410421 v3 = foldl (\b a -> if even a then b+1 else b) 0 ls
411422 assert (v1 == (v2, v3))
@@ -419,7 +430,11 @@ partitionByFstM =
419430
420431 action _ = do
421432 let f = \x -> if odd x then return (Left x) else return (Right x)
422− v1 <- run $ S.fold (F.partitionByFstM f (FL.take 25 FL.length) FL.length) (S.fromList ([1..100]:: [Int]))
433+ v1 <-
434+ run
435+ $ Stream.fold
436+ (Fold.partitionByFstM f (Fold.take 25 Fold.length) Fold.length)
437+ (Stream.fromList ([1 .. 100] :: [Int]))
423438 let v2 = foldl (\b a -> if odd a then b+1 else b) 0 ([1..49] :: [Int])
424439 v3 = foldl (\b a -> if even a then b+1 else b) 0 ([1..49] :: [Int])
425440 assert (v1 == (v2, v3))
@@ -433,7 +448,11 @@ partitionByMinM1 =
433448
434449 action _ = do
435450 let f = \x -> if odd x then return (Left x) else return (Right x)
436− v1 <- run $ S.fold (F.partitionByMinM f FL.length (FL.take 25 FL.length)) (S.fromList ([1..100]:: [Int]))
451+ v1 <-
452+ run
453+ $ Stream.fold
454+ (Fold.partitionByMinM f Fold.length (Fold.take 25 Fold.length))
455+ (Stream.fromList ([1 .. 100] :: [Int]))
437456 let v2 = foldl (\b a -> if odd a then b+1 else b) 0 ([1..50] :: [Int])
438457 v3 = foldl (\b a -> if even a then b+1 else b) 0 ([1..50] :: [Int])
439458 assert (v1 == (v2, v3))
@@ -447,7 +466,11 @@ partitionByMinM2 =
447466
448467 action _ = do
449468 let f = \x -> if odd x then return (Left x) else return (Right x)
450− v1 <- run $ S.fold (F.partitionByMinM f (FL.take 25 FL.length) FL.length) (S.fromList ([1..100]:: [Int]))
469+ v1 <-
470+ run
471+ $ Stream.fold
472+ (Fold.partitionByMinM f (Fold.take 25 Fold.length) Fold.length)
473+ (Stream.fromList ([1 .. 100] :: [Int]))
451474 let v2 = foldl (\b a -> if odd a then b+1 else b) 0 ([1..49] :: [Int])
452475 v3 = foldl (\b a -> if even a then b+1 else b) 0 ([1..49] :: [Int])
453476 assert (v1 == (v2, v3))
@@ -460,7 +483,10 @@ teeWithMinLength1 =
460483 where
461484
462485 action ls = do
463− v1 <- run $ S.fold (F.teeWithMin (,) (FL.take 5 FL.sum) FL.length) $ S.fromList ls
486+ v1 <-
487+ run
488+ $ Stream.fold (Fold.teeWithMin (,) (Fold.take 5 Fold.sum) Fold.length)
489+ $ Stream.fromList ls
464490 let v2 = Prelude.sum (Prelude.take 5 ls)
465491 v3 = Prelude.length (Prelude.take 5 ls)
466492 assert (v1 == (v2, v3))
@@ -474,10 +500,14 @@ teeWithMinLength2 =
474500 where
475501
476502 action ls = do
477− v1 <- run $ S.fold (F.teeWithMin (,) FL.sum (FL.take 5 FL.length)) $ S.fromList ls
503+ v1 <-
504+ run
505+ $ Stream.fold (Fold.teeWithMin (,) Fold.sum (Fold.take 5 Fold.length))
506+ $ Stream.fromList ls
478507 let v2 = Prelude.sum (Prelude.take 5 ls)
479508 v3 = Prelude.length (Prelude.take 5 ls)
480509 assert (v1 == (v2, v3))
510+
481511teeWithMax :: Property
482512teeWithMax =
483513 forAll (listOf1 (chooseInt (intMin, intMax)))
@@ -486,7 +516,7 @@ teeWithMax =
486516 where
487517
488518 action ls = do
489− v1 <- run $ S.fold (FL.tee FL.sum FL.maximum) $ S.fromList ls
519+ v1 <- run $ Stream.fold (Fold.tee Fold.sum Fold.maximum) $ Stream.fromList ls
490520 let v2 = Prelude.sum ls
491521 v3 = foldMaybe (greater compare) intMin ls
492522 assert (v1 == (v2, v3))
@@ -499,7 +529,8 @@ distribute =
499529 where
500530
501531 action ls = do
502− v1 <- run $ S.fold (FL.distribute [FL.sum, FL.length]) $ S.fromList ls
532+ v1 <-
533+ run $ Stream.fold (Fold.distribute [Fold.sum, Fold.length]) $ Stream.fromList ls
503534 let v2 = Prelude.sum ls
504535 v3 = Prelude.length ls
505536 assert (v1 == [v2, v3])
@@ -509,8 +540,8 @@ partition =
509540 monadicIO $ do
510541 v1 :: (Int, [String]) <-
511542 run
512− $ S.fold (FL.partition FL.sum FL.toList)
513− $ S.fromList
543+ $ Stream.fold (Fold.partition Fold.sum Fold.toList)
544+ $ Stream.fromList
514545 [Left 1, Right "abc", Left 3, Right "xy", Right "pp2"]
515546 let v2 = (4,["abc","xy","pp2"])
516547 assert (v1 == v2)
@@ -520,8 +551,8 @@ unzip =
520551 monadicIO $ do
521552 v1 :: (Int, [String]) <-
522553 run
523− $ S.fold (FL.unzip FL.sum FL.toList)
524− $ S.fromList [(1, "aa"), (2, "bb"), (3, "cc")]
554+ $ Stream.fold (Fold.unzip Fold.sum Fold.toList)
555+ $ Stream.fromList [(1, "aa"), (2, "bb"), (3, "cc")]
525556 let v2 = (6, ["aa", "bb", "cc"])
526557 assert (v1 == v2)
527558
@@ -530,8 +561,8 @@ postscan = forAll (listOf (chooseInt (intMin, intMax))) $ \ls ->
530561 monadicIO $ do
531562 v1 :: [Int] <-
532563 run
533− $ S.fold (F.postscan FL.sum FL.toList)
534− $ S.fromList ls
564+ $ Stream.fold (Fold.postscan Fold.sum Fold.toList)
565+ $ Stream.fromList ls
535566 let v2 = scanl1 (+) ls
536567 assert (v1 == v2)
537568
@@ -540,19 +571,19 @@ many =
540571 forAll (listOf (chooseInt (0, 100))) $ \lst ->
541572 forAll (chooseInt (1, 100)) $ \i ->
542573 monadicIO $ do
543− let strm = S.fromList lst
544− r1 <- S.fold (FL.many (split i) FL.toList) strm
545− r2 <- S.toList $ Stream.foldMany (split i) strm
574+ let strm = Stream.fromList lst
575+ r1 <- Stream.fold (Fold.many (split i) Fold.toList) strm
576+ r2 <- Stream.fold Fold.toList $ Stream.foldMany (split i) strm
546577 assert $ r1 == r2
547578
548579 where
549580
550− split i = FL.take i FL.toList
581+ split i = Fold.take i Fold.toList
551582
552583foldBreak :: [Int] -> Property
553584foldBreak ls = monadicIO $ do
554− (mbh, rest) <- run $ Stream.foldBreak FL.head (S.fromList ls)
555− rests <- run $ S.toList rest
585+ (mbh, rest) <- run $ Stream.foldBreak Fold.head (Stream.fromList ls)
586+ rests <- run $ Stream.fold Fold.toList rest
556587 assert (mbh == headl ls)
557588 listEquals (==) rests (taill ls)
558589
@@ -564,10 +595,10 @@ foldBreak ls = monadicIO $ do
564595
565596demux :: Expectation
566597demux =
567− let table "SUM" = return FL.sum
568− table "PRODUCT" = return FL.product
569− table _ = return FL.length
570− input = Stream.fromList (
598+ let table "SUM" = return Fold.sum
599+ table "PRODUCT" = return Fold.product
600+ table _ = return Fold.length
601+ input = Stream.fromList (
571602 [ ("SUM", 1)
572603 , ("abc", 1)
573604 , ("PRODUCT", 2)
@@ -579,7 +610,7 @@ demux =
579610 , ("abc", 2)
580611 ] :: [(String, Int)])
581612 in Stream.fold
582− (F.demux table)
613+ (Fold.demux table)
583614 input
584615 `shouldReturn`
585616 Data.Map.fromList [("PRODUCT", 8),("SUM", 4),("abc",3),("xyz",2)]
@@ -590,22 +621,22 @@ demuxWith =
590621 let getKey x | even x = "SUM"
591622 | otherwise = "PRODUCT"
592623
593− getFold "SUM" = return FL.sum
594− getFold "PRODUCT" = return FL.product
624+ getFold "SUM" = return Fold.sum
625+ getFold "PRODUCT" = return Fold.product
595626 getFold _ = error "demuxWith: bug"
596627
597− input = Stream.fromList [1, 2, 3, 4 :: Int]
628+ input = Stream.fromList [1, 2, 3, 4 :: Int]
598629 in Stream.fold
599− (F.demuxWith getKey (getFold . getKey))
630+ (Fold.demuxWith getKey (getFold . getKey))
600631 input
601632 `shouldReturn`
602− Data.Map.fromList [("PRODUCT",3),("SUM",6)]
633+ Data.Map.fromList [("PRODUCT",3),("SUM",6)]
603634
604635classifyWith :: Expectation
605636classifyWith =
606− let input = Stream.fromList [("ONE",1),("ONE",1.1),("TWO",2), ("TWO",2.2)]
637+ let input = Stream.fromList [("ONE",1),("ONE",1.1),("TWO",2), ("TWO",2.2)]
607638 in Stream.fold
608− (F.classifyWith fst (FL.lmap snd FL.toList))
639+ (Fold.classifyWith fst (Fold.lmap snd Fold.toList))
609640 input
610641 `shouldReturn`
611642 Data.Map.fromList
@@ -622,7 +653,7 @@ classify =
622653 , ("TWO",(2, 2.2))
623654 ]
624655 in Stream.fold
625− (F.classify (FL.lmap snd FL.toList))
656+ (Fold.classify (Fold.lmap snd Fold.toList))
626657 input
627658 `shouldReturn`
628659 Data.Map.fromList
@@ -631,8 +662,8 @@ classify =
631662splitAt :: Expectation
632663splitAt =
633664 Stream.fold
634− (F.splitAt 6 FL.toList FL.toList)
635− (Stream.fromList "Hello World!")
665+ (Fold.splitAt 6 Fold.toList Fold.toList)
666+ (Stream.fromList "Hello World!")
636667 `shouldReturn`
637668 ("Hello ","World!")
638669
@@ -641,8 +672,8 @@ scan = forAll (listOf (chooseInt (0, 100))) $ \lst ->
641672 monadicIO $ do
642673 v1 :: [Int] <-
643674 run
644− $ S.fold (F.scan FL.sum FL.toList)
645− $ S.fromList lst
675+ $ Stream.fold (Fold.scan Fold.sum Fold.toList)
676+ $ Stream.fromList lst
646677 let v2 = scanl (+) 0 lst
647678 assert (v1 == v2)
648679
@@ -658,10 +689,10 @@ topBy isTop = forAll (listOf (chooseInt (-50, 100))) $ \ls0 ->
658689 n <- liftIO $ generate $ chooseInt (-2, n0 + 2)
659690 if isTop
660691 then do
661− lst <- S.fold (F.top n) (S.fromList ls) >>= MA.toList
692+ lst <- Stream.fold (Fold.top n) (Stream.fromList ls) >>= MArray.toList
662693 assert ((Prelude.take n . Prelude.reverse . sort) ls == lst)
663694 else do
664− lst <- S.fold (F.bottom n) (S.fromList ls) >>= MA.toList
695+ lst <- Stream.fold (Fold.bottom n) (Stream.fromList ls) >>= MArray.toList
665696 assert ((Prelude.take n . sort) ls == lst)
666697
667698top :: Property
@@ -672,10 +703,10 @@ bottom = topBy False
672703
673704nub :: Property
674705nub = monadicIO $ do
675− vals <- Stream.toList
706+ vals <- Stream.fold Fold.toList
676707 $ Stream.catMaybes
677− $ Stream.postscan F.nub
678− $ Stream.fromList [1::Int, 1, 2, 3, 4, 4, 5, 1, 5, 7]
708+ $ Stream.postscan Fold.nub
709+ $ Stream.fromList [1::Int, 1, 2, 3, 4, 4, 5, 1, 5, 7]
679710 assert (vals == [1, 2, 3, 4, 5, 7])
680711
681712moduleName :: String
test/Streamly/Test/Data/Fold/Window.hs+5−4
@@ -3,7 +3,8 @@ module Streamly.Test.Data.Fold.Window (main) where
33import Streamly.Internal.Data.Fold.Window
44import Test.Hspec (hspec, describe, it, runIO)
55import qualified Streamly.Internal.Data.Ring.Foreign as Ring
6−import qualified Streamly.Prelude as S
6+import qualified Streamly.Internal.Data.Stream as S
7+import qualified Streamly.Internal.Data.Fold as Fold
78
89import Prelude hiding (sum, maximum, minimum)
910
@@ -23,7 +24,7 @@ main = hspec $ do
2324 let c = S.fromList testCase
2425 a <- runIO $ S.fold (Ring.slidingWindow winSize f) c
2526 b <- runIO $ S.fold f $ S.drop (numElem - winSize)
26− $ S.map (, Nothing) c
27+ $ fmap (, Nothing) c
2728 let c1 = a - b
2829 it ("should not deviate more than " ++ show deviationLimit)
2930 $ c1 >= -1 * deviationLimit && c1 <= deviationLimit
@@ -40,8 +41,8 @@ main = hspec $ do
4041
4142 testFunc tc f sI sW = do
4243 let c = S.fromList tc
43− a <- runIO $ S.toList $ S.postscan f $ S.map (, Nothing) c
44− b <- runIO $ S.toList $ S.postscan
44+ a <- runIO $ S.fold Fold.toList $ S.postscan f $ fmap (, Nothing) c
45+ b <- runIO $ S.fold Fold.toList $ S.postscan
4546 (Ring.slidingWindow winSize f) c
4647 it "Infinite" $ a == sI
4748 it ("Finite " ++ show winSize) $ b == sW
test/Streamly/Test/Data/List.hs+16−16
@@ -9,10 +9,10 @@ import qualified GHC.Exts as GHC
99
1010#ifdef USE_STREAMLY_LIST
1111import Data.Functor.Identity
12−import Streamly.Internal.Data.List (List(..), pattern Cons, pattern Nil, ZipList(..),
13− fromZipList, toZipList)
14−import Streamly.Prelude (SerialT)
15−import qualified Streamly.Prelude as S
12+import Streamly.Internal.Data.List
13+ (List(..), pattern Cons, pattern Nil, ZipList(..), fromZipList, toZipList)
14+import Streamly.Internal.Data.Stream (Stream)
15+import qualified Streamly.Internal.Data.Stream as S
1616#else
1717import Prelude -- to suppress compiler warning
1818
@@ -39,37 +39,37 @@ main :: IO ()
3939main = hspec $
4040 describe moduleName $ do
4141#ifdef USE_STREAMLY_LIST
42− describe "OverloadedLists for 'SerialT Identity' type" $ do
42+ describe "OverloadedLists for 'Stream Identity' type" $ do
4343 it "Overloaded lists" $ do
44− ([1..3] :: SerialT Identity Int) `shouldBe` S.fromList [1..3]
45− GHC.toList ([1..3] :: SerialT Identity Int) `shouldBe` [1..3]
44+ ([1..3] :: Stream Identity Int) `shouldBe` S.fromList [1..3]
45+ GHC.toList ([1..3] :: Stream Identity Int) `shouldBe` [1..3]
4646
4747 it "Show instance" $ do
48− show (S.fromList [1..3] :: SerialT Identity Int)
48+ show (S.fromList [1..3] :: Stream Identity Int)
4949 `shouldBe` "fromList [1,2,3]"
5050 it "Read instance" $ do
51− (read "fromList [1,2,3]" :: SerialT Identity Int) `shouldBe` [1..3]
51+ (read "fromList [1,2,3]" :: Stream Identity Int) `shouldBe` [1..3]
5252
5353 it "Eq instance" $ do
54− ([1,2,3] :: SerialT Identity Int) == [1,2,3] `shouldBe` True
54+ ([1,2,3] :: Stream Identity Int) == [1,2,3] `shouldBe` True
5555
5656 it "Ord instance" $ do
57− ([1,2,3] :: SerialT Identity Int) > [1,2,1] `shouldBe` True
57+ ([1,2,3] :: Stream Identity Int) > [1,2,1] `shouldBe` True
5858
5959 it "Monad comprehension" $ do
6060 [(x,y) | x <- [1..2], y <- [1..2]] `shouldBe`
61− ([(1,1), (1,2), (2,1), (2,2)] :: SerialT Identity (Int, Int))
61+ ([(1,1), (1,2), (2,1), (2,2)] :: Stream Identity (Int, Int))
6262
63− it "Foldable (sum)" $ sum ([1..3] :: SerialT Identity Int)
63+ it "Foldable (sum)" $ sum ([1..3] :: Stream Identity Int)
6464 `shouldBe` 6
6565
6666 it "Traversable (mapM)" $
67− mapM return ([1..10] :: SerialT Identity Int)
67+ mapM return ([1..10] :: Stream Identity Int)
6868 `shouldReturn` [1..10]
6969
70− describe "OverloadedStrings for 'SerialT Identity' type" $ do
70+ describe "OverloadedStrings for 'Stream Identity' type" $ do
7171 it "overloaded strings" $ do
72− ("hello" :: SerialT Identity Char) `shouldBe` S.fromList "hello"
72+ ("hello" :: Stream Identity Char) `shouldBe` S.fromList "hello"
7373#endif
7474
7575 describe "OverloadedLists for List type" $ do
test/Streamly/Test/Data/Parser.hs+14−10
@@ -18,7 +18,7 @@ import qualified Prelude
1818import qualified Streamly.Internal.Data.Array.Unboxed as A
1919import qualified Streamly.Internal.Data.Fold as FL
2020import qualified Streamly.Internal.Data.Parser as P
21−import qualified Streamly.Internal.Data.Stream.IsStream as S
21+import qualified Streamly.Internal.Data.Stream as S
2222import qualified Test.Hspec as H
2323
2424#if MIN_VERSION_QuickCheck(2,14,0)
@@ -36,7 +36,6 @@ chooseAny = MkGen (\r _ -> let (x,_) = random r in x)
3636
3737#endif
3838
39−
4039maxTestCount :: Int
4140maxTestCount = 100
4241
@@ -482,7 +481,7 @@ parseManyWordQuotedBy =
482481 spc _ = False
483482
484483 parser = P.wordQuotedBy kQ esc lQ rQ fromLQ spc FL.toList
485− result <- H.runIO $ S.toList $ S.parseMany parser inpStrm
484+ result <- H.runIO $ S.fold FL.toList $ S.parseMany parser inpStrm
486485 H.it (showCase c) $ result `H.shouldBe` expected
487486
488487 where
@@ -727,7 +726,7 @@ parseMany =
727726 outs <- do
728727 let p = P.fromFold $ FL.take len FL.toList
729728 run
730− $ S.toList
729+ $ S.fold FL.toList
731730 $ S.parseMany p (S.fromList $ concat ins)
732731 listEquals (==) outs ins
733732
@@ -781,7 +780,7 @@ parseMany2Events =
781780 monadicIO $ do
782781 xs <-
783782 ( run
784− $ S.toList
783+ $ S.fold FL.toList
785784 $ S.parseMany readOneEvent
786785 $ S.fromList (concat (replicate 2 event))
787786 )
@@ -801,7 +800,7 @@ manyEqParseMany =
801800 monadicIO $ do
802801 let strm = S.fromList lst
803802 r1 <- run $ S.parse (P.many (split i) FL.toList) strm
804− r2 <- run $ S.toList $ S.parseMany (split i) strm
803+ r2 <- run $ S.fold FL.toList $ S.parseMany (split i) strm
805804 assert $ r1 == r2
806805
807806 where
@@ -829,6 +828,11 @@ takeEndBy1 =
829828 else [x]
830829 takeWhileAndFirstFail _ [] = []
831830
831+splitWithSuffix
832+ :: Monad m
833+ => (a -> Bool) -> FL.Fold m a b -> S.Stream m a -> S.Stream m b
834+splitWithSuffix predicate f = S.foldMany (FL.takeEndBy predicate f)
835+
832836takeEndBy2 :: Property
833837takeEndBy2 =
834838 forAll (listOf (chooseInt (0, 1))) $ \ls ->
@@ -838,7 +842,7 @@ takeEndBy2 =
838842 predicate = (==0)
839843
840844 eitherParsedList =
841− S.toList $
845+ S.fold FL.toList $
842846 S.parseMany (P.takeEndBy predicate prsr) strm
843847
844848 where
@@ -850,12 +854,12 @@ takeEndBy2 =
850854 [] -> return []
851855 _ ->
852856 if last ls == 0
853− then S.toList $ S.append strm1 (S.fromList [])
854− else S.toList strm1
857+ then S.fold FL.toList $ S.append strm1 (S.fromList [])
858+ else S.fold FL.toList strm1
855859
856860 where
857861
858− strm1 = S.splitWithSuffix predicate FL.toList strm
862+ strm1 = splitWithSuffix predicate FL.toList strm
859863 in
860864 case eitherParsedList of
861865 Left _ -> property False
test/Streamly/Test/Data/Parser/ParserD.hs+9−5
@@ -17,7 +17,7 @@ import qualified Streamly.Internal.Data.Fold as FL
1717import qualified Streamly.Internal.Data.Parser.ParserD as P
1818import qualified Streamly.Internal.Data.Producer.Source as Source
1919import qualified Streamly.Internal.Data.Producer as Producer
20−import qualified Streamly.Internal.Data.Stream.IsStream as S
20+import qualified Streamly.Internal.Data.Stream as S
2121import qualified Streamly.Internal.Data.Stream.StreamD as D
2222import qualified Streamly.Internal.Data.Unfold as Unfold
2323import qualified Test.Hspec as H
@@ -28,6 +28,7 @@ import Prelude hiding (sequence)
2828
2929import Test.QuickCheck (chooseAny)
3030
31+
3132#else
3233
3334import System.Random (Random(random))
@@ -54,6 +55,9 @@ max_value = 10000
5455max_length :: Int
5556max_length = 1000
5657
58+toList :: Monad m => S.Stream m a -> m [a]
59+toList = S.fold FL.toList
60+
5761-- Accumulator Tests
5862
5963fromFold :: Property
@@ -602,7 +606,7 @@ parseMany =
602606 monadicIO $ do
603607 outs <-
604608 ( run
605− $ S.toList
609+ $ toList
606610 $ S.parseManyD
607611 (P.fromFold $ FL.take len FL.toList) (S.fromList $ concat ins)
608612 )
@@ -621,7 +625,7 @@ parseUnfold = do
621625 <*> chooseInt (1, len)
622626 <*> chooseInt (1, len)) $ \(ls, clen, tlen) ->
623627 monadicIO $ do
624− arrays <- S.toList $ S.arraysOf clen (S.fromList ls)
628+ arrays <- toList $ S.arraysOf clen (S.fromList ls)
625629 let src = Source.source (Just (Producer.OuterLoop arrays))
626630 let parser = P.fromFold (FL.take tlen FL.toList)
627631 let readSrc =
@@ -630,7 +634,7 @@ parseUnfold = do
630634 let streamParser =
631635 Producer.simplify (Source.parseManyD parser readSrc)
632636 xs <- run
633− $ S.toList
637+ $ toList
634638 $ S.unfoldMany Unfold.fromList
635639 $ S.unfold streamParser src
636640
@@ -697,7 +701,7 @@ parseMany2Events =
697701 monadicIO $ do
698702 xs <-
699703 ( run
700− $ S.toList
704+ $ toList
701705 $ S.parseManyD readOneEvent
702706 $ S.fromList (concat (replicate 2 event))
703707 )
test/Streamly/Test/Data/Unfold.hs+4−6
@@ -13,17 +13,15 @@ import Streamly.Internal.Data.Unfold (Unfold)
1313
1414import qualified Data.List as List
1515import qualified Prelude
16−import qualified Streamly.Data.Unfold as UF
1716import qualified Streamly.Internal.Data.Fold as Fold
1817import qualified Streamly.Internal.Data.Unfold as UF
19−import qualified Streamly.Internal.Data.Stream.IsStream as S
18+import qualified Streamly.Internal.Data.Stream as S
2019import qualified Streamly.Internal.Data.Stream.StreamD as D
2120import qualified Streamly.Internal.Data.Stream.StreamK as K
2221
2322import Control.Monad.Trans.State.Strict
2423import Data.Functor.Identity
2524import Prelude hiding (const, take, drop, concat, mapM)
26−import Streamly.Prelude (SerialT)
2725import Test.Hspec as H
2826import Test.Hspec.QuickCheck
2927import Test.QuickCheck
@@ -43,7 +41,7 @@ testUnfoldM unf seed si sf lst = evalState action si
4341 where
4442
4543 action = do
46− x <- S.toList $ S.unfold unf seed
44+ x <- S.fold Fold.toList $ S.unfold unf seed
4745 y <- get
4846 return $ x == lst && y == sf
4947
@@ -57,7 +55,7 @@ testUnfold unf seed lst = runIdentity action
5755 where
5856
5957 action = do
60− x <- S.toList $ S.unfold unf seed
58+ x <- S.fold Fold.toList $ S.unfold unf seed
6159 return $ x == lst
6260
6361testUnfoldD :: Unfold Identity a Int -> a -> [Int] -> Bool
@@ -112,7 +110,7 @@ fromStream =
112110 $ \list ->
113111 testUnfoldD
114112 UF.fromStream
115− (S.fromList list :: SerialT Identity Int)
113+ (S.fromList list :: S.Stream Identity Int)
116114 list
117115
118116fromStreamD :: Property
test/streamly-tests.cabal+83−19
@@ -40,6 +40,11 @@ flag opt
4040 manual: True
4141 default: True
4242
43+flag test-core
44+ description: Test only core package
45+ manual: True
46+ default: False
47+
4348-------------------------------------------------------------------------------
4449-- Common stanzas
4550-------------------------------------------------------------------------------
@@ -139,21 +144,23 @@ common optimization-options
139144
140145common test-dependencies
141146 build-depends:
142− streamly
143− , streamly-core
144− , base >= 4.9 && < 4.17
145− , containers >= 0.5 && < 0.7
146− , exceptions >= 0.8 && < 0.11
147− , ghc
148− , hspec >= 2.0 && < 2.10
149− , mtl >= 2.2 && < 2.3
150− , random >= 1.0.0 && < 1.3
151− , transformers >= 0.4 && < 0.7
152− , QuickCheck >= 2.13 && < 2.15
153− , directory >= 1.2.2 && < 1.4
154− , filepath >= 1.4.1 && < 1.5
155− , temporary >= 1.3 && < 1.4
156− , network >= 3.1 && < 3.2
147+ streamly-core
148+ , base >= 4.9 && < 4.17
149+ , containers >= 0.5 && < 0.7
150+ , exceptions >= 0.8 && < 0.11
151+ , ghc
152+ , hspec >= 2.0 && < 2.10
153+ , mtl >= 2.2 && < 2.3
154+ , random >= 1.0.0 && < 1.3
155+ , transformers >= 0.4 && < 0.7
156+ , QuickCheck >= 2.13 && < 2.15
157+ , directory >= 1.2.2 && < 1.4
158+ , filepath >= 1.4.1 && < 1.5
159+ , temporary >= 1.3 && < 1.4
160+ , network >= 3.1 && < 3.2
161+
162+ if !flag(test-core)
163+ build-depends: streamly
157164
158165 if flag(fusion-plugin) && !impl(ghcjs) && !impl(ghc < 8.6)
159166 build-depends:
@@ -173,7 +180,8 @@ library
173180 import: lib-options, test-dependencies
174181 hs-source-dirs: lib
175182 exposed-modules: Streamly.Test.Common
176− , Streamly.Test.Prelude.Common
183+ if !flag(test-core)
184+ exposed-modules: Streamly.Test.Prelude.Common
177185 if flag(limit-build-mem)
178186 ghc-options: +RTS -M1500M -RTS
179187
@@ -222,23 +230,37 @@ test-suite Data.Array
222230 type: exitcode-stdio-1.0
223231 main-is: Streamly/Test/Data/Array.hs
224232 ghc-options: -main-is Streamly.Test.Data.Array.main
233+ if flag(test-core)
234+ buildable: False
225235
226236test-suite Data.Array.Unboxed
227237 import: test-options
228238 type: exitcode-stdio-1.0
229239 main-is: Streamly/Test/Data/Array/Unboxed.hs
230240 ghc-options: -main-is Streamly.Test.Data.Array.Unboxed.main
241+ if flag(test-core)
242+ buildable: False
243+
244+test-suite Data.Array.Unboxed.Mut
245+ import: test-options
246+ type: exitcode-stdio-1.0
247+ main-is: Streamly/Test/Data/Array/Unboxed/Mut.hs
248+ ghc-options: -main-is Streamly.Test.Data.Array.Unboxed.Mut.main
231249
232250test-suite Data.Ring.Unboxed
233251 import: test-options
234252 type: exitcode-stdio-1.0
235253 main-is: Streamly/Test/Data/Ring/Unboxed.hs
236254 ghc-options: -main-is Streamly.Test.Data.Ring.Unboxed.main
255+ if flag(test-core)
256+ buildable: False
237257
238258test-suite Data.Array.Stream.Foreign
239259 import: test-options
240260 type: exitcode-stdio-1.0
241261 main-is: Streamly/Test/Data/Array/Stream/Foreign.hs
262+ if flag(test-core)
263+ buildable: False
242264
243265test-suite Data.Fold
244266 import: test-options
@@ -270,6 +292,8 @@ test-suite Data.SmallArray
270292 type: exitcode-stdio-1.0
271293 main-is: Streamly/Test/Data/SmallArray.hs
272294 ghc-options: -main-is Streamly.Test.Data.SmallArray.main
295+ if flag(test-core)
296+ buildable: False
273297
274298test-suite Data.Unfold
275299 import: test-options
@@ -282,6 +306,8 @@ test-suite FileSystem.Event
282306 ghc-options: -main-is Streamly.Test.FileSystem.Event
283307 main-is: Streamly/Test/FileSystem/Event.hs
284308 other-modules: Streamly.Test.FileSystem.Event.Common
309+ if flag(test-core)
310+ buildable: False
285311
286312test-suite FileSystem.Event.Darwin
287313 import: test-options
@@ -292,6 +318,8 @@ test-suite FileSystem.Event.Darwin
292318 ghc-options: -main-is Streamly.Test.FileSystem.Event.Darwin
293319 if !os(darwin)
294320 buildable: False
321+ if flag(test-core)
322+ buildable: False
295323
296324test-suite FileSystem.Event.Linux
297325 import: test-options
@@ -302,6 +330,8 @@ test-suite FileSystem.Event.Linux
302330 ghc-options: -main-is Streamly.Test.FileSystem.Event.Linux
303331 if !os(linux)
304332 buildable: False
333+ if flag(test-core)
334+ buildable: False
305335
306336test-suite FileSystem.Event.Windows
307337 import: test-options
@@ -312,40 +342,54 @@ test-suite FileSystem.Event.Windows
312342 ghc-options: -main-is Streamly.Test.FileSystem.Event.Windows
313343 if !os(windows)
314344 buildable: False
345+ if flag(test-core)
346+ buildable: False
315347
316348test-suite FileSystem.Handle
317349 import: test-options
318350 type: exitcode-stdio-1.0
319351 main-is: Streamly/Test/FileSystem/Handle.hs
320352 ghc-options: -main-is Streamly.Test.FileSystem.Handle.main
353+ if flag(test-core)
354+ buildable: False
321355
322356test-suite Network.Inet.TCP
323357 import: test-options
324358 type: exitcode-stdio-1.0
325359 main-is: Streamly/Test/Network/Inet/TCP.hs
360+ if flag(test-core)
361+ buildable: False
326362
327363test-suite Network.Socket
328364 import: test-options
329365 type: exitcode-stdio-1.0
330366 main-is: Streamly/Test/Network/Socket.hs
367+ if flag(test-core)
368+ buildable: False
331369
332370test-suite Prelude
333371 import: test-options
334372 type: exitcode-stdio-1.0
335373 main-is: Streamly/Test/Prelude.hs
336374 ghc-options: -main-is Streamly.Test.Prelude.main
375+ if flag(test-core)
376+ buildable: False
337377
338378test-suite Prelude.Ahead
339379 import: test-options
340380 type: exitcode-stdio-1.0
341381 main-is: Streamly/Test/Prelude/Ahead.hs
342382 ghc-options: -main-is Streamly.Test.Prelude.Ahead.main
383+ if flag(test-core)
384+ buildable: False
343385
344386test-suite Prelude.Async
345387 import: test-options
346388 type: exitcode-stdio-1.0
347389 main-is: Streamly/Test/Prelude/Async.hs
348390 ghc-options: -main-is Streamly.Test.Prelude.Async.main
391+ if flag(test-core)
392+ buildable: False
349393
350394test-suite Prelude.Concurrent
351395 import: test-options
@@ -354,18 +398,24 @@ test-suite Prelude.Concurrent
354398 ghc-options: -main-is Streamly.Test.Prelude.Concurrent.main
355399 if flag(limit-build-mem)
356400 ghc-options: +RTS -M2000M -RTS
401+ if flag(test-core)
402+ buildable: False
357403
358404test-suite Prelude.Fold
359405 import: test-options
360406 type: exitcode-stdio-1.0
361407 main-is: Streamly/Test/Prelude/Fold.hs
362408 ghc-options: -main-is Streamly.Test.Prelude.Fold.main
409+ if flag(test-core)
410+ buildable: False
363411
364412test-suite Prelude.Parallel
365413 import: test-options
366414 type: exitcode-stdio-1.0
367415 main-is: Streamly/Test/Prelude/Parallel.hs
368416 ghc-options: -main-is Streamly.Test.Prelude.Parallel.main
417+ if flag(test-core)
418+ buildable: False
369419
370420test-suite Prelude.Rate
371421 import:always-optimized
@@ -376,6 +426,8 @@ test-suite Prelude.Rate
376426 buildable: True
377427 else
378428 buildable: False
429+ if flag(test-core)
430+ buildable: False
379431
380432test-suite Prelude.Serial
381433 import: test-options
@@ -384,23 +436,31 @@ test-suite Prelude.Serial
384436 ghc-options: -main-is Streamly.Test.Prelude.Serial.main
385437 if flag(limit-build-mem)
386438 ghc-options: +RTS -M1500M -RTS
439+ if flag(test-core)
440+ buildable: False
387441
388442test-suite Prelude.Top
389443 import: test-options
390444 type: exitcode-stdio-1.0
391445 main-is: Streamly/Test/Prelude/Top.hs
446+ if flag(test-core)
447+ buildable: False
392448
393449test-suite Prelude.WAsync
394450 import: test-options
395451 type: exitcode-stdio-1.0
396452 main-is: Streamly/Test/Prelude/WAsync.hs
397453 ghc-options: -main-is Streamly.Test.Prelude.WAsync.main
454+ if flag(test-core)
455+ buildable: False
398456
399457test-suite Prelude.WSerial
400458 import: test-options
401459 type: exitcode-stdio-1.0
402460 main-is: Streamly/Test/Prelude/WSerial.hs
403461 ghc-options: -main-is Streamly.Test.Prelude.WSerial.main
462+ if flag(test-core)
463+ buildable: False
404464
405465test-suite Prelude.ZipAsync
406466 import: test-options
@@ -409,27 +469,31 @@ test-suite Prelude.ZipAsync
409469 ghc-options: -main-is Streamly.Test.Prelude.ZipAsync.main
410470 if flag(limit-build-mem)
411471 ghc-options: +RTS -M750M -RTS
472+ if flag(test-core)
473+ buildable: False
412474
413475test-suite Prelude.ZipSerial
414476 import: test-options
415477 type: exitcode-stdio-1.0
416478 main-is: Streamly/Test/Prelude/ZipSerial.hs
417479 ghc-options: -main-is Streamly.Test.Prelude.ZipSerial.main
480+ if flag(test-core)
481+ buildable: False
418482
419483test-suite Unicode.Stream
420484 import: test-options
421485 type: exitcode-stdio-1.0
422486 main-is: Streamly/Test/Unicode/Stream.hs
423487 ghc-options: -main-is Streamly.Test.Unicode.Stream.main
488+ if flag(test-core)
489+ buildable: False
424490
425491test-suite Unicode.Char
426492 import: test-options
427493 type: exitcode-stdio-1.0
428494 main-is: Streamly/Test/Unicode/Char.hs
429495 ghc-options: -main-is Streamly.Test.Unicode.Char.main
430− if flag(dev)
431− buildable: True
432− else
496+ if flag(test-core) || !flag(dev)
433497 buildable: False
434498
435499test-suite version-bounds