1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
{-# LANGUAGE CPP #-}
{-# OPTIONS_GHC -Wall #-}
module Spec.ShowRead where
import Control.Applicative (liftA2)
import Data.Complex (Complex)
import Data.Fixed (E0, E1, E12, Fixed, HasResolution)
import Data.Int (Int64, Int8)
import Data.Orphans ()
import Data.Proxy (Proxy(Proxy))
import Data.Ratio (Ratio)
import Data.Word
import Test.QuickCheck (Arbitrary(arbitrary), elements)
#if MIN_VERSION_QuickCheck(2,8,2)
import Data.IntMap (IntMap)
import Data.IntSet (IntSet)
import Data.Map (Map)
import Data.Sequence (Seq)
import Data.Set (Set)
#endif
#if MIN_VERSION_QuickCheck(2,9,0)
import Control.Applicative (Const, ZipList)
import Data.Functor.Constant (Constant)
import Data.Functor.Identity (Identity)
import Data.Version (Version)
#endif
#if MIN_VERSION_QuickCheck(2,10,0)
import Data.Functor.Compose (Compose)
import Data.Functor.Product (Product)
#endif
import Test.QuickCheck.Classes
data Prefix = Prefix | Prefix' | Prefix_
deriving (Eq, Read, Show)
instance Arbitrary Prefix where
arbitrary = elements [Prefix, Prefix', Prefix_]
data WeirdRecord = (:*) { left :: Int, right :: Int }
deriving (Eq, Read, Show)
instance Arbitrary WeirdRecord where
arbitrary = liftA2 (:*) arbitrary arbitrary
lawsApplied :: [(String,[Laws])]
lawsApplied =
[ -- local
("Prefix", allShowReadLaws (Proxy :: Proxy Prefix))
, ("WeirdRecord", allShowReadLaws (Proxy :: Proxy WeirdRecord))
-- base
, ("()", allShowReadLaws (Proxy :: Proxy ()))
, ("Bool", allShowReadLaws (Proxy :: Proxy Bool))
, ("Char", allShowReadLaws (Proxy :: Proxy Char))
, ("Complex Float", allShowReadLaws (Proxy :: Proxy (Complex Float)))
, ("Complex Double", allShowReadLaws (Proxy :: Proxy (Complex Double)))
, ("Double", allShowReadLaws (Proxy :: Proxy Double))
, ("Either", allShowReadLaws (Proxy :: Proxy (Either Int Int)))
, ("Fixed E12", allFixedLaws (Proxy :: Proxy (Fixed E12)))
-- , ("Fixed E9", allFixedLaws (Proxy :: Proxy (Fixed E9)))
-- , ("Fixed E6", allFixedLaws (Proxy :: Proxy (Fixed E6)))
-- , ("Fixed E3", allFixedLaws (Proxy :: Proxy (Fixed E3)))
-- , ("Fixed E2", allFixedLaws (Proxy :: Proxy (Fixed E2)))
, ("Fixed E1", allFixedLaws (Proxy :: Proxy (Fixed E1)))
, ("Fixed E0", allFixedLaws (Proxy :: Proxy (Fixed E0)))
, ("Float", allShowReadLaws (Proxy :: Proxy Float))
, ("Int", allShowReadLaws (Proxy :: Proxy Int))
-- , ("Int16", allShowReadLaws (Proxy :: Proxy Int16))
-- , ("Int32", allShowReadLaws (Proxy :: Proxy Int32))
, ("Int64", allShowReadLaws (Proxy :: Proxy Int64))
, ("Int8", allShowReadLaws (Proxy :: Proxy Int8))
, ("Integer", allShowReadLaws (Proxy :: Proxy Integer))
, ("List", allShowReadLaws (Proxy :: Proxy [Int]))
, ("Maybe", allShowReadLaws (Proxy :: Proxy (Maybe Int)))
, ("Ordering", allShowReadLaws (Proxy :: Proxy Ordering))
, ("Ratio", allShowReadLaws (Proxy :: Proxy (Ratio Int)))
, ("Tuple2", allShowReadLaws (Proxy :: Proxy (Int,Int)))
, ("Tuple3", allShowReadLaws (Proxy :: Proxy (Int,Int,Int)))
, ("Word", allShowReadLaws (Proxy :: Proxy Word))
-- , ("Word16", allShowReadLaws (Proxy :: Proxy Word16))
-- , ("Word32", allShowReadLaws (Proxy :: Proxy Word32))
, ("Word64", allShowReadLaws (Proxy :: Proxy Word64))
, ("Word8", allShowReadLaws (Proxy :: Proxy Word8))
#if MIN_VERSION_QuickCheck(2,9,0)
, ("Const", allShowReadLaws (Proxy :: Proxy (Const Int Int)))
, ("Constant", allShowReadLaws (Proxy :: Proxy (Constant Int Int)))
, ("Identity", allShowReadLaws (Proxy :: Proxy (Identity Int)))
, ("Version", allShowReadLaws (Proxy :: Proxy Version))
, ("ZipList", allShowReadLaws (Proxy :: Proxy (ZipList Int)))
#endif
#if MIN_VERSION_QuickCheck(2,10,0)
, ("Compose", allShowReadLaws (Proxy :: Proxy (Compose [] Maybe Int)))
, ("Product", allShowReadLaws (Proxy :: Proxy (Product [] Maybe Int)))
#endif
-- containers
#if MIN_VERSION_QuickCheck(2,8,2)
, ("IntMap", allShowReadLaws (Proxy :: Proxy (IntMap Int)))
, ("IntSet", allShowReadLaws (Proxy :: Proxy IntSet))
, ("Map", allShowReadLaws (Proxy :: Proxy (Map Int Int)))
, ("Seq", allShowReadLaws (Proxy :: Proxy (Seq Int)))
, ("Set", allShowReadLaws (Proxy :: Proxy (Set Int)))
#endif
]
allShowReadLaws :: (Show a, Read a, Eq a, Arbitrary a) => Proxy a -> [Laws]
allShowReadLaws p = map ($p)
[ showLaws
, showReadLaws
]
allFixedLaws :: HasResolution e => Proxy (Fixed e) -> [Laws]
allFixedLaws p = map ($p)
[ showLaws
#if MIN_VERSION_base(4,7,0)
-- Earlier versions of base have a buggy read instance.
, showReadLaws
#endif
]
|