@@ -11,24 +11,29 @@ module Instances () where
11import Prelude ()
11import Prelude ()
12import Prelude.Compat
12import Prelude.Compat
14−import Control.Applicative (Const(..), empty)
14+import Control.Applicative (empty)
15import Control.Monad
15import Control.Monad
16import Data.Aeson.Types
16import Data.Aeson.Types
17import Data.Function (on)
17import Data.Function (on)
18import Data.Functor.Compose (Compose (..))
18import Data.Functor.Compose (Compose (..))
19−import Data.Functor.Identity (Identity (..))
20−import Data.List.NonEmpty (NonEmpty(..))
21import Data.Proxy (Proxy(..))
19import Data.Proxy (Proxy(..))
22import Data.Tagged (Tagged(..))
20import Data.Tagged (Tagged(..))
23import Data.Time (ZonedTime(..), TimeZone(..))
21import Data.Time (ZonedTime(..), TimeZone(..))
24import Data.Time.Clock (UTCTime(..))
22import Data.Time.Clock (UTCTime(..))
26import Functions
23import Functions
27−import Test.QuickCheck (Arbitrary(..), getNonNegative, elements, listOf1, oneof, resize)
24+import Test.QuickCheck (Arbitrary(..), elements, oneof)
28import Types
25import Types
29import qualified Data.DList as DList
26import qualified Data.DList as DList
30import qualified Data.HashMap.Strict as HM
27import qualified Data.HashMap.Strict as HM
29+#if !MIN_VERSION_QuickCheck(2,9,0)
30+import Control.Applicative (Const(..))
31+import Data.List.NonEmpty (NonEmpty(..))
32+import Data.Functor.Identity (Identity (..))
34+import Test.QuickCheck (getNonNegative, listOf1, resize)
32import Data.Orphans ()
37import Data.Orphans ()
33import Test.QuickCheck.Instances ()
38import Test.QuickCheck.Instances ()
34#if MIN_VERSION_base(4,7,0)
39#if MIN_VERSION_base(4,7,0)
@@ -172,21 +177,11 @@ instance ApproxEq Char where
172instance (ApproxEq a) => ApproxEq [a] where
177instance (ApproxEq a) => ApproxEq [a] where
173 a =~ b = length a == length b && all (uncurry (=~)) (zip a b)
178 a =~ b = length a == length b && all (uncurry (=~)) (zip a b)
175−instance Arbitrary Version where
176− arbitrary = makeVersion . fmap getNonNegative <$> resize 4 (listOf1 arbitrary)
178−instance Arbitrary a => Arbitrary (NonEmpty a) where
179− arbitrary = (:|) <$> arbitrary <*> arbitrary
181-- Version tags are deprecated, so we avoid using them in the Arbitrary
180-- Version tags are deprecated, so we avoid using them in the Arbitrary
182-- instance. However, the recommended constructor 'makeVersion' is not
181-- instance. However, the recommended constructor 'makeVersion' is not
183-- exported by "Data.Version" until base-4.8.0.0. For previous versions,
182-- exported by "Data.Version" until base-4.8.0.0. For previous versions,
184-- a definition is given below.
183-- a definition is given below.
186−#if !MIN_VERSION_base(4,8,0)
187−makeVersion :: [Int] -> Version
188−makeVersion b = Version b []
191#if !MIN_VERSION_base(4,8,0) && !MIN_VERSION_QuickCheck(2,8,3)
186#if !MIN_VERSION_base(4,8,0) && !MIN_VERSION_QuickCheck(2,8,3)
192instance Arbitrary Natural where
187instance Arbitrary Natural where
@@ -199,15 +194,27 @@ instance Arbitrary (Proxy a) where
199instance Arbitrary b => Arbitrary (Tagged a b) where
194instance Arbitrary b => Arbitrary (Tagged a b) where
200 arbitrary = Tagged <$> arbitrary
195 arbitrary = Tagged <$> arbitrary
197+instance Arbitrary a => Arbitrary (DList.DList a) where
198+ arbitrary = DList.fromList <$> arbitrary
200+instance Arbitrary (f (g a)) => Arbitrary (Compose f g a) where
201+ arbitrary = Compose <$> arbitrary
203+#if !MIN_VERSION_QuickCheck(2,9,0)
202instance Arbitrary a => Arbitrary (Const a b) where
204instance Arbitrary a => Arbitrary (Const a b) where
203 arbitrary = Const <$> arbitrary
205 arbitrary = Const <$> arbitrary
205−instance Arbitrary a => Arbitrary (DList.DList a) where
207+instance Arbitrary a => Arbitrary (NonEmpty a) where
206− arbitrary = DList.fromList <$> arbitrary
208+ arbitrary = (:|) <$> arbitrary <*> arbitrary
210+instance Arbitrary Version where
211+ arbitrary = makeVersion . fmap getNonNegative <$> resize 4 (listOf1 arbitrary)
213+#if !MIN_VERSION_base(4,8,0)
214+makeVersion :: [Int] -> Version
215+makeVersion b = Version b []
208−-- would like to have -- https://github.com/nick8325/quickcheck/issues/73
209instance Arbitrary a => Arbitrary (Identity a) where
218instance Arbitrary a => Arbitrary (Identity a) where
210 arbitrary = Identity <$> arbitrary
219 arbitrary = Identity <$> arbitrary
212−instance Arbitrary (f (g a)) => Arbitrary (Compose f g a) where
213− arbitrary = Compose <$> arbitrary