@@ -10,6 +10,13 @@
1010
1111-- This is a common array test module that gets included in different
1212-- Array test modules with the corresponding macro defined.
13+--
14+-- Meanings of CPP macros:
15+-- Default => Data.Array
16+-- TEST_ARRAY => Data.Array.Foreign
17+-- TEST_SMALL_ARRAY => Data.SmallArray
18+-- DATA_ARRAY_PRIM => Data.Array.Prim
19+-- DATA_ARRAY_PRIM_PINNED => Data.Array.Prim.Pinned
1320
1421import Foreign.Storable (Storable(..))
1522
@@ -18,10 +25,18 @@ import Test.QuickCheck (Property, forAll, Gen, vectorOf, arbitrary, choose)
1825import Test.QuickCheck.Monadic (monadicIO, assert, run)
1926import Test.Hspec as H
2027
28+import Streamly.Data.Fold (Fold)
2129import Streamly.Prelude (SerialT)
2230import Streamly.Test.Common (listEquals)
2331
2432import qualified Streamly.Prelude as S
33+
34+#if defined(TEST_ARRAY) ||\
35+ defined(DATA_ARRAY_PRIM) ||\
36+ defined(DATA_ARRAY_PRIM_PINNED)
37+import qualified Streamly.Internal.Data.Fold as Fold
38+#endif
39+
2540#ifdef TEST_SMALL_ARRAY
2641import qualified Streamly.Internal.Data.SmallArray as A
2742type Array = A.SmallArray
@@ -31,18 +46,15 @@ import Data.Word(Word8)
3146import qualified Streamly.Internal.Data.Array.Foreign as A
3247import qualified Streamly.Internal.Data.Array.Foreign.Type as A
3348import qualified Streamly.Internal.Data.Array.Foreign.Mut.Type as MA
34−import qualified Streamly.Internal.Data.Stream.IsStream as IP
3549import qualified Streamly.Internal.Data.Array.Stream.Foreign as AS
3650type Array = A.Array
3751#elif defined(DATA_ARRAY_PRIM_PINNED)
3852import qualified Streamly.Internal.Data.Array.Prim.Pinned as A
3953import qualified Streamly.Internal.Data.Array.Prim.Pinned.Type as A
40−import qualified Streamly.Internal.Data.Stream.IsStream as IP
4154type Array = A.Array
4255#elif defined(DATA_ARRAY_PRIM)
4356import qualified Streamly.Internal.Data.Array.Prim as A
4457import qualified Streamly.Internal.Data.Array.Prim.Type as A
45−import qualified Streamly.Internal.Data.Stream.IsStream as IP
4658type Array = A.Array
4759#else
4860import qualified Streamly.Internal.Data.Array as A
@@ -166,25 +178,17 @@ testFromList =
166178 assert (xs == list)
167179#endif
168180
169−#if defined(TEST_ARRAY) ||\
170− defined(DATA_ARRAY_PRIM) ||\
171− defined(DATA_ARRAY_PRIM_PINNED)
172−
173−testArraysOf :: Property
174−testArraysOf =
181+foldManyWith :: (Int -> Fold IO Int (Array Int)) -> Property
182+foldManyWith f =
175183 forAll (choose (0, maxArrLen)) $ \len ->
176184 forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
177185 monadicIO $ do
178186 xs <- run
179187 $ S.toList
180188 $ S.unfoldMany A.read
181− $ arraysOf 240
189+ $ S.foldMany (f 240)
182190 $ S.fromList list
183191 assert (xs == list)
184− where
185− arraysOf n = IP.chunksOf n (A.writeNUnsafe n)
186−
187−#endif
188192
189193#ifdef TEST_ARRAY
190194
@@ -261,8 +265,11 @@ main =
261265#if defined(TEST_ARRAY) ||\
262266 defined(DATA_ARRAY_PRIM) ||\
263267 defined(DATA_ARRAY_PRIM_PINNED)
264− prop "arraysOf concats to original" testArraysOf
268+ prop "foldMany with writeNUnsafe concats to original"
269+ (foldManyWith (\n -> Fold.take n (A.writeNUnsafe n)))
265270#endif
271+ prop "foldMany with writeN concats to original"
272+ (foldManyWith A.writeN)
266273
267274#ifdef TEST_ARRAY
268275 prop "AS.concat . (A.fromList . (:[]) <$>) === id" $ concatArrayW8