git.iko.soy/servant-quickcheck
on master help sign in
Documentation improvements
commit26a6171265568d604238b973109964729777a2b5 authorJulian K. Arni <jkarni@gmail.com> dateMon 9 May 2016, 18:20 (10 years ago) parentc5172a1
4 files changed+34−10
src/Servant/QuickCheck.hs+7 src/Servant/QuickCheck/Internal/Equality.hs+2−2 src/Servant/QuickCheck/Internal/Predicates.hs+21−4 src/Servant/QuickCheck/Internal/QuickCheck.hs+4−4
src/Servant/QuickCheck.hs+7
@@ -59,9 +59,12 @@ module Servant.QuickCheck
5959 , defaultArgs
6060
6161 -- ** Re-exports
62+ -- | Types and constructors from other packages that are generally needed for
63+ -- using @servant-quickcheck@.
6264 , BaseUrl(..)
6365 , Scheme(..)
6466 , Args(..)
67+ , Proxy(..)
6568
6669
6770 ) where
@@ -69,6 +72,10 @@ module Servant.QuickCheck
6972import Servant.QuickCheck.Internal
7073import Servant.Client (BaseUrl(..), Scheme(..))
7174import Test.QuickCheck (Args(..), stdArgs)
75+import Data.Proxy (Proxy(..))
7276
77+-- | QuickCheck @Args@ with 1000 rather than 100 test cases.
78+--
79+-- /Since 0.0.0.0/
7380defaultArgs :: Args
7481defaultArgs = stdArgs { maxSuccess = 1000 }
src/Servant/QuickCheck/Internal/Equality.hs+2−2
@@ -14,12 +14,12 @@ instance Monoid (ResponseEquality b) where
1414
1515-- | Use `Eq` instance for `Response`
1616--
17−-- #SINCE#
17+-- /Since 0.0.0.0/
1818allEquality :: Eq b => ResponseEquality b
1919allEquality = ResponseEquality (==)
2020
2121-- | ByteString `Eq` instance over the response body.
2222--
23−-- #SINCE#
23+-- /Since 0.0.0.0/
2424bodyEquality :: Eq b => ResponseEquality b
2525bodyEquality = ResponseEquality ((==) `on` responseBody)
src/Servant/QuickCheck/Internal/Predicates.hs+21−4
@@ -31,6 +31,8 @@ import Network.HTTP.Types (methodGet, methodHead, parseMethod,
3131-- indication of how to proceed or what went wrong.
3232--
3333-- This function checks that the response code is not 500.
34+--
35+-- /Since 0.0.0.0/
3436not500 :: ResponsePredicate Text Bool
3537not500 = ResponsePredicate "not500" (\resp -> not $ responseStatus resp == status500)
3638
@@ -53,6 +55,8 @@ not500 = ResponsePredicate "not500" (\resp -> not $ responseStatus resp == statu
5355--
5456-- * JSON Grammar: <https://tools.ietf.org/html/rfc7159#section-2 RFC 7159 Section 2>
5557-- * JSON Grammar: <https://tools.ietf.org/html/rfc4627#section-2 RFC 4627 Section 2>
58+--
59+-- /Since 0.0.0.0/
5660onlyJsonObjects :: ResponsePredicate Text Bool
5761onlyJsonObjects
5862 = ResponsePredicate "onlyJsonObjects" (\resp -> case decode (responseBody resp) of
@@ -76,6 +80,8 @@ onlyJsonObjects
7680--
7781-- * 201 Created: <https://tools.ietf.org/html/rfc7231#section-6.3.2 RFC 7231 Section 6.3.2>
7882-- * Location header: <https://tools.ietf.org/html/rfc7231#section-7.1.2 RFC 7231 Section 7.1.2>
83+--
84+-- /Since 0.0.0.0/
7985createContainsValidLocation :: RequestPredicate Text Bool
8086createContainsValidLocation
8187 = RequestPredicate
@@ -114,6 +120,8 @@ getsHaveLastModifiedHeader
114120--
115121-- * @Allow@ header: <https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html RFC 2616 Section 14.7>
116122-- * Status 405: <https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html RFC 2616 Section 10.4.6>
123+--
124+-- /Since 0.0.0.0/
117125notAllowedContainsAllowHeader :: RequestPredicate Text Bool
118126notAllowedContainsAllowHeader
119127 = RequestPredicate
@@ -144,6 +152,8 @@ notAllowedContainsAllowHeader
144152-- __References__:
145153--
146154-- * @Accept@ header: <https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html RFC 2616 Section 14.1>
155+--
156+-- /Since 0.0.0.0/
147157honoursAcceptHeader :: RequestPredicate Text Bool
148158honoursAcceptHeader
149159 = RequestPredicate
@@ -171,7 +181,7 @@ honoursAcceptHeader
171181--
172182-- * @Cache-Control@ header: <https://tools.ietf.org/html/rfc7234#section-5.2 RFC 7234 Section 5.2>
173183--
174−-- #SINCE#
184+-- /Since 0.0.0.0/
175185getsHaveCacheControlHeader :: RequestPredicate Text Bool
176186getsHaveCacheControlHeader
177187 = RequestPredicate
@@ -188,7 +198,7 @@ getsHaveCacheControlHeader
188198--
189199-- Like 'getsHaveCacheControlHeader', but for @HEAD@ requests.
190200--
191−-- #SINCE#
201+-- /Since 0.0.0.0/
192202headsHaveCacheControlHeader :: RequestPredicate Text Bool
193203headsHaveCacheControlHeader
194204 = RequestPredicate
@@ -260,7 +270,7 @@ linkHeadersAreValid
260270--
261271-- * @WWW-Authenticate@ header: <https://tools.ietf.org/html/rfc7235#section-4.1 RFC 7235 Section 4.1>
262272--
263−-- #SINCE#
273+-- /Since 0.0.0.0/
264274unauthorizedContainsWWWAuthenticate :: ResponsePredicate Text Bool
265275unauthorizedContainsWWWAuthenticate
266276 = ResponsePredicate "unauthorizedContainsWWWAuthenticate" (\resp ->
@@ -276,6 +286,9 @@ unauthorizedContainsWWWAuthenticate
276286--
277287-- Still, this is all kind of ugly.
278288
289+-- | A predicate that depends only on the response.
290+--
291+-- /Since 0.0.0.0/
279292data ResponsePredicate n r = ResponsePredicate
280293 { respPredName :: n
281294 , respPred :: Response LBS.ByteString -> r
@@ -292,6 +305,9 @@ instance (Monoid n, Monoid r) => Monoid (ResponsePredicate n r) where
292305 , respPred = respPred a <> respPred b
293306 }
294307
308+-- | A predicate that depends on both the request and the response.
309+--
310+-- /Since 0.0.0.0/
295311data RequestPredicate n r = RequestPredicate
296312 { reqPredName :: n
297313 , reqResps :: Request -> Manager -> IO (r, [Response LBS.ByteString])
@@ -309,6 +325,7 @@ instance (Monoid n, Monoid r) => Monoid (RequestPredicate n r) where
309325 , reqResps = \x m -> liftM2 (<>) (reqResps a x m) (reqResps b x m)
310326 }
311327
328+-- | A set of predicates. Construct one with 'mempty' and '<%>'.
312329data Predicates n r = Predicates
313330 { reqPreds :: RequestPredicate n r
314331 , respPreds :: ResponsePredicate n r
@@ -339,7 +356,7 @@ instance JoinPreds (ResponsePredicate Text Bool) where
339356--
340357-- > not500 <%> onlyJsonObjects <%> empty
341358--
342−-- #SINCE#
359+-- /Since 0.0.0.0/
343360(<%>) :: JoinPreds a => a -> Predicates [Text] [Text] -> Predicates [Text] [Text]
344361(<%>) = joinPreds
345362infixr 6 <%>
src/Servant/QuickCheck/Internal/QuickCheck.hs+4−4
@@ -25,7 +25,7 @@ import Servant.QuickCheck.Internal.Equality
2525-- | Start a servant application on an open port, run the provided function,
2626-- then stop the application.
2727--
28−-- #SINCE#
28+-- /Since 0.0.0.0/
2929withServantServer :: HasServer a '[] => Proxy a -> IO (Server a)
3030 -> (BaseUrl -> IO r) -> IO r
3131withServantServer api = withServantServerAndContext api EmptyContext
@@ -33,7 +33,7 @@ withServantServer api = withServantServerAndContext api EmptyContext
3333-- | Like 'withServantServer', but allows passing in a 'Context' to the
3434-- application.
3535--
36−-- #SINCE#
36+-- /Since 0.0.0.0/
3737withServantServerAndContext :: HasServer a ctx
3838 => Proxy a -> Context ctx -> IO (Server a) -> (BaseUrl -> IO r) -> IO r
3939withServantServerAndContext api ctx server t
@@ -52,7 +52,7 @@ withServantServerAndContext api ctx server t
5252-- Evidently, if the behaviour of the server is expected to be
5353-- non-deterministic, this function may produce spurious failures
5454--
55−-- #SINCE#
55+-- /Since 0.0.0.0/
5656serversEqual :: HasGenRequest a =>
5757 Proxy a -> BaseUrl -> BaseUrl -> Args -> ResponseEquality LBS.ByteString -> Expectation
5858serversEqual api burl1 burl2 args req = do
@@ -86,7 +86,7 @@ serversEqual api burl1 burl2 args req = do
8686-- > <%> notAllowedContainsAllowHeader
8787-- > <%> mempty)
8888--
89−-- #SINCE#
89+-- /Since 0.0.0.0/
9090serverSatisfies :: (HasGenRequest a) =>
9191 Proxy a -> BaseUrl -> Args -> Predicates [Text] [Text] -> Expectation
9292serverSatisfies api burl args preds = do