@@ -28,18 +28,15 @@ import Streamly.Data.Serialize (Serialize)
2828import Streamly.Test.Data.Serialize.TH (genDatatype)
2929
3030import qualified Streamly.Internal.Data.Serialize.TH as Serialize
31− ( deriveSerializeWith
32−#ifdef ENABLE_constructorTagAsString
33− , Config(..)
34−#endif
35− , defaultConfig
36− )
3731
3832import Data.Functor.Identity (Identity (..))
3933
4034import qualified Streamly.Internal.Data.Array as Array
4135import qualified Streamly.Internal.Data.Serialize as Serialize
4236
37+import qualified Streamly.Test.Data.Serialize.CompatV0 as CompatV0
38+import qualified Streamly.Test.Data.Serialize.CompatV1 as CompatV1
39+
4340import Test.Hspec.QuickCheck
4441import Test.QuickCheck
4542import Test.Hspec as H
@@ -115,6 +112,47 @@ $(Serialize.deriveSerializeWith
115112instance Arbitrary a => Arbitrary (BinTree a) where
116113 arbitrary = oneof [Leaf <$> arbitrary, Tree <$> arbitrary <*> arbitrary]
117114
115+--------------------------------------------------------------------------------
116+-- Record syntax type
117+--------------------------------------------------------------------------------
118+
119+upgradeRec :: (a -> b) -> CompatV0.Rec a -> CompatV1.Rec b
120+upgradeRec f val =
121+ CompatV1.Rec
122+ { CompatV1.initialField = CompatV0.initialField val
123+ , CompatV1.otherField = f (CompatV0.otherField val)
124+ , CompatV1.theLastField = CompatV0.theLastField val
125+ , CompatV1.aNewField = Nothing
126+ }
127+
128+upgradeRiver :: CompatV0.River -> CompatV1.River
129+upgradeRiver = read . show
130+
131+downgradeRec :: (a -> b) -> CompatV1.Rec a -> CompatV0.Rec b
132+downgradeRec f val =
133+ CompatV0.Rec
134+ { CompatV0.initialField = CompatV1.initialField val
135+ , CompatV0.otherField = f (CompatV1.otherField val)
136+ , CompatV0.theLastField = CompatV1.theLastField val
137+ }
138+
139+downgradeRiver :: CompatV1.River -> CompatV0.River
140+downgradeRiver = read . show
141+
142+testCompatibility ::
143+ CompatV0.Rec (CompatV0.Rec CompatV0.River)
144+ -> CompatV1.Rec (CompatV1.Rec CompatV1.River)
145+ -> IO ()
146+testCompatibility v0 v1 = do
147+ let upgradedV0 = upgradeRec (upgradeRec upgradeRiver) v0
148+ downgradedV1 = downgradeRec (downgradeRec downgradeRiver) v1
149+
150+ res <- poke v0
151+ peekAndVerify res upgradedV0
152+
153+ res1 <- poke v1
154+ peekAndVerify res1 downgradedV1
155+
118156--------------------------------------------------------------------------------
119157-- Test helpers
120158--------------------------------------------------------------------------------
@@ -204,6 +242,12 @@ testCases = do
204242 prop "Array Int"
205243 $ \(x :: [Int]) -> roundtrip (Array.fromList x)
206244
245+ prop "Compatible Record"
246+ $ \(a :: CompatV1.Rec (CompatV0.Rec CompatV1.River)) -> roundtrip a
247+
248+ prop "Compatibility"
249+ $ \a b -> testCompatibility a b
250+
207251 limitQC
208252 $ prop "CustomDatatype"
209253 $ \(x :: CustomDatatype) -> roundtrip x