@@ -8,5 +8,48 @@
88
99module Streamly.Test.Data.Array.Prim.Pinned where
1010
11−#define DATA_ARRAY_PRIM_PINNED
12−#include "Streamly/Test/Common/Array.hs"
11+#include "Streamly/Test/Data/Array/CommonImports.hs"
12+
13+import qualified Streamly.Internal.Data.Fold as Fold
14+import qualified Streamly.Internal.Data.Array.Prim as A
15+import qualified Streamly.Internal.Data.Array.Prim.Type as A
16+type Array = A.Array
17+
18+moduleName :: String
19+moduleName = "Data.Array.Prim.Pinned"
20+
21+#include "Streamly/Test/Data/Array/Common.hs"
22+
23+testFromStreamToStream :: Property
24+testFromStreamToStream = genericTestFromTo (const A.fromStream) A.toStream (==)
25+
26+testFoldUnfold :: Property
27+testFoldUnfold = genericTestFromTo (const (S.fold A.write)) (S.unfold A.read) (==)
28+
29+testFromList :: Property
30+testFromList =
31+ forAll (choose (0, maxArrLen)) $ \len ->
32+ forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
33+ monadicIO $ do
34+ let arr = A.fromList list
35+ xs <- run $ S.toList $ (S.unfold A.read) arr
36+ assert (xs == list)
37+
38+testLengthFromStream :: Property
39+testLengthFromStream = genericTestFrom (const A.fromStream)
40+
41+
42+main :: IO ()
43+main =
44+ hspec $
45+ H.parallel $
46+ modifyMaxSuccess (const maxTestCount) $ do
47+ describe moduleName $ do
48+ commonMain
49+ describe "Construction" $ do
50+ prop "length . fromStream === n" testLengthFromStream
51+ prop "toStream . fromStream === id" testFromStreamToStream
52+ prop "read . write === id" testFoldUnfold
53+ prop "fromList" testFromList
54+ prop "foldMany with writeNUnsafe concats to original"
55+ (foldManyWith (\n -> Fold.take n (A.writeNUnsafe n)))