1{-# LANGUAGE TemplateHaskell #-}
4-- Module : Streamly.Test.Data.Serialize
5-- Copyright : (c) 2022 Composewell technologies
6-- License : BSD-3-Clause
7-- Maintainer : streamly@composewell.com
8-- Stability : experimental
11module Streamly.Test.Data.Serialize (main) where
13--------------------------------------------------------------------------------
15--------------------------------------------------------------------------------
17import Streamly.Internal.Data.Unbox (newBytes)
18import GHC.Generics (Generic)
19import Streamly.Test.Data.Serialize.TH (genDatatype)
20import Streamly.Internal.Data.Serialize.TH (deriveSerialize)
22import qualified Streamly.Internal.Data.Serialize as Serialize
24import Test.Hspec.QuickCheck
28--------------------------------------------------------------------------------
30--------------------------------------------------------------------------------
32$(genDatatype "CustomDatatype" 15)
33$(deriveSerialize ''CustomDatatype)
35--------------------------------------------------------------------------------
37--------------------------------------------------------------------------------
41 = Tree (BinTree a) (BinTree a)
43 deriving (Show, Read, Eq, Generic)
45$(deriveSerialize ''BinTree)
47instance Arbitrary a => Arbitrary (BinTree a) where
48 arbitrary = oneof [Leaf <$> arbitrary, Tree <$> arbitrary <*> arbitrary]
50--------------------------------------------------------------------------------
52--------------------------------------------------------------------------------
55 :: forall a. (Eq a, Show a, Serialize.Serialize a)
61 case Serialize.size :: Serialize.Size a of
62 Serialize.VarSize f -> f val
63 Serialize.ConstSize csz -> csz
67 off1 <- Serialize.serialize 0 arr val
68 (off2, val2) <- Serialize.deserialize 0 arr
73 :: forall a. (Eq a, Show a, Serialize.Serialize a)
77testSerializeList sizeOfA val = do
80 case Serialize.size :: Serialize.Size a of
81 Serialize.VarSize f -> f val
82 Serialize.ConstSize csz -> csz
88--------------------------------------------------------------------------------
90--------------------------------------------------------------------------------
96 $ testSerializeList (8 + 4 * 8) ([1, 2, 3, 4] :: [Int])
97 it "Serialize [[Int]]"
100 ([[1], [1, 2], [1, 2, 3]] :: [[Int]])
103 $ prop "CustomDatatype"
104 $ \(x :: CustomDatatype) -> roundtrip x
107 $ prop "[CustomDatatype]"
108 $ \(x :: [CustomDatatype]) -> roundtrip x
111 $ prop "BinTree" $ \(x :: BinTree Int) -> roundtrip x
115 limitQC = modifyMaxSize (const 50)
117--------------------------------------------------------------------------------
119--------------------------------------------------------------------------------
122moduleName = "Data.Serialize"
125main = hspec $ H.parallel $ describe moduleName testCases
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list