@@ -27,7 +27,7 @@ import Test.QuickCheck (Property, forAll, Gen, vectorOf, choose)
2727import Test.QuickCheck.Monadic (monadicIO, assert, run)
2828
2929import qualified Streamly.Data.Fold as Fold
30−import qualified Streamly.FileSystem.Handle as Handle
30+import qualified Streamly.Internal.FileSystem.Handle as Handle
3131import qualified Streamly.Internal.Data.Stream.IsStream as Stream
3232import qualified Streamly.Internal.Data.Array.Foreign as Array
3333import qualified Streamly.Internal.Unicode.Stream as Unicode
@@ -155,52 +155,48 @@ testWriteWithChunk =
155155 let arr = Array.fromList ls
156156 return (testDataLarge == utf8ToString arr)
157157
158+testReadChunksFromToWith :: Int -> Int -> Int -> [[Word8]] -> Property
159+testReadChunksFromToWith from to buffSize res = monadicIO $ run go
158160
159−testReadChunksFromToWith :: Int -> Int -> Int -> String -> Property
160−testReadChunksFromToWith from to buffSize expRes =
161− monadicIO $ do
162− res <- run go
163− assert res
164−
165− where
161+ where
166162
167− go =
168− withSystemTempDirectory "fs_handle" $ \fp -> do
169− let fpathRead = fp </> "tmp_read.txt"
170− writeFile fpathRead testBinData
171− h <- openFile fpathRead ReadMode
172− ls <- Stream.toList $
173− Stream.unfold
174− Handle.readChunksFromToWith
175− (from, to, buffSize, h)
176− return ( expRes == show ls)
163+ go =
164+ withSystemTempDirectory "fs_handle" $ \fp -> do
165+ let fpathRead = fp </> "tmp_read.txt"
166+ writeFile fpathRead testBinData
167+ h <- openFile fpathRead ReadMode
168+ ls <-
169+ Stream.toList
170+ $ Stream.unfold
171+ Handle.readChunksFromToWith (from, to, buffSize, h)
172+ return (res `shouldBe` fmap Array.toList ls)
177173
178174-- Test for first byte
179175testReadChunksFromToWithFirstByte :: Property
180−testReadChunksFromToWithFirstByte = testReadChunksFromToWith 0 0 15 "[[48]]"
176+testReadChunksFromToWithFirstByte = testReadChunksFromToWith 0 0 15 [[48]]
181177
182178-- Test for second byte
183179testReadChunksFromToWithSecondByte :: Property
184−testReadChunksFromToWithSecondByte = testReadChunksFromToWith 1 1 15 "[[49]]"
180+testReadChunksFromToWithSecondByte = testReadChunksFromToWith 1 1 15 [[49]]
185181
186182-- Test for second to 10th bytes
187183testReadChunksFromToWithSecondToTenthBytes :: Property
188184testReadChunksFromToWithSecondToTenthBytes =
189− testReadChunksFromToWith 1 10 15 "[[49,50,51,52,53,54,55,56,57,48]]"
185+ testReadChunksFromToWith 1 10 15 [[49,50,51,52,53,54,55,56,57,48]]
190186
191187-- Test for offset of buffer size
192188testReadChunksFromToWithBuffSizeOffset :: Property
193189testReadChunksFromToWithBuffSizeOffset =
194− testReadChunksFromToWith 15 25 15 "[[53,54,55,56,57,48,49,50,51,52,53]]"
190+ testReadChunksFromToWith 15 25 15 [[53,54,55,56,57,48,49,50,51,52,53]]
195191
196192-- Test with multi buffer size
197193testReadChunksFromToWithMultiBuff :: Property
198194testReadChunksFromToWithMultiBuff =
199195 testReadChunksFromToWith
200− 5 22 5 "[[53,54,55,56,57],[48,49,50,51,52],[53,54,55,56,57],[48,49,50]]"
196+ 5 22 5 [[53,54,55,56,57],[48,49,50,51,52],[53,54,55,56,57],[48,49,50]]
201197
202198testReadChunksFromToWithRangeInvalid :: Property
203−testReadChunksFromToWithRangeInvalid = testReadChunksFromToWith 15 5 15 "[]"
199+testReadChunksFromToWithRangeInvalid = testReadChunksFromToWith 15 5 15 []
204200
205201moduleName :: String
206202moduleName = "FileSystem.Handle"
@@ -216,14 +212,21 @@ main =
216212 prop "readWithBufferOf" $ testRead readWithBufferFromHandle
217213 prop "readChunks" $ testRead readChunksFromHandle
218214 prop "readChunksWithBufferOf" $ testRead readChunksWithBuffer
219− prop "readChunksFromToWithFirstByte" testReadChunksFromToWithFirstByte
220− prop "readChunksFromToWithSecondByte" testReadChunksFromToWithSecondByte
221− prop "readChunksFromToWithSecondToTenthBytes" testReadChunksFromToWithSecondToTenthBytes
222− prop "readChunksFromToWithBuffSizeOffset" testReadChunksFromToWithBuffSizeOffset
223− prop "readChunksFromToWithMultiBuff" testReadChunksFromToWithMultiBuff
224− prop "readChunksFromToWithRangeInvalid" testReadChunksFromToWithRangeInvalid
215+ prop "readChunksFromToWith (0,0,n)"
216+ testReadChunksFromToWithFirstByte
217+ prop "readChunksFromToWith (1,1,n)"
218+ testReadChunksFromToWithSecondByte
219+ prop "readChunksFromToWith (1,10,n)"
220+ testReadChunksFromToWithSecondToTenthBytes
221+ prop "readChunksFromToWith (n,<2n,n)"
222+ testReadChunksFromToWithBuffSizeOffset
223+ prop "readChunksFromToWith (n,>2n,n)"
224+ testReadChunksFromToWithMultiBuff
225+ prop "readChunksFromToWith (n,<n,n)"
226+ testReadChunksFromToWithRangeInvalid
225227 describe "Write To Handle" $ do
226228 prop "write" $ testWrite Handle.write
227− prop "writeWithBufferOf" $ testWrite $ Handle.writeWithBufferOf 1024
229+ prop "writeWithBufferOf"
230+ $ testWrite $ Handle.writeWithBufferOf 1024
228231 -- XXX This test needs a lot of stack when built with -O0
229232 prop "writeChunks" testWriteWithChunk