From c4343a47f75a9cd864dfee61557f30a6119a3401 Mon Sep 17 00:00:00 2001 From: Adithya Kumar Date: Wed, 16 Aug 2023 19:03:15 +0530 Subject: [PATCH] Abstact size and simplify the CPP statement in Unbox tests --- test/Streamly/Test/Data/Unbox.hs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/test/Streamly/Test/Data/Unbox.hs b/test/Streamly/Test/Data/Unbox.hs index 85020e0d14..978f232a3d 100644 --- a/test/Streamly/Test/Data/Unbox.hs +++ b/test/Streamly/Test/Data/Unbox.hs @@ -174,6 +174,17 @@ $(deriveSerialize ''Identity) -- Test helpers -------------------------------------------------------------------------------- +#ifdef USE_SERIALIZE +variableSizeOf :: + forall a. Serialize a + => a + -> Int +variableSizeOf val = + case size :: Size a of + ConstSize x -> x + VarSize f -> f val +#endif + testSerialization :: forall a. (Eq a, Show a, TYPE_CLASS a) => a @@ -181,9 +192,7 @@ testSerialization :: testSerialization val = do arr <- newBytes #ifdef USE_SERIALIZE - (case size :: Size a of - ConstSize x -> x - VarSize f -> f val) + (variableSizeOf val) #else (sizeOf (Proxy :: Proxy a)) #endif @@ -195,10 +204,9 @@ testGenericConsistency :: ( Eq a , Show a #ifdef USE_SERIALIZE - , Serialize a, Unbox a -#else - , Unbox a + , Serialize a #endif + , Unbox a , Generic a , SizeOfRep (Rep a) , PeekRep (Rep a) @@ -210,9 +218,7 @@ testGenericConsistency val = do -- Test the generic sizeOf #ifdef USE_SERIALIZE - (case size :: Size a of - ConstSize x -> x - VarSize f -> f val) + variableSizeOf val #else sizeOf (Proxy :: Proxy a) #endif