git.iko.soy/typeable/http-api-data
on master help sign in
Use quickcheck-instances and newer QuickCheck, less own orphan instances
042adadOleg Grenrus
http-api-data.cabal+2−1
@@ -59,7 +59,8 @@ test-suite spec
59 , hspec >= 1.3
59 , hspec >= 1.3
60 , base >= 4 && < 5
60 , base >= 4 && < 5
61 , bytestring
61 , bytestring
62− , QuickCheck
62+ , QuickCheck >=2.9
63+ , quickcheck-instances >= 0.3.12
63 , unordered-containers
64 , unordered-containers
64 , http-api-data
65 , http-api-data
65 , text
66 , text
stack-ghc-7.10.yaml+2−1
@@ -7,5 +7,6 @@ flags:
7 http-api-data:
7 http-api-data:
8 use-text-show: false
8 use-text-show: false
9
9
10−extra-deps: []
10+extra-deps:
11+- QuickCheck-2.9.2
11extra-package-dbs: []
12extra-package-dbs: []
stack-ghc-7.8.yaml+3
@@ -20,4 +20,7 @@ extra-deps:
20- base-orphans-0.5.4
20- base-orphans-0.5.4
21- generic-deriving-1.9.0
21- generic-deriving-1.9.0
22- doctest-0.11.0
22- doctest-0.11.0
23+- QuickCheck-2.9.2
24+- quickcheck-instances-0.3.12
25+- quickcheck-io-0.1.3
23extra-package-dbs: []
26extra-package-dbs: []
stack.yaml+2−1
@@ -7,5 +7,6 @@ flags:
7 http-api-data:
7 http-api-data:
8 use-text-show: false
8 use-text-show: false
9
9
10−extra-deps: []
10+extra-deps:
11+- QuickCheck-2.9.2
11extra-package-dbs: []
12extra-package-dbs: []
test/Web/Internal/HttpApiDataSpec.hs+21−4
@@ -62,10 +62,10 @@ spec = do
62 checkUrlPiece (Proxy :: Proxy T.Text) "Text.Strict"
62 checkUrlPiece (Proxy :: Proxy T.Text) "Text.Strict"
63 checkUrlPiece (Proxy :: Proxy L.Text) "Text.Lazy"
63 checkUrlPiece (Proxy :: Proxy L.Text) "Text.Lazy"
64 checkUrlPiece (Proxy :: Proxy Day) "Day"
64 checkUrlPiece (Proxy :: Proxy Day) "Day"
65− checkUrlPiece (Proxy :: Proxy LocalTime) "LocalTime"
65+ checkUrlPiece' localTimeGen "LocalTime"
66− checkUrlPiece (Proxy :: Proxy ZonedTime) "ZonedTime"
66+ checkUrlPiece' zonedTimeGen "ZonedTime"
67− checkUrlPiece (Proxy :: Proxy UTCTime) "UTCTime"
67+ checkUrlPiece' utcTimeGen "UTCTime"
68− checkUrlPiece (Proxy :: Proxy NominalDiffTime) "NominalDiffTime"
68+ checkUrlPiece' nominalDiffTimeGen "NominalDiffTime"
69 checkUrlPiece (Proxy :: Proxy Version) "Version"
69 checkUrlPiece (Proxy :: Proxy Version) "Version"
70 checkUrlPiece' uuidGen "UUID"
70 checkUrlPiece' uuidGen "UUID"
71
71
@@ -90,3 +90,20 @@ spec = do
90
90
91uuidGen :: Gen UUID.UUID
91uuidGen :: Gen UUID.UUID
92uuidGen = UUID.fromWords <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary
92uuidGen = UUID.fromWords <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary
93+
94+-- TODO: this generators don't generate full range items
95+localTimeGen :: Gen LocalTime
96+localTimeGen = LocalTime
97+ <$> arbitrary
98+ <*> liftA3 TimeOfDay (choose (0, 23)) (choose (0, 59)) (fromInteger <$> choose (0, 60))
99+
100+zonedTimeGen :: Gen ZonedTime
101+zonedTimeGen = ZonedTime
102+ <$> localTimeGen -- Note: not arbitrary!
103+ <*> liftA3 TimeZone arbitrary arbitrary (vectorOf 3 (elements ['A'..'Z']))
104+
105+utcTimeGen :: Gen UTCTime
106+utcTimeGen = UTCTime <$> arbitrary <*> fmap fromInteger (choose (0, 86400))
107+
108+nominalDiffTimeGen :: Gen NominalDiffTime
109+nominalDiffTimeGen = fromInteger <$> arbitrary
test/Web/Internal/TestInstances.hs+1−37
@@ -9,58 +9,22 @@ module Web.Internal.TestInstances
9 ) where
9 ) where
10
10
11import Control.Applicative
11import Control.Applicative
12−import qualified Data.ByteString.Lazy.Char8 as BSL
13import Data.Char
12import Data.Char
14import qualified Data.HashMap.Strict as HashMap
13import qualified Data.HashMap.Strict as HashMap
15import qualified Data.Text as T
14import qualified Data.Text as T
16−import qualified Data.Text.Lazy as L
17import Data.Time
15import Data.Time
18−import Data.Version
19import GHC.Exts (fromList)
16import GHC.Exts (fromList)
20import GHC.Generics
17import GHC.Generics
21
18
22import Test.QuickCheck
19import Test.QuickCheck
20+import Test.QuickCheck.Instances ()
23
21
24import Web.Internal.FormUrlEncoded
22import Web.Internal.FormUrlEncoded
25import Web.Internal.HttpApiData
23import Web.Internal.HttpApiData
26
24
27−instance Arbitrary T.Text where
28− arbitrary = T.pack <$> arbitrary
29−
30−instance Arbitrary L.Text where
31− arbitrary = L.pack <$> arbitrary
32−
33−instance Arbitrary BSL.ByteString where
34− arbitrary = BSL.pack <$> arbitrary
35−
36−instance Arbitrary Day where
37− arbitrary = liftA3 fromGregorian (fmap abs arbitrary) arbitrary arbitrary
38−
39−instance Arbitrary LocalTime where
40− arbitrary = LocalTime
41− <$> arbitrary
42− <*> liftA3 TimeOfDay (choose (0, 23)) (choose (0, 59)) (fromInteger <$> choose (0, 60))
43−
44instance Eq ZonedTime where
25instance Eq ZonedTime where
45 ZonedTime t (TimeZone x _ _) == ZonedTime t' (TimeZone y _ _) = t == t' && x == y
26 ZonedTime t (TimeZone x _ _) == ZonedTime t' (TimeZone y _ _) = t == t' && x == y
46
27
47−instance Arbitrary ZonedTime where
48− arbitrary = ZonedTime
49− <$> arbitrary
50− <*> liftA3 TimeZone arbitrary arbitrary (vectorOf 3 (elements ['A'..'Z']))
51−
52−instance Arbitrary UTCTime where
53− arbitrary = UTCTime <$> arbitrary <*> fmap fromInteger (choose (0, 86400))
54−
55−instance Arbitrary NominalDiffTime where
56− arbitrary = fromInteger <$> arbitrary
57−
58−instance Arbitrary Version where
59− arbitrary = (version . map abs) <$> nonempty
60− where
61− version branch = Version branch []
62− nonempty = liftA2 (:) arbitrary arbitrary
63−
64instance Arbitrary Form where
28instance Arbitrary Form where
65 arbitrary = fromList <$> arbitrary
29 arbitrary = fromList <$> arbitrary
66
30