@@ -21,6 +21,7 @@ module Streamly.Test.Data.Serialize (main) where
2121-- Imports
2222--------------------------------------------------------------------------------
2323
24+import System.Random (randomRIO)
2425import Streamly.Internal.Data.Unbox (newBytes)
2526import GHC.Generics (Generic)
2627import Streamly.Test.Data.Serialize.TH (genDatatype)
@@ -121,11 +122,13 @@ roundtrip val = do
121122
122123 let sz = Serialize.size 0 val
123124
125+ let excessSize = 100
126+ randomOff <- randomRIO (10, excessSize)
124127 -- Use a proper slice to test instead of the array directly. This will catch
125128 -- any hardcoded 0 offsets
126− let arrSize = sz + 100
127− serStartOff = 50
128− serEndOff = 50 + sz
129+ let arrSize = sz + excessSize
130+ serStartOff = randomOff
131+ serEndOff = randomOff + sz
129132 arr <- newBytes arrSize
130133
131134 off1 <- Serialize.serialize serStartOff arr val
@@ -134,7 +137,10 @@ roundtrip val = do
134137 off2 `shouldBe` off1
135138 off2 `shouldBe` serEndOff
136139 val `shouldBe` Serialize.decode (Serialize.encode val)
137− val `shouldBe` Serialize.decode (Array.Array arr serStartOff serEndOff)
140+ let slice = Array.Array arr serStartOff serEndOff
141+ val `shouldBe` Serialize.decode slice
142+ clonedSlice <- Array.clone slice
143+ val `shouldBe` Serialize.decode clonedSlice
138144
139145testSerializeList
140146 :: forall a. (Eq a, Show a, Serialize.Serialize a)