Skip to content

Commit

Permalink
Add a recursive ADT to the Serialize test-suite
Browse files Browse the repository at this point in the history
  • Loading branch information
adithyaov committed Aug 18, 2023
1 parent 9be03c8 commit 4997b47
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions test/Streamly/Test/Data/Serialize.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,15 @@ module Streamly.Test.Data.Serialize (main) where
--------------------------------------------------------------------------------

import Streamly.Internal.Data.Unbox (newBytes)

import Test.Hspec as H

import GHC.Generics (Generic)
import Streamly.Test.Data.Serialize.TH (genDatatype)
import Streamly.Internal.Data.Serialize.TH (deriveSerialize)
-- import Streamly.Internal.Data.Serialize (Serialize(..))

import qualified Streamly.Internal.Data.Serialize as Serialize

import Streamly.Test.Data.Serialize.TH (genDatatype)

import Test.Hspec.QuickCheck
import Test.QuickCheck
import Test.Hspec as H

--------------------------------------------------------------------------------
-- Generated types
Expand All @@ -34,6 +32,21 @@ import Test.Hspec.QuickCheck
$(genDatatype "CustomDatatype" 15)
$(deriveSerialize ''CustomDatatype)

--------------------------------------------------------------------------------
-- Recursive type
--------------------------------------------------------------------------------

-- Recursive ADT
data BinTree a
= Tree (BinTree a) (BinTree a)
| Leaf a
deriving (Show, Read, Eq, Generic)

$(deriveSerialize ''BinTree)

instance Arbitrary a => Arbitrary (BinTree a) where
arbitrary = oneof [Leaf <$> arbitrary, Tree <$> arbitrary <*> arbitrary]

--------------------------------------------------------------------------------
-- Test helpers
--------------------------------------------------------------------------------
Expand Down Expand Up @@ -91,12 +104,14 @@ testCases = do
prop "[CustomDatatype]"
$ \(x :: [CustomDatatype]) -> roundtrip x

prop "BinTree" $ \(x :: BinTree Int) -> roundtrip x

--------------------------------------------------------------------------------
-- Main function
--------------------------------------------------------------------------------

moduleName :: String
moduleName = "Data.Unboxed"
moduleName = "Data.Serialize"

main :: IO ()
main = hspec $ H.parallel $ describe moduleName testCases

0 comments on commit 4997b47

Please sign in to comment.