@@ -1,3 +1,4 @@
1{-# LANGUAGE TemplateHaskell #-}
2{-# LANGUAGE TemplateHaskell #-}
3-- Required for Eq instance declaration of HigherOrderType
4-- Required for Eq instance declaration of HigherOrderType
@@ -24,10 +25,9 @@ import Streamly.Internal.Data.Unbox (newBytes)
24import GHC.Generics (Generic)
25import GHC.Generics (Generic)
25import Streamly.Test.Data.Serialize.TH (genDatatype)
26import Streamly.Test.Data.Serialize.TH (genDatatype)
26import qualified Streamly.Internal.Data.Serialize.TH as Serialize
27import qualified Streamly.Internal.Data.Serialize.TH as Serialize
27− ( deriveSerialize
28+ ( Config(..)
28− , deriveSerializeWith
29 , defaultConfig
29 , defaultConfig
30− , Config(..)
30+ , deriveSerializeWith
32import Data.Functor.Identity (Identity (..))
32import Data.Functor.Identity (Identity (..))
@@ -38,12 +38,38 @@ import Test.Hspec.QuickCheck
38import Test.QuickCheck
38import Test.QuickCheck
39import Test.Hspec as H
39import Test.Hspec as H
41+--------------------------------------------------------------------------------
42+-- Serialize configuration
43+--------------------------------------------------------------------------------
45+#ifdef ENABLE_constructorTagAsString
46+#define CONF_NAME "ENABLE_constructorTagAsString"
47+#define CONF (Serialize.defaultConfig {Serialize.constructorTagAsString = True})
49+#define CONF_NAME "DEFAULT"
50+#define CONF Serialize.defaultConfig
53+--------------------------------------------------------------------------------
55+--------------------------------------------------------------------------------
60+$(Serialize.deriveSerializeWith CONF ''Unit)
65+$(Serialize.deriveSerializeWith CONF ''The)
41--------------------------------------------------------------------------------
67--------------------------------------------------------------------------------
42-- Generated types
68-- Generated types
43--------------------------------------------------------------------------------
69--------------------------------------------------------------------------------
45$(genDatatype "CustomDatatype" 15)
71$(genDatatype "CustomDatatype" 15)
46−$(Serialize.deriveSerialize ''CustomDatatype)
72+$(Serialize.deriveSerializeWith CONF ''CustomDatatype)
48--------------------------------------------------------------------------------
74--------------------------------------------------------------------------------
49-- Types with functional parameters
75-- Types with functional parameters
@@ -61,9 +87,9 @@ instance (Eq (f Int), Eq (f Char)) => Eq (HigherOrderType f) where
61instance (Show (f Int), Show (f Char)) => Show (HigherOrderType f) where
87instance (Show (f Int), Show (f Char)) => Show (HigherOrderType f) where
62 show a = "HigherOrderType " ++ show (field0 a) ++ " " ++ show (field1 a)
88 show a = "HigherOrderType " ++ show (field0 a) ++ " " ++ show (field1 a)
64−$(Serialize.deriveSerialize ''Identity)
90+$(Serialize.deriveSerializeWith CONF ''Identity)
65$(Serialize.deriveSerializeWith
91$(Serialize.deriveSerializeWith
66− (Serialize.defaultConfig
92+ (CONF
67 {Serialize.specializations = [("f", ConT ''Identity)]})
93 {Serialize.specializations = [("f", ConT ''Identity)]})
68 ''HigherOrderType)
94 ''HigherOrderType)
@@ -77,7 +103,7 @@ data BinTree a
78 deriving (Show, Read, Eq, Generic)
104 deriving (Show, Read, Eq, Generic)
80−$(Serialize.deriveSerialize ''BinTree)
106+$(Serialize.deriveSerializeWith CONF ''BinTree)
82instance Arbitrary a => Arbitrary (BinTree a) where
108instance Arbitrary a => Arbitrary (BinTree a) where
83 arbitrary = oneof [Leaf <$> arbitrary, Tree <$> arbitrary <*> arbitrary]
109 arbitrary = oneof [Leaf <$> arbitrary, Tree <$> arbitrary <*> arbitrary]
@@ -133,6 +159,10 @@ testCases = do
133 (8 + 3 * 8 + 6 * 8)
159 (8 + 3 * 8 + 6 * 8)
134 ([[1], [1, 2], [1, 2, 3]] :: [[Int]])
160 ([[1], [1, 2], [1, 2, 3]] :: [[Int]])
162+ describe "Edge Cases" $ do
163+ it "Unit" $ roundtrip Unit
164+ it "The" $ roundtrip $ The Unit 1 'a'
136 it "HigherOrderType"
166 it "HigherOrderType"
137 $ roundtrip $ HigherOrderType (Identity 5) (Identity 'e')
167 $ roundtrip $ HigherOrderType (Identity 5) (Identity 'e')
@@ -156,7 +186,7 @@ testCases = do
156--------------------------------------------------------------------------------
186--------------------------------------------------------------------------------
158moduleName :: String
188moduleName :: String
159−moduleName = "Data.Serialize"
189+moduleName = "Data.Serialize." ++ CONF_NAME
161main :: IO ()
191main :: IO ()
162main = hspec $ H.parallel $ describe moduleName testCases
192main = hspec $ H.parallel $ describe moduleName testCases