on master help sign in
Test the encoding and decoding functions in the roundtrip
commitb675912c27fd2f66049c141b8a25d6c2bf1e9ca5 authorAdithya Kumar <adithya@composewell.com> dateFri 8 Sep 2023, 01:17 (3 years ago) parentcedc81c
1 file changed+12−8
test/Streamly/Test/Data/Serialize.hs+12−8
test/Streamly/Test/Data/Serialize.hs+12−8
@@ -31,6 +31,7 @@ import qualified Streamly.Internal.Data.Serialize.TH as Serialize
3131 )
3232import Data.Functor.Identity (Identity (..))
3333
34+import qualified Streamly.Internal.Data.Array as Array
3435import qualified Streamly.Internal.Data.Serialize as Serialize
3536
3637import Language.Haskell.TH
@@ -120,17 +121,20 @@ roundtrip val = do
120121
121122 let sz = Serialize.size 0 val
122123
123− -- putStrLn "----------------------------------------------------------------"
124− -- putStrLn $ show val
125− -- putStrLn $ "Size is: " ++ show sz
126− -- putStrLn "----------------------------------------------------------------"
127− arr <- newBytes sz
124+ -- Use a proper slice to test instead of the array directly. This will catch
125+ -- any hardcoded 0 offsets
126+ let arrSize = sz + 100
127+ serStartOff = 50
128+ serEndOff = 50 + sz
129+ arr <- newBytes arrSize
128130
129− off1 <- Serialize.serialize 0 arr val
130− (off2, val2) <- Serialize.deserialize 0 arr sz
131+ off1 <- Serialize.serialize serStartOff arr val
132+ (off2, val2) <- Serialize.deserialize serStartOff arr serEndOff
131133 val2 `shouldBe` val
132134 off2 `shouldBe` off1
133− off2 `shouldBe` sz
135+ off2 `shouldBe` serEndOff
136+ val `shouldBe` Serialize.decode (Serialize.encode val)
137+ val `shouldBe` Serialize.decode (Array.Array arr serStartOff serEndOff)
134138
135139testSerializeList
136140 :: forall a. (Eq a, Show a, Serialize.Serialize a)