Skip to content

Commit

Permalink
Abstact size and simplify the CPP statement in Unbox tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adithyaov committed Aug 18, 2023
1 parent 3aba909 commit c4343a4
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions test/Streamly/Test/Data/Unbox.hs
Original file line number Diff line number Diff line change
Expand Up @@ -174,16 +174,25 @@ $(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
-> IO ()
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
Expand All @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit c4343a4

Please sign in to comment.