@@ -1,4 +1,4 @@
1−{-# Language OverloadedStrings, RecordWildCards, StandaloneDeriving #-}
1+{-# Language OverloadedStrings, RecordWildCards, StandaloneDeriving, CPP #-}
22{-# OPTIONS_GHC -fno-warn-orphans #-}
33
44module Instances where
@@ -6,12 +6,16 @@ module Instances where
66import Types
77import Data.Function (on)
88import Control.Monad
9−import Test.QuickCheck (Arbitrary(..), Gen, choose, oneof, elements)
9+import Test.QuickCheck
10+ ( Arbitrary(..), Gen, choose, oneof, elements
11+ , resize, listOf1, getNonNegative
12+ )
1013import Data.Time.Clock (DiffTime, UTCTime(..), picosecondsToDiffTime)
1114import Data.Fixed (Pico)
1215import Data.Time (ZonedTime(..), LocalTime(..), TimeZone(..),
1316 hoursToTimeZone, Day(..), TimeOfDay(..),
1417 NominalDiffTime)
18+import Data.Version
1519import qualified Data.Text as T
1620import qualified Data.Map as Map
1721import Data.Text (Text)
@@ -153,3 +157,16 @@ instance ApproxEq Char where
153157
154158instance (ApproxEq a) => ApproxEq [a] where
155159 a =~ b = length a == length b && all (uncurry (=~)) (zip a b)
160+
161+instance Arbitrary Version where
162+ arbitrary = makeVersion . fmap getNonNegative <$> resize 4 (listOf1 arbitrary)
163+
164+-- Version tags are deprecated, so we avoid using them in the Arbitrary
165+-- instance. However, the recommended constructor 'makeVersion' is not
166+-- exported by "Data.Version" until base-4.8.0.0. For previous versions,
167+-- a definition is given below.
168+
169+#if !MIN_VERSION_base(4,8,0)
170+makeVersion :: [Int] -> Version
171+makeVersion b = Version b []
172+#endif