on master help sign in
Abstact size and simplify the CPP statement in Unbox tests
commitc4343a47f75a9cd864dfee61557f30a6119a3401 authorAdithya Kumar <adithya@composewell.com> dateWed 16 Aug 2023, 19:03 (3 years ago) parent3aba909
1 file changed+15−9
test/Streamly/Test/Data/Unbox.hs+15−9
test/Streamly/Test/Data/Unbox.hs+15−9
@@ -174,6 +174,17 @@ $(deriveSerialize ''Identity)
174174-- Test helpers
175175--------------------------------------------------------------------------------
176176
177+#ifdef USE_SERIALIZE
178+variableSizeOf ::
179+ forall a. Serialize a
180+ => a
181+ -> Int
182+variableSizeOf val =
183+ case size :: Size a of
184+ ConstSize x -> x
185+ VarSize f -> f val
186+#endif
187+
177188testSerialization ::
178189 forall a. (Eq a, Show a, TYPE_CLASS a)
179190 => a
@@ -181,9 +192,7 @@ testSerialization ::
181192testSerialization val = do
182193 arr <- newBytes
183194#ifdef USE_SERIALIZE
184− (case size :: Size a of
185− ConstSize x -> x
186− VarSize f -> f val)
195+ (variableSizeOf val)
187196#else
188197 (sizeOf (Proxy :: Proxy a))
189198#endif
@@ -195,10 +204,9 @@ testGenericConsistency ::
195204 ( Eq a
196205 , Show a
197206#ifdef USE_SERIALIZE
198− , Serialize a, Unbox a
199−#else
200− , Unbox a
207+ , Serialize a
201208#endif
209+ , Unbox a
202210 , Generic a
203211 , SizeOfRep (Rep a)
204212 , PeekRep (Rep a)
@@ -210,9 +218,7 @@ testGenericConsistency val = do
210218
211219 -- Test the generic sizeOf
212220#ifdef USE_SERIALIZE
213− (case size :: Size a of
214− ConstSize x -> x
215− VarSize f -> f val)
221+ variableSizeOf val
216222#else
217223 sizeOf (Proxy :: Proxy a)
218224#endif