on master help sign in
Refactor, cleanup, hlint - fold and handle tests
c3b506bHarendra Kumar
.hlint.ignore−1
@@ -26,7 +26,6 @@ test/Streamly/Test/Data/Array.hs
26test/Streamly/Test/Data/Array/Prim.hs
26test/Streamly/Test/Data/Array/Prim.hs
27test/Streamly/Test/Data/Array/Prim/Pinned.hs
27test/Streamly/Test/Data/Array/Prim/Pinned.hs
28test/Streamly/Test/Data/Array/Storable/Foreign.hs
28test/Streamly/Test/Data/Array/Storable/Foreign.hs
29−test/Streamly/Test/Data/Fold.hs
30test/Streamly/Test/Data/Parser.hs
29test/Streamly/Test/Data/Parser.hs
31test/Streamly/Test/Data/Parser/ParserD.hs
30test/Streamly/Test/Data/Parser/ParserD.hs
32test/Streamly/Test/Data/SmallArray.hs
31test/Streamly/Test/Data/SmallArray.hs
bin/targets.sh+1−1
@@ -105,6 +105,6 @@ GROUP_TARGETS="\
105INDIVIDUAL_TARGETS="\
105INDIVIDUAL_TARGETS="\
106 Data.Unfold \
106 Data.Unfold \
107 Unicode.Stream \
107 Unicode.Stream \
108− `bench_only FileSystem.Handle` \
108+ FileSystem.Handle \
109 `test_only FileSystem.Event` \
109 `test_only FileSystem.Event` \
110 `test_only version-bounds`"
110 `test_only version-bounds`"
hie.yaml+2
@@ -80,6 +80,8 @@ cradle:
80 component: "test:Unicode.Stream"
80 component: "test:Unicode.Stream"
81 - path: "./test/Streamly/Test/FileSystem/Event.hs"
81 - path: "./test/Streamly/Test/FileSystem/Event.hs"
82 component: "test:FileSystem.Event"
82 component: "test:FileSystem.Event"
83+ - path: "./test/Streamly/Test/FileSystem/Handle.hs"
84+ component: "test:FileSystem.Handle"
83 - path: "./test/version-bounds.hs"
85 - path: "./test/version-bounds.hs"
84 component: "test:version-bounds"
86 component: "test:version-bounds"
85
87
test/Streamly/Test/Common/Array.hs+2−2
@@ -219,13 +219,13 @@ main =
219 prop "toStreamRev . writeN === reverse" testFoldNToStreamRev
219 prop "toStreamRev . writeN === reverse" testFoldNToStreamRev
220 prop "read . fromStreamN === id" testFromStreamNUnfold
220 prop "read . fromStreamN === id" testFromStreamNUnfold
221 prop "toStream . fromStreamN === id" testFromStreamNToStream
221 prop "toStream . fromStreamN === id" testFromStreamNToStream
222− prop "First N elements of a list" testFromListN
222+ prop "fromListN" testFromListN
223
223
224#ifndef TEST_SMALL_ARRAY
224#ifndef TEST_SMALL_ARRAY
225 prop "length . fromStream === n" testLengthFromStream
225 prop "length . fromStream === n" testLengthFromStream
226 prop "toStream . fromStream === id" testFromStreamToStream
226 prop "toStream . fromStream === id" testFromStreamToStream
227 prop "read . write === id" testFoldUnfold
227 prop "read . write === id" testFoldUnfold
228− prop "From a list" testFromList
228+ prop "fromList" testFromList
229#endif
229#endif
230
230
231#if defined(TEST_ARRAY) ||\
231#if defined(TEST_ARRAY) ||\
test/Streamly/Test/Data/Fold.hs+45−42
@@ -1,8 +1,7 @@
1module Main (main) where
1module Main (main) where
2
2
3−import Prelude hiding
4− (maximum, minimum, elem, notElem, null, product, sum, head, last)
5import Data.Semigroup (Sum(..), getSum)
3import Data.Semigroup (Sum(..), getSum)
4+import Streamly.Test.Common (checkListEqual)
6import Test.QuickCheck
5import Test.QuickCheck
7 ( Gen
6 ( Gen
8 , Property
7 , Property
@@ -15,15 +14,15 @@ import Test.QuickCheck
15 , vectorOf
14 , vectorOf
16 , withMaxSuccess
15 , withMaxSuccess
17 )
16 )
18−import Prelude hiding
19− (maximum, minimum, elem, notElem, null, product, sum, head, last)
20−import Streamly.Test.Common (checkListEqual)
21import Test.QuickCheck.Monadic (monadicIO, assert, run)
17import Test.QuickCheck.Monadic (monadicIO, assert, run)
22
18
19+import qualified Prelude
23import qualified Streamly.Internal.Data.Fold as F
20import qualified Streamly.Internal.Data.Fold as F
24import qualified Streamly.Prelude as S
21import qualified Streamly.Prelude as S
25import qualified Streamly.Data.Fold as FL
22import qualified Streamly.Data.Fold as FL
26
23
24+import Prelude hiding
25+ (maximum, minimum, elem, notElem, null, product, sum, head, last)
27import Test.Hspec as H
26import Test.Hspec as H
28import Test.Hspec.QuickCheck
27import Test.Hspec.QuickCheck
29
28
@@ -70,10 +69,11 @@ length :: [Int] -> Expectation
70length ls = S.fold FL.length (S.fromList ls) `shouldReturn` Prelude.length ls
69length ls = S.fold FL.length (S.fromList ls) `shouldReturn` Prelude.length ls
71
70
72sum :: [Int] -> Expectation
71sum :: [Int] -> Expectation
73−sum ls = S.fold FL.sum (S.fromList ls) `shouldReturn` foldl (+) 0 ls
72+sum ls = S.fold FL.sum (S.fromList ls) `shouldReturn` Prelude.sum ls
74
73
75product :: [Int] -> Expectation
74product :: [Int] -> Expectation
75+product ls =
76−product ls = S.fold FL.product (S.fromList ls) `shouldReturn` foldl (*) 1 ls
76+ S.fold FL.product (S.fromList ls) `shouldReturn` Prelude.product ls
77
77
78lesser :: (a -> a -> Ordering) -> a -> a -> a
78lesser :: (a -> a -> Ordering) -> a -> a -> a
79lesser f x y = if f x y == LT then x else y
79lesser f x y = if f x y == LT then x else y
@@ -90,8 +90,7 @@ foldMaybe f acc ls =
90maximumBy :: (Ord a, Show a) => a -> (a -> a -> Ordering) -> [a] -> Expectation
90maximumBy :: (Ord a, Show a) => a -> (a -> a -> Ordering) -> [a] -> Expectation
91maximumBy genmin f ls =
91maximumBy genmin f ls =
92 S.fold (FL.maximumBy f) (S.fromList ls)
92 S.fold (FL.maximumBy f) (S.fromList ls)
93− `shouldReturn`
94− foldMaybe (greater f) genmin ls
93+ `shouldReturn` foldMaybe (greater f) genmin ls
95
94
96maximum :: (Show a, Ord a) => a -> [a] -> Expectation
95maximum :: (Show a, Ord a) => a -> [a] -> Expectation
97maximum genmin ls =
96maximum genmin ls =
@@ -129,16 +128,16 @@ mapMaybe ls =
129 in S.fold f (S.fromList ls) `shouldReturn` filter even ls
128 in S.fold f (S.fromList ls) `shouldReturn` filter even ls
130
129
131nth :: Int -> [a] -> Maybe a
130nth :: Int -> [a] -> Maybe a
132−nth idx (x:xs) = if idx == 0
131+nth idx (x : xs)
133− then Just x
132+ | idx == 0 = Just x
134− else if idx < 0
135− then Nothing
133+ | idx < 0 = Nothing
136− else nth (idx - 1) xs
134+ | otherwise = nth (idx - 1) xs
137nth _ [] = Nothing
135nth _ [] = Nothing
138
136
139index :: Int -> [String] -> Expectation
137index :: Int -> [String] -> Expectation
138+index idx ls =
140−index idx ls = let x = S.fold (FL.index idx) (S.fromList ls)
139+ let x = S.fold (FL.index idx) (S.fromList ls)
141− in x `shouldReturn` (nth idx ls)
140+ in x `shouldReturn` nth idx ls
142
141
143find :: (Show a, Eq a) => (a -> Bool) -> [a] -> Expectation
142find :: (Show a, Eq a) => (a -> Bool) -> [a] -> Expectation
144find f ls = do
143find f ls = do
@@ -152,7 +151,7 @@ find f ls = do
152 in fld `shouldReturn` False
151 in fld `shouldReturn` False
153
152
154neg :: (a -> Bool) -> a -> Bool
153neg :: (a -> Bool) -> a -> Bool
155−neg f x = if f x == True then False else True
154+neg f x = not (f x)
156
155
157findIndex :: (a -> Bool) -> [a] -> Expectation
156findIndex :: (a -> Bool) -> [a] -> Expectation
158findIndex f ls = do
157findIndex f ls = do
@@ -161,16 +160,16 @@ findIndex f ls = do
161 Nothing ->
160 Nothing ->
162 let fld = S.fold (FL.all $ neg f) (S.fromList ls)
161 let fld = S.fold (FL.all $ neg f) (S.fromList ls)
163 in fld `shouldReturn` True
162 in fld `shouldReturn` True
164− Just idx -> if idx == 0
163+ Just idx ->
164+ if idx == 0
165− then
165+ then
166− S.fold (FL.all f) (S.fromList []) `shouldReturn` True
166+ S.fold (FL.all f) (S.fromList []) `shouldReturn` True
167− else
167+ else
168− S.fold (FL.all f) (S.fromList $ (take idx ls))
168+ S.fold (FL.all f) (S.fromList $ take idx ls)
169− `shouldReturn`
169+ `shouldReturn` False
170− False
171
170
172predicate :: Int -> Bool
171predicate :: Int -> Bool
173−predicate x = if x * x < 100 then True else False
172+predicate x = x * x < 100
174
173
175elemIndex :: Int -> [Int] -> Expectation
174elemIndex :: Int -> [Int] -> Expectation
176elemIndex elm ls = do
175elemIndex elm ls = do
@@ -180,13 +179,17 @@ elemIndex elm ls = do
180 let fld = S.fold (FL.any (== elm)) (S.fromList ls)
179 let fld = S.fold (FL.any (== elm)) (S.fromList ls)
181 in fld `shouldReturn` False
180 in fld `shouldReturn` False
182 Just idx ->
181 Just idx ->
183− let fld = S.fold (FL.any (== elm)) (S.fromList $ (take idx ls))
182+ let fld = S.fold (FL.any (== elm)) (S.fromList $ take idx ls)
184 in fld `shouldReturn` False
183 in fld `shouldReturn` False
185
184
186null :: [Int] -> Expectation
185null :: [Int] -> Expectation
186+null ls =
187−null ls = S.fold FL.null (S.fromList ls) `shouldReturn` case ls of
187+ S.fold FL.null (S.fromList ls)
188+ `shouldReturn`
189+ case ls of
188− [] -> True
190+ [] -> True
189− _ -> False
191+ _ -> False
192+
190elem :: Int -> [Int] -> Expectation
193elem :: Int -> [Int] -> Expectation
191elem elm ls = do
194elem elm ls = do
192 y <- S.fold (FL.elem elm) (S.fromList ls)
195 y <- S.fold (FL.elem elm) (S.fromList ls)
@@ -201,7 +204,7 @@ notElem elm ls = do
201
204
202all :: (a -> Bool) -> [a] -> Expectation
205all :: (a -> Bool) -> [a] -> Expectation
203all f ls =
206all f ls =
204− S.fold (FL.all f) (S.fromList ls) `shouldReturn` Prelude.and (map f ls)
207+ S.fold (FL.all f) (S.fromList ls) `shouldReturn` Prelude.all f ls
205
208
206any :: (a -> Bool) -> [a] -> Expectation
209any :: (a -> Bool) -> [a] -> Expectation
207any f ls = S.fold (FL.any f) (S.fromList ls) `shouldReturn` Prelude.any f ls
210any f ls = S.fold (FL.any f) (S.fromList ls) `shouldReturn` Prelude.any f ls
@@ -257,7 +260,7 @@ mean =
257
260
258 action ls = do
261 action ls = do
259 v1 <- run $ S.fold FL.mean (S.fromList ls)
262 v1 <- run $ S.fold FL.mean (S.fromList ls)
260− let v2 = (foldl (+) 0 ls) / fromIntegral (Prelude.length ls)
263+ let v2 = Prelude.sum ls / fromIntegral (Prelude.length ls)
261 assert (abs (v1 - v2) < 0.0001)
264 assert (abs (v1 - v2) < 0.0001)
262
265
263stdDev :: Property
266stdDev :: Property
@@ -269,8 +272,8 @@ stdDev =
269
272
270 action ls = do
273 action ls = do
271 v1 <- run $ S.fold FL.stdDev (S.fromList ls)
274 v1 <- run $ S.fold FL.stdDev (S.fromList ls)
272− let avg = (foldl (+) 0 ls) / fromIntegral (Prelude.length ls)
275+ let avg = Prelude.sum ls / fromIntegral (Prelude.length ls)
273− se = (foldl (+) 0 (map (\x -> (x - avg) * (x - avg)) ls))
276+ se = Prelude.sum (fmap (\x -> (x - avg) * (x - avg)) ls)
274 sd = sqrt $ se / fromIntegral (Prelude.length ls)
277 sd = sqrt $ se / fromIntegral (Prelude.length ls)
275 assert (abs (v1 - sd) < 0.0001 )
278 assert (abs (v1 - sd) < 0.0001 )
276
279
@@ -283,8 +286,8 @@ variance =
283
286
284 action ls = do
287 action ls = do
285 v1 <- run $ S.fold FL.variance (S.fromList ls)
288 v1 <- run $ S.fold FL.variance (S.fromList ls)
286− let avg = (foldl (+) 0 ls) / fromIntegral (Prelude.length ls)
289+ let avg = Prelude.sum ls / fromIntegral (Prelude.length ls)
287− se = (foldl (+) 0 (map (\x -> (x - avg) * (x - avg)) ls))
290+ se = Prelude.sum (fmap (\x -> (x - avg) * (x - avg)) ls)
288 vr = se / fromIntegral (Prelude.length ls)
291 vr = se / fromIntegral (Prelude.length ls)
289 assert (abs (v1 - vr) < 0.01 )
292 assert (abs (v1 - vr) < 0.01 )
290
293
@@ -297,7 +300,7 @@ mconcat =
297
300
298 action ls = do
301 action ls = do
299 v1 <- run $ S.fold FL.mconcat (S.map Sum $ S.fromList ls)
302 v1 <- run $ S.fold FL.mconcat (S.map Sum $ S.fromList ls)
300− let v2 = (foldl (+) 0 ls)
303+ let v2 = Prelude.sum ls
301 assert (getSum v1 == v2)
304 assert (getSum v1 == v2)
302
305
303foldMap :: Property
306foldMap :: Property
@@ -309,7 +312,7 @@ foldMap =
309
312
310 action ls = do
313 action ls = do
311 v1 <- run $ S.fold (FL.foldMap Sum) $ S.fromList ls
314 v1 <- run $ S.fold (FL.foldMap Sum) $ S.fromList ls
312− let v2 = (foldl (+) 0 ls)
315+ let v2 = Prelude.sum ls
313 assert (getSum v1 == v2)
316 assert (getSum v1 == v2)
314
317
315foldMapM :: Property
318foldMapM :: Property
@@ -321,7 +324,7 @@ foldMapM =
321
324
322 action ls = do
325 action ls = do
323 v1 <- run $ S.fold (FL.foldMapM (return . Sum)) $ S.fromList ls
326 v1 <- run $ S.fold (FL.foldMapM (return . Sum)) $ S.fromList ls
324− let v2 = (foldl (+) 0 ls)
327+ let v2 = Prelude.sum ls
325 assert (getSum v1 == v2)
328 assert (getSum v1 == v2)
326
329
327lookup :: Property
330lookup :: Property
@@ -363,7 +366,7 @@ teeWithLength =
363
366
364 action ls = do
367 action ls = do
365 v1 <- run $ S.fold (FL.tee FL.sum FL.length) $ S.fromList ls
368 v1 <- run $ S.fold (FL.tee FL.sum FL.length) $ S.fromList ls
366− let v2 = foldl (+) 0 ls
369+ let v2 = Prelude.sum ls
367 v3 = Prelude.length ls
370 v3 = Prelude.length ls
368 assert (v1 == (v2, v3))
371 assert (v1 == (v2, v3))
369
372
@@ -376,7 +379,7 @@ teeWithMax =
376
379
377 action ls = do
380 action ls = do
378 v1 <- run $ S.fold (FL.tee FL.sum FL.maximum) $ S.fromList ls
381 v1 <- run $ S.fold (FL.tee FL.sum FL.maximum) $ S.fromList ls
379− let v2 = foldl (+) 0 ls
382+ let v2 = Prelude.sum ls
380 v3 = foldMaybe (greater compare) intMin ls
383 v3 = foldMaybe (greater compare) intMin ls
381 assert (v1 == (v2, v3))
384 assert (v1 == (v2, v3))
382
385
@@ -389,7 +392,7 @@ distribute =
389
392
390 action ls = do
393 action ls = do
391 v1 <- run $ S.fold (FL.distribute [FL.sum, FL.length]) $ S.fromList ls
394 v1 <- run $ S.fold (FL.distribute [FL.sum, FL.length]) $ S.fromList ls
392− let v2 = foldl (+) 0 ls
395+ let v2 = Prelude.sum ls
393 v3 = Prelude.length ls
396 v3 = Prelude.length ls
394 assert (v1 == [v2, v3])
397 assert (v1 == [v2, v3])
395
398
@@ -418,7 +421,7 @@ main :: IO ()
418main = hspec $
421main = hspec $
419 describe "Fold s" $ do
422 describe "Fold s" $ do
420 prop "RollingHashFirstN" rollingHashFirstN
423 prop "RollingHashFirstN" rollingHashFirstN
421− prop "Index" $ index
424+ prop "Index" index
422 prop "Head" head
425 prop "Head" head
423 prop "Last" last
426 prop "Last" last
424 prop "Length" Main.length
427 prop "Length" Main.length
test/Streamly/Test/FileSystem/Handle.hs+39−36
@@ -26,15 +26,15 @@ import System.IO.Temp (withSystemTempDirectory)
26import Test.QuickCheck (Property, forAll, Gen, vectorOf, choose)
26import Test.QuickCheck (Property, forAll, Gen, vectorOf, choose)
27import Test.QuickCheck.Monadic (monadicIO, assert, run)
27import Test.QuickCheck.Monadic (monadicIO, assert, run)
28
28
29+import qualified Streamly.Data.Fold as Fold
29−import Streamly.FileSystem.Handle as FH
30+import qualified Streamly.FileSystem.Handle as Handle
31+import qualified Streamly.Internal.Data.Stream.IsStream as Stream
32+import qualified Streamly.Internal.Data.Array.Storable.Foreign as Array
33+import qualified Streamly.Internal.Unicode.Stream as Unicode
34+
30import Test.Hspec as H
35import Test.Hspec as H
31import Test.Hspec.QuickCheck
36import Test.Hspec.QuickCheck
32
37
33−import qualified Streamly.Data.Fold as FL
34−import qualified Streamly.Internal.Data.Stream.IsStream as S
35−import qualified Streamly.Internal.Data.Array.Storable.Foreign as A
36−import qualified Streamly.Internal.Unicode.Stream as U
37−
38allocOverhead :: Int
38allocOverhead :: Int
39allocOverhead = 2 * sizeOf (undefined :: Int)
39allocOverhead = 2 * sizeOf (undefined :: Int)
40
40
@@ -51,8 +51,9 @@ maxTestCount = 10
51chooseWord8 :: (Word8, Word8) -> Gen Word8
51chooseWord8 :: (Word8, Word8) -> Gen Word8
52chooseWord8 = choose
52chooseWord8 = choose
53
53
54−utf8ToString :: A.Array Word8 -> String
54+utf8ToString :: Array.Array Word8 -> String
55+utf8ToString =
55−utf8ToString = runIdentity . S.toList . U.decodeUtf8' . A.toStream
56+ runIdentity . Stream.toList . Unicode.decodeUtf8' . Array.toStream
56
57
57testData :: String
58testData :: String
58testData = "This is the test data for FileSystem.Handle ??`!@#$%^&*~~))`]"
59testData = "This is the test data for FileSystem.Handle ??`!@#$%^&*~~))`]"
@@ -60,7 +61,7 @@ testData = "This is the test data for FileSystem.Handle ??`!@#$%^&*~~))`]"
60testDataLarge :: String
61testDataLarge :: String
61testDataLarge = concat $ replicate 6000 testData
62testDataLarge = concat $ replicate 6000 testData
62
63
63−executor :: (Handle -> (SerialT IO Char)) -> IO (SerialT IO Char)
64+executor :: (Handle -> SerialT IO Char) -> IO (SerialT IO Char)
64executor f =
65executor f =
65 withSystemTempDirectory "fs_handle" $ \fp -> do
66 withSystemTempDirectory "fs_handle" $ \fp -> do
66 let fpath = fp </> "tmp_read.txt"
67 let fpath = fp </> "tmp_read.txt"
@@ -70,38 +71,40 @@ executor f =
70
71
71readFromHandle :: IO (SerialT IO Char)
72readFromHandle :: IO (SerialT IO Char)
72readFromHandle =
73readFromHandle =
73− let f = U.decodeUtf8 . S.unfold FH.read
74+ let f = Unicode.decodeUtf8 . Stream.unfold Handle.read
74 in executor f
75 in executor f
75
76
76readWithBufferFromHandle :: IO (SerialT IO Char)
77readWithBufferFromHandle :: IO (SerialT IO Char)
77readWithBufferFromHandle =
78readWithBufferFromHandle =
78 let f1 = (\h -> (1024, h))
79 let f1 = (\h -> (1024, h))
79− f2 = U.decodeUtf8 . S.unfold FH.readWithBufferOf . f1
80+ f2 = Unicode.decodeUtf8 . Stream.unfold Handle.readWithBufferOf . f1
80 in executor f2
81 in executor f2
81
82
82readChunksFromHandle :: IO (SerialT IO Char)
83readChunksFromHandle :: IO (SerialT IO Char)
83readChunksFromHandle =
84readChunksFromHandle =
85+ let f = Unicode.decodeUtf8
84− let f = U.decodeUtf8 . S.concatMap (A.toStream) . S.unfold FH.readChunks
86+ . Stream.concatMap Array.toStream
87+ . Stream.unfold Handle.readChunks
85 in executor f
88 in executor f
86
89
87readChunksWithBuffer :: IO (SerialT IO Char)
90readChunksWithBuffer :: IO (SerialT IO Char)
88readChunksWithBuffer =
91readChunksWithBuffer =
89 let f1 = (\h -> (1024, h))
92 let f1 = (\h -> (1024, h))
90 f2 =
93 f2 =
91− U.decodeUtf8
94+ Unicode.decodeUtf8
92− . S.concatMap (A.toStream)
95+ . Stream.concatMap Array.toStream
93− . S.unfold FH.readChunksWithBufferOf
96+ . Stream.unfold Handle.readChunksWithBufferOf
94 . f1
97 . f1
95 in executor f2
98 in executor f2
96
99
97testRead :: (IsStream t) => IO (t IO Char) -> Property
100testRead :: (IsStream t) => IO (t IO Char) -> Property
98testRead fn = monadicIO $ do
101testRead fn = monadicIO $ do
99− let v2 = (S.fromList testDataLarge)
102+ let v2 = Stream.fromList testDataLarge
100− v1 <- run $ fn
103+ v1 <- run fn
101− res <- run $ S.eqBy (==) v1 v2
104+ res <- run $ Stream.eqBy (==) v1 v2
102− assert (res)
105+ assert res
103
106
104−testWrite :: (Handle -> FL.Fold IO Word8 ()) -> Property
107+testWrite :: (Handle -> Fold.Fold IO Word8 ()) -> Property
105testWrite hfold =
108testWrite hfold =
106 forAll (choose (0, maxArrLen)) $ \len ->
109 forAll (choose (0, maxArrLen)) $ \len ->
107 forAll (vectorOf len $ chooseWord8 (0, 255)) $ \list0 ->
110 forAll (vectorOf len $ chooseWord8 (0, 255)) $ \list0 ->
@@ -117,17 +120,17 @@ testWrite hfold =
117 writeFile fpathWrite ""
120 writeFile fpathWrite ""
118 h <- openFile fpathWrite ReadWriteMode
121 h <- openFile fpathWrite ReadWriteMode
119 hSeek h AbsoluteSeek 0
122 hSeek h AbsoluteSeek 0
120− S.fold (hfold h) $ S.fromList list
123+ Stream.fold (hfold h) $ Stream.fromList list
121 hFlush h
124 hFlush h
122 hSeek h AbsoluteSeek 0
125 hSeek h AbsoluteSeek 0
123− ls <- S.toList $ S.unfold FH.read h
126+ ls <- Stream.toList $ Stream.unfold Handle.read h
124 hClose h
127 hClose h
125 return (ls == list)
128 return (ls == list)
126
129
127testWriteWithChunk :: Property
130testWriteWithChunk :: Property
128testWriteWithChunk =
131testWriteWithChunk =
129 monadicIO $ do
132 monadicIO $ do
130− res <- run $ go
133+ res <- run go
131 assert res
134 assert res
132
135
133 where
136 where
@@ -141,12 +144,12 @@ testWriteWithChunk =
141 hr <- openFile fpathRead ReadMode
144 hr <- openFile fpathRead ReadMode
142 hw <- openFile fpathWrite ReadWriteMode
145 hw <- openFile fpathWrite ReadWriteMode
143 hSeek hw AbsoluteSeek 0
146 hSeek hw AbsoluteSeek 0
144− S.fold (FH.writeChunks hw)
147+ Stream.fold (Handle.writeChunks hw)
145− $ S.unfold FH.readChunksWithBufferOf (1024, hr)
148+ $ Stream.unfold Handle.readChunksWithBufferOf (1024, hr)
146 hFlush hw
149 hFlush hw
147 hSeek hw AbsoluteSeek 0
150 hSeek hw AbsoluteSeek 0
148− ls <- S.toList $ S.unfold FH.read hw
151+ ls <- Stream.toList $ Stream.unfold Handle.read hw
149− let arr = A.fromList ls
152+ let arr = Array.fromList ls
150 return (testDataLarge == utf8ToString arr)
153 return (testDataLarge == utf8ToString arr)
151
154
152main :: IO ()
155main :: IO ()
@@ -154,12 +157,12 @@ main =
154 hspec $
157 hspec $
155 H.parallel $
158 H.parallel $
156 modifyMaxSuccess (const maxTestCount) $ do
159 modifyMaxSuccess (const maxTestCount) $ do
157− describe "Read" $ do
160+ describe "Read From Handle" $ do
158− prop "testRead" $ testRead readFromHandle
161+ prop "read" $ testRead readFromHandle
159− prop "testReadWithBuffer" $ testRead readWithBufferFromHandle
162+ prop "readWithBufferOf" $ testRead readWithBufferFromHandle
160− prop "testReadChunks" $ testRead readChunksFromHandle
163+ prop "readChunks" $ testRead readChunksFromHandle
161− prop "testReadChunksWithBuffer" $ testRead readChunksWithBuffer
164+ prop "readChunksWithBufferOf" $ testRead readChunksWithBuffer
162− describe "Write" $ do
165+ describe "Write To Handle" $ do
163− prop "testWrite" $ testWrite FH.write
166+ prop "write" $ testWrite Handle.write
164− prop "testWriteWithBufferOf" $ testWrite $ FH.writeWithBufferOf 1024
167+ prop "writeWithBufferOf" $ testWrite $ Handle.writeWithBufferOf 1024
165− prop "testWriteWithChunk" $ testWriteWithChunk
168+ prop "writeChunks" testWriteWithChunk