[commit: packages/binary] master: Add roundtrip tests for GHC.Fingerprint. (2a84d67)
git at git.haskell.org
git at git.haskell.org
Wed Dec 16 09:42:23 UTC 2015
Repository : ssh://git@git.haskell.org/binary
On branch : master
Link : http://git.haskell.org/packages/binary.git/commitdiff/2a84d6707a72fb21891ba842bcfff240d52e16cb
>---------------------------------------------------------------
commit 2a84d6707a72fb21891ba842bcfff240d52e16cb
Author: Lennart Kolmodin <kolmodin at google.com>
Date: Wed Jun 3 11:52:46 2015 -0700
Add roundtrip tests for GHC.Fingerprint.
>---------------------------------------------------------------
2a84d6707a72fb21891ba842bcfff240d52e16cb
src/Data/Binary/Class.hs | 8 ++++++--
tests/QC.hs | 25 +++++++++++++++++++++++--
2 files changed, 29 insertions(+), 4 deletions(-)
diff --git a/src/Data/Binary/Class.hs b/src/Data/Binary/Class.hs
index 79a30b2..4259165 100644
--- a/src/Data/Binary/Class.hs
+++ b/src/Data/Binary/Class.hs
@@ -10,6 +10,10 @@
#define HAS_NATURAL
#endif
+#if __GLASGOW_HASKELL__ >= 704
+#define HAS_GHC_FINGERPRINT
+#endif
+
-----------------------------------------------------------------------------
-- |
-- Module : Data.Binary.Class
@@ -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
@@ -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
diff --git a/tests/QC.hs b/tests/QC.hs
index addf185..58991a4 100644
--- a/tests/QC.hs
+++ b/tests/QC.hs
@@ -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
@@ -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
@@ -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
@@ -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 ))
More information about the ghc-commits
mailing list