git.iko.soy/typeable/http-api-data
on master help sign in
Use quickcheck-instances and newer QuickCheck, less own orphan instances
commit042adad6bbfeea88b7454542e568d00936e5a9e0 authorOleg Grenrus <oleg.grenrus@iki.fi> dateFri 23 Sep 2016, 19:54 (10 years ago) parente8c7d07
6 files changed+31−44
http-api-data.cabal+2−1 stack-ghc-7.10.yaml+2−1 stack-ghc-7.8.yaml+3 stack.yaml+2−1 test/Web/Internal/HttpApiDataSpec.hs+21−4 test/Web/Internal/TestInstances.hs+1−37
http-api-data.cabal+2−1
@@ -59,7 +59,8 @@ test-suite spec
5959 , hspec >= 1.3
6060 , base >= 4 && < 5
6161 , bytestring
62− , QuickCheck
62+ , QuickCheck >=2.9
63+ , quickcheck-instances >= 0.3.12
6364 , unordered-containers
6465 , http-api-data
6566 , text
stack-ghc-7.10.yaml+2−1
@@ -7,5 +7,6 @@ flags:
77 http-api-data:
88 use-text-show: false
99
10−extra-deps: []
10+extra-deps:
11+- QuickCheck-2.9.2
1112extra-package-dbs: []
stack-ghc-7.8.yaml+3
@@ -20,4 +20,7 @@ extra-deps:
2020- base-orphans-0.5.4
2121- generic-deriving-1.9.0
2222- doctest-0.11.0
23+- QuickCheck-2.9.2
24+- quickcheck-instances-0.3.12
25+- quickcheck-io-0.1.3
2326extra-package-dbs: []
stack.yaml+2−1
@@ -7,5 +7,6 @@ flags:
77 http-api-data:
88 use-text-show: false
99
10−extra-deps: []
10+extra-deps:
11+- QuickCheck-2.9.2
1112extra-package-dbs: []
test/Web/Internal/HttpApiDataSpec.hs+21−4
@@ -62,10 +62,10 @@ spec = do
6262 checkUrlPiece (Proxy :: Proxy T.Text) "Text.Strict"
6363 checkUrlPiece (Proxy :: Proxy L.Text) "Text.Lazy"
6464 checkUrlPiece (Proxy :: Proxy Day) "Day"
65− checkUrlPiece (Proxy :: Proxy LocalTime) "LocalTime"
66− checkUrlPiece (Proxy :: Proxy ZonedTime) "ZonedTime"
67− checkUrlPiece (Proxy :: Proxy UTCTime) "UTCTime"
68− checkUrlPiece (Proxy :: Proxy NominalDiffTime) "NominalDiffTime"
65+ checkUrlPiece' localTimeGen "LocalTime"
66+ checkUrlPiece' zonedTimeGen "ZonedTime"
67+ checkUrlPiece' utcTimeGen "UTCTime"
68+ checkUrlPiece' nominalDiffTimeGen "NominalDiffTime"
6969 checkUrlPiece (Proxy :: Proxy Version) "Version"
7070 checkUrlPiece' uuidGen "UUID"
7171
@@ -90,3 +90,20 @@ spec = do
9090
9191uuidGen :: Gen UUID.UUID
9292uuidGen = 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
99 ) where
1010
1111import Control.Applicative
12−import qualified Data.ByteString.Lazy.Char8 as BSL
1312import Data.Char
1413import qualified Data.HashMap.Strict as HashMap
1514import qualified Data.Text as T
16−import qualified Data.Text.Lazy as L
1715import Data.Time
18−import Data.Version
1916import GHC.Exts (fromList)
2017import GHC.Generics
2118
2219import Test.QuickCheck
20+import Test.QuickCheck.Instances ()
2321
2422import Web.Internal.FormUrlEncoded
2523import Web.Internal.HttpApiData
2624
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−
4425instance Eq ZonedTime where
4526 ZonedTime t (TimeZone x _ _) == ZonedTime t' (TimeZone y _ _) = t == t' && x == y
4627
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−
6428instance Arbitrary Form where
6529 arbitrary = fromList <$> arbitrary
6630