Skip to content

Commit

Permalink
Add roundtrip tests for GHC.Fingerprint.
Browse files Browse the repository at this point in the history
  • Loading branch information
kolmodin committed Jun 3, 2015
1 parent 66146ae commit 2a84d67
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/Data/Binary/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
#define HAS_NATURAL
#endif

#if __GLASGOW_HASKELL__ >= 704
#define HAS_GHC_FINGERPRINT
#endif

-----------------------------------------------------------------------------
-- |
-- Module : Data.Binary.Class
Expand Down Expand Up @@ -77,7 +81,7 @@ import qualified Data.Sequence as Seq
import qualified Data.Foldable as Fold
#endif

#if __GLASGOW_HASKELL__ >= 704
#ifdef HAS_GHC_FINGERPRINT
import GHC.Fingerprint
#endif

Expand Down Expand Up @@ -591,7 +595,7 @@ instance (Binary i, Ix i, Binary e, IArray UArray e) => Binary (UArray i e) wher
------------------------------------------------------------------------
-- Fingerprints

#if __GLASGOW_HASKELL__ >= 704
#ifdef HAS_GHC_FINGERPRINT
instance Binary Fingerprint where
put (Fingerprint x1 x2) = do
put x1
Expand Down
25 changes: 23 additions & 2 deletions tests/QC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ module Main ( main ) where
#define HAS_NATURAL
#endif

#if __GLASGOW_HASKELL__ >= 704
#define HAS_GHC_FINGERPRINT
#endif

import Control.Applicative
import Control.Exception as C (SomeException,
catch, evaluate)
import Control.Monad (unless)
import Control.Monad (unless, liftM2)
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as L
import qualified Data.ByteString.Lazy.Internal as L
Expand All @@ -20,6 +24,10 @@ import System.IO.Unsafe
import Numeric.Natural
#endif

#ifdef HAS_GHC_FINGERPRINT
import GHC.Fingerprint
#endif

import Test.Framework
import Test.Framework.Providers.QuickCheck2
import Test.QuickCheck
Expand Down Expand Up @@ -376,6 +384,16 @@ prop_test_Natural = forAll (gen :: Gen Natural) test

------------------------------------------------------------------------

#ifdef HAS_GHC_FINGERPRINT
prop_test_GHC_Fingerprint :: Property
prop_test_GHC_Fingerprint = forAll gen test
where
gen :: Gen Fingerprint
gen = liftM2 Fingerprint arbitrary arbitrary
#endif

------------------------------------------------------------------------

type T a = a -> Property
type B a = a -> Bool

Expand Down Expand Up @@ -454,7 +472,10 @@ tests =
, ("Int", p (test :: T Int ))
, ("Integer", p (test :: T Integer ))
#ifdef HAS_NATURAL
, ("Natural", (prop_test_Natural :: Property ))
, ("Natural", prop_test_Natural )
#endif
#ifdef HAS_GHC_FINGERPRINT
, ("GHC.Fingerprint", prop_test_GHC_Fingerprint )
#endif

, ("Float", p (test :: T Float ))
Expand Down

0 comments on commit 2a84d67

Please sign in to comment.