@@ -0,0 +1,79 @@
1+{-# LANGUAGE DeriveAnyClass #-}
4+-- Module : Streamly.Test.Data.Unbox
5+-- Copyright : (c) 2022 Composewell technologies
6+-- License : BSD-3-Clause
7+-- Maintainer : streamly@composewell.com
8+-- Stability : experimental
11+module Streamly.Test.Data.Unbox (main) where
13+import Data.Proxy (Proxy(..))
14+import GHC.Generics (Generic)
15+import Streamly.Internal.Data.Unboxed (Unbox(..))
16+import qualified Streamly.Internal.Data.IORef.Unboxed as IORef
18+import Test.Hspec as H
19+import Test.Hspec.QuickCheck
20+import Test.QuickCheck (Property)
21+import Test.QuickCheck.Monadic (monadicIO, assert, run)
23+data Unit = Unit deriving (Unbox, Show, Generic, Eq)
25+{-# ANN Single "HLint: ignore" #-}
26+data Single = Single Int deriving (Unbox, Show, Generic, Eq)
28+data Product2 = Product2 Int Char deriving (Unbox, Show, Generic, Eq)
34+ | SOP3 Int Int Int deriving (Unbox, Show, Generic, Eq)
38+ | NSOP1 SumOfProducts deriving (Unbox, Show, Generic, Eq)
40+test ::(Unbox a, Eq a) => a -> a -> Property
41+test v1 v2 = monadicIO $ do
42+ ref <- run $ IORef.newIORef v1
43+ x1 <- run $ IORef.readIORef ref
44+ run $ IORef.writeIORef ref v2
45+ x2 <- run $ IORef.readIORef ref
49+checkSizeOf :: forall a. Unbox a => Proxy a -> Int -> Property
50+checkSizeOf _ size = monadicIO $
51+ assert (sizeOf (undefined :: a) == size)
54+moduleName = "Data.Unbox"
58+ prop "test Unit Unit" $ test Unit Unit
59+ prop "(Single 0) (Single 1)" $ test (Single 0) (Single 1)
60+ prop "(Product2 0 'a') (Product2 1 'b')"
61+ $ test (Product2 0 'a') (Product2 1 'b')
62+ prop "(SOP0) (SOP1 1)" $ test SOP0 (SOP1 1)
63+ prop "(SOP0) (SOP2 1 'a')" $ test SOP0 (SOP2 1 'a')
64+ prop "(SOP0) (SOP3 1 2 3)" $ test SOP0 (SOP3 1 2 3)
66+ prop "checkSizeOf Unit" $ checkSizeOf (Proxy :: Proxy Unit) 1
67+ prop "checkSizeOf Single" $ checkSizeOf (Proxy :: Proxy Single) 8
68+ prop "checkSizeOf Product2" $ checkSizeOf (Proxy :: Proxy Product2) 12
69+ prop "checkSizeOf SumOfProducts"
70+ $ checkSizeOf (Proxy :: Proxy SumOfProducts) 25
71+ prop "checkSizeOf NestedSOP" $ checkSizeOf (Proxy :: Proxy NestedSOP) 26
77+ modifyMaxSuccess (const 1) $ do
78+ describe moduleName $ do
79+ describe "Generic Unboxed Type" tests