@@ -28,18 +28,15 @@ import Streamly.Data.Serialize (Serialize)
28import Streamly.Test.Data.Serialize.TH (genDatatype)
28import Streamly.Test.Data.Serialize.TH (genDatatype)
30import qualified Streamly.Internal.Data.Serialize.TH as Serialize
30import qualified Streamly.Internal.Data.Serialize.TH as Serialize
31− ( deriveSerializeWith
32−#ifdef ENABLE_constructorTagAsString
38import Data.Functor.Identity (Identity (..))
32import Data.Functor.Identity (Identity (..))
40import qualified Streamly.Internal.Data.Array as Array
34import qualified Streamly.Internal.Data.Array as Array
41import qualified Streamly.Internal.Data.Serialize as Serialize
35import qualified Streamly.Internal.Data.Serialize as Serialize
37+import qualified Streamly.Test.Data.Serialize.CompatV0 as CompatV0
38+import qualified Streamly.Test.Data.Serialize.CompatV1 as CompatV1
43import Test.Hspec.QuickCheck
40import Test.Hspec.QuickCheck
44import Test.QuickCheck
41import Test.QuickCheck
45import Test.Hspec as H
42import Test.Hspec as H
@@ -115,6 +112,47 @@ $(Serialize.deriveSerializeWith
115instance Arbitrary a => Arbitrary (BinTree a) where
112instance Arbitrary a => Arbitrary (BinTree a) where
116 arbitrary = oneof [Leaf <$> arbitrary, Tree <$> arbitrary <*> arbitrary]
113 arbitrary = oneof [Leaf <$> arbitrary, Tree <$> arbitrary <*> arbitrary]
115+--------------------------------------------------------------------------------
116+-- Record syntax type
117+--------------------------------------------------------------------------------
119+upgradeRec :: (a -> b) -> CompatV0.Rec a -> CompatV1.Rec b
122+ { CompatV1.initialField = CompatV0.initialField val
123+ , CompatV1.otherField = f (CompatV0.otherField val)
124+ , CompatV1.theLastField = CompatV0.theLastField val
125+ , CompatV1.aNewField = Nothing
128+upgradeRiver :: CompatV0.River -> CompatV1.River
129+upgradeRiver = read . show
131+downgradeRec :: (a -> b) -> CompatV1.Rec a -> CompatV0.Rec b
134+ { CompatV0.initialField = CompatV1.initialField val
135+ , CompatV0.otherField = f (CompatV1.otherField val)
136+ , CompatV0.theLastField = CompatV1.theLastField val
139+downgradeRiver :: CompatV1.River -> CompatV0.River
140+downgradeRiver = read . show
143+ CompatV0.Rec (CompatV0.Rec CompatV0.River)
144+ -> CompatV1.Rec (CompatV1.Rec CompatV1.River)
146+testCompatibility v0 v1 = do
147+ let upgradedV0 = upgradeRec (upgradeRec upgradeRiver) v0
148+ downgradedV1 = downgradeRec (downgradeRec downgradeRiver) v1
151+ peekAndVerify res upgradedV0
154+ peekAndVerify res1 downgradedV1
118--------------------------------------------------------------------------------
156--------------------------------------------------------------------------------
119-- Test helpers
157-- Test helpers
120--------------------------------------------------------------------------------
158--------------------------------------------------------------------------------
@@ -204,6 +242,12 @@ testCases = do
204 prop "Array Int"
242 prop "Array Int"
205 $ \(x :: [Int]) -> roundtrip (Array.fromList x)
243 $ \(x :: [Int]) -> roundtrip (Array.fromList x)
245+ prop "Compatible Record"
246+ $ \(a :: CompatV1.Rec (CompatV0.Rec CompatV1.River)) -> roundtrip a
248+ prop "Compatibility"
249+ $ \a b -> testCompatibility a b
208 $ prop "CustomDatatype"
252 $ prop "CustomDatatype"
209 $ \(x :: CustomDatatype) -> roundtrip x
253 $ \(x :: CustomDatatype) -> roundtrip x