on master help sign in
Merge pull request #464 from phadej/quickcheck-2.9-second-try
e27915eAdam Bergmark
aeson.cabal+1−1
@@ -173,7 +173,7 @@ test-suite tests
173
173
174 build-depends:
174 build-depends:
175 HUnit,
175 HUnit,
176− QuickCheck >= 2.7 && <2.8.3,
176+ QuickCheck >= 2.7 && <2.9.2,
177 aeson,
177 aeson,
178 attoparsec,
178 attoparsec,
179 base,
179 base,
tests/Instances.hs+28−21
@@ -11,24 +11,29 @@ module Instances () where
11import Prelude ()
11import Prelude ()
12import Prelude.Compat
12import Prelude.Compat
13
13
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(..))
25−import Data.Version
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
31
28
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 (..))
33+import Data.Version
34+import Test.QuickCheck (getNonNegative, listOf1, resize)
35+#endif
36+
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)
174
179
175−instance Arbitrary Version where
176− arbitrary = makeVersion . fmap getNonNegative <$> resize 4 (listOf1 arbitrary)
177−
178−instance Arbitrary a => Arbitrary (NonEmpty a) where
179− arbitrary = (:|) <$> arbitrary <*> arbitrary
180−
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.
185
184
186−#if !MIN_VERSION_base(4,8,0)
187−makeVersion :: [Int] -> Version
188−makeVersion b = Version b []
189−#endif
190
185
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
201
196
197+instance Arbitrary a => Arbitrary (DList.DList a) where
198+ arbitrary = DList.fromList <$> arbitrary
199+
200+instance Arbitrary (f (g a)) => Arbitrary (Compose f g a) where
201+ arbitrary = Compose <$> arbitrary
202+
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
204
206
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
209+
210+instance Arbitrary Version where
211+ arbitrary = makeVersion . fmap getNonNegative <$> resize 4 (listOf1 arbitrary)
212+
213+#if !MIN_VERSION_base(4,8,0)
214+makeVersion :: [Int] -> Version
215+makeVersion b = Version b []
216+#endif
207
217
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
211−
220+#endif
212−instance Arbitrary (f (g a)) => Arbitrary (Compose f g a) where
213− arbitrary = Compose <$> arbitrary