@@ -61,6 +61,9 @@ testData = "This is the test data for FileSystem.Handle ??`!@#$%^&*~~))`]"
6161testDataLarge :: String
6262testDataLarge = concat $ replicate 6000 testData
6363
64+testBinData :: String
65+testBinData = "01234567890123456789012345678901234567890123456789"
66+
6467executor :: (Handle -> SerialT IO Char) -> IO (SerialT IO Char)
6568executor f =
6669 withSystemTempDirectory "fs_handle" $ \fp -> do
@@ -152,6 +155,53 @@ testWriteWithChunk =
152155 let arr = Array.fromList ls
153156 return (testDataLarge == utf8ToString arr)
154157
158+
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
166+
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)
177+
178+-- Test for first byte
179+testReadChunksFromToWithFirstByte :: Property
180+testReadChunksFromToWithFirstByte = testReadChunksFromToWith 0 0 15 "[[48]]"
181+
182+-- Test for second byte
183+testReadChunksFromToWithSecondByte :: Property
184+testReadChunksFromToWithSecondByte = testReadChunksFromToWith 1 1 15 "[[49]]"
185+
186+-- Test for second to 10th bytes
187+testReadChunksFromToWithSecondToTenthBytes :: Property
188+testReadChunksFromToWithSecondToTenthBytes =
189+ testReadChunksFromToWith 1 10 15 "[[49,50,51,52,53,54,55,56,57,48]]"
190+
191+-- Test for offset of buffer size
192+testReadChunksFromToWithBuffSizeOffset :: Property
193+testReadChunksFromToWithBuffSizeOffset =
194+ testReadChunksFromToWith 15 25 15 "[[53,54,55,56,57,48,49,50,51,52,53]]"
195+
196+-- Test with multi buffer size
197+testReadChunksFromToWithMultiBuff :: Property
198+testReadChunksFromToWithMultiBuff =
199+ testReadChunksFromToWith
200+ 5 22 5 "[[53,54,55,56,57],[48,49,50,51,52],[53,54,55,56,57],[48,49,50]]"
201+
202+testReadChunksFromToWithRangeInvalid :: Property
203+testReadChunksFromToWithRangeInvalid = testReadChunksFromToWith 15 5 15 "[]"
204+
155205moduleName :: String
156206moduleName = "FileSystem.Handle"
157207
@@ -166,6 +216,12 @@ main =
166216 prop "readWithBufferOf" $ testRead readWithBufferFromHandle
167217 prop "readChunks" $ testRead readChunksFromHandle
168218 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
169225 describe "Write To Handle" $ do
170226 prop "write" $ testWrite Handle.write
171227 prop "writeWithBufferOf" $ testWrite $ Handle.writeWithBufferOf 1024