@@ -27,7 +27,7 @@ import Test.QuickCheck (Property, forAll, Gen, vectorOf, choose)
27import Test.QuickCheck.Monadic (monadicIO, assert, run)
27import Test.QuickCheck.Monadic (monadicIO, assert, run)
29import qualified Streamly.Data.Fold as Fold
29import qualified Streamly.Data.Fold as Fold
30−import qualified Streamly.FileSystem.Handle as Handle
30+import qualified Streamly.Internal.FileSystem.Handle as Handle
31import qualified Streamly.Internal.Data.Stream.IsStream as Stream
31import qualified Streamly.Internal.Data.Stream.IsStream as Stream
32import qualified Streamly.Internal.Data.Array.Foreign as Array
32import qualified Streamly.Internal.Data.Array.Foreign as Array
33import qualified Streamly.Internal.Unicode.Stream as Unicode
33import qualified Streamly.Internal.Unicode.Stream as Unicode
@@ -155,52 +155,48 @@ testWriteWithChunk =
155 let arr = Array.fromList ls
155 let arr = Array.fromList ls
156 return (testDataLarge == utf8ToString arr)
156 return (testDataLarge == utf8ToString arr)
158+testReadChunksFromToWith :: Int -> Int -> Int -> [[Word8]] -> Property
159+testReadChunksFromToWith from to buffSize res = monadicIO $ run go
159−testReadChunksFromToWith :: Int -> Int -> Int -> String -> Property
160−testReadChunksFromToWith from to buffSize expRes =
168− withSystemTempDirectory "fs_handle" $ \fp -> do
164+ withSystemTempDirectory "fs_handle" $ \fp -> do
169− let fpathRead = fp </> "tmp_read.txt"
165+ let fpathRead = fp </> "tmp_read.txt"
170− writeFile fpathRead testBinData
166+ writeFile fpathRead testBinData
171− h <- openFile fpathRead ReadMode
167+ h <- openFile fpathRead ReadMode
172− ls <- Stream.toList $
169+ Stream.toList
173− Stream.unfold
170+ $ Stream.unfold
174− Handle.readChunksFromToWith
171+ Handle.readChunksFromToWith (from, to, buffSize, h)
175− (from, to, buffSize, h)
172+ return (res `shouldBe` fmap Array.toList ls)
176− return ( expRes == show ls)
178-- Test for first byte
174-- Test for first byte
179testReadChunksFromToWithFirstByte :: Property
175testReadChunksFromToWithFirstByte :: Property
180−testReadChunksFromToWithFirstByte = testReadChunksFromToWith 0 0 15 "[[48]]"
176+testReadChunksFromToWithFirstByte = testReadChunksFromToWith 0 0 15 [[48]]
182-- Test for second byte
178-- Test for second byte
183testReadChunksFromToWithSecondByte :: Property
179testReadChunksFromToWithSecondByte :: Property
184−testReadChunksFromToWithSecondByte = testReadChunksFromToWith 1 1 15 "[[49]]"
180+testReadChunksFromToWithSecondByte = testReadChunksFromToWith 1 1 15 [[49]]
186-- Test for second to 10th bytes
182-- Test for second to 10th bytes
187testReadChunksFromToWithSecondToTenthBytes :: Property
183testReadChunksFromToWithSecondToTenthBytes :: Property
188testReadChunksFromToWithSecondToTenthBytes =
184testReadChunksFromToWithSecondToTenthBytes =
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]]
191-- Test for offset of buffer size
187-- Test for offset of buffer size
192testReadChunksFromToWithBuffSizeOffset :: Property
188testReadChunksFromToWithBuffSizeOffset :: Property
193testReadChunksFromToWithBuffSizeOffset =
189testReadChunksFromToWithBuffSizeOffset =
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]]
196-- Test with multi buffer size
192-- Test with multi buffer size
197testReadChunksFromToWithMultiBuff :: Property
193testReadChunksFromToWithMultiBuff :: Property
198testReadChunksFromToWithMultiBuff =
194testReadChunksFromToWithMultiBuff =
199 testReadChunksFromToWith
195 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]]
202testReadChunksFromToWithRangeInvalid :: Property
198testReadChunksFromToWithRangeInvalid :: Property
203−testReadChunksFromToWithRangeInvalid = testReadChunksFromToWith 15 5 15 "[]"
199+testReadChunksFromToWithRangeInvalid = testReadChunksFromToWith 15 5 15 []
205moduleName :: String
201moduleName :: String
206moduleName = "FileSystem.Handle"
202moduleName = "FileSystem.Handle"
@@ -216,14 +212,21 @@ main =
216 prop "readWithBufferOf" $ testRead readWithBufferFromHandle
212 prop "readWithBufferOf" $ testRead readWithBufferFromHandle
217 prop "readChunks" $ testRead readChunksFromHandle
213 prop "readChunks" $ testRead readChunksFromHandle
218 prop "readChunksWithBufferOf" $ testRead readChunksWithBuffer
214 prop "readChunksWithBufferOf" $ testRead readChunksWithBuffer
215+ prop "readChunksFromToWith (0,0,n)"
219− prop "readChunksFromToWithFirstByte" testReadChunksFromToWithFirstByte
216+ testReadChunksFromToWithFirstByte
217+ prop "readChunksFromToWith (1,1,n)"
220− prop "readChunksFromToWithSecondByte" testReadChunksFromToWithSecondByte
218+ testReadChunksFromToWithSecondByte
219+ prop "readChunksFromToWith (1,10,n)"
221− prop "readChunksFromToWithSecondToTenthBytes" testReadChunksFromToWithSecondToTenthBytes
220+ testReadChunksFromToWithSecondToTenthBytes
221+ prop "readChunksFromToWith (n,<2n,n)"
222− prop "readChunksFromToWithBuffSizeOffset" testReadChunksFromToWithBuffSizeOffset
222+ testReadChunksFromToWithBuffSizeOffset
223+ prop "readChunksFromToWith (n,>2n,n)"
223− prop "readChunksFromToWithMultiBuff" testReadChunksFromToWithMultiBuff
224+ testReadChunksFromToWithMultiBuff
225+ prop "readChunksFromToWith (n,<n,n)"
224− prop "readChunksFromToWithRangeInvalid" testReadChunksFromToWithRangeInvalid
226+ testReadChunksFromToWithRangeInvalid
225 describe "Write To Handle" $ do
227 describe "Write To Handle" $ do
226 prop "write" $ testWrite Handle.write
228 prop "write" $ testWrite Handle.write
229+ prop "writeWithBufferOf"
227− prop "writeWithBufferOf" $ testWrite $ Handle.writeWithBufferOf 1024
230+ $ testWrite $ Handle.writeWithBufferOf 1024
228 -- XXX This test needs a lot of stack when built with -O0
231 -- XXX This test needs a lot of stack when built with -O0
229 prop "writeChunks" testWriteWithChunk
232 prop "writeChunks" testWriteWithChunk