@@ -20,6 +20,12 @@ module Streamly.Test.Data.Unbox (main) where
21--------------------------------------------------------------------------------
21--------------------------------------------------------------------------------
24+import Data.Foldable (forM_)
25+import Data.Word (Word8)
26+import qualified Streamly.Internal.Data.Array as Array
23import Data.Complex (Complex ((:+)))
29import Data.Complex (Complex ((:+)))
24import Data.Functor.Const (Const (..))
30import Data.Functor.Const (Const (..))
25import Data.Functor.Identity (Identity (..))
31import Data.Functor.Identity (Identity (..))
@@ -201,6 +207,19 @@ testSerialization val = do
202 arr <- MBA.new len
208 arr <- MBA.new len
203 nextOff <- POKE(0, arr, val)
209 nextOff <- POKE(0, arr, val)
212+ -- Re-initialize the array with random value
213+ forM_ [0..(len - 1)] $ \i -> POKE(i, arr2, (8 :: Word8))
214+ _ <- POKE(0, arr2, val)
215+ let slice1 = Array.Array arr 0 len :: Array.Array Word8
216+ slice2 = Array.Array arr2 0 len :: Array.Array Word8
217+ -- The serialized representation should be the same
218+ slice1 `shouldBe` slice2
219+ -- The serialized representation is not the same for "Unbox" as the Array
220+ -- might not be fully utilized in case of "Unbox". This is because different
221+ -- constructors might have different lengths.
204 (nextOff1, val1) <- PEEK(0, arr, len)
223 (nextOff1, val1) <- PEEK(0, arr, len)
205 val1 `shouldBe` val
224 val1 `shouldBe` val
206 nextOff1 `shouldBe` len
225 nextOff1 `shouldBe` len