on master help sign in
Correct some doctest looking things to be doctests
commit953747b55ba6f6531ba5d761c285ae20ab3592b5 authorOleg Grenrus <oleg.grenrus@iki.fi> dateThu 8 Nov 2018, 17:12 (8 years ago) parent7bed805
1 file changed+43−31
servant-docs/src/Servant/Docs/Internal.hs+43−31
servant-docs/src/Servant/Docs/Internal.hs+43−31
@@ -76,14 +76,15 @@ import qualified Network.HTTP.Types as HTTP
7676-- or any 'Endpoint' value you want using the 'path' and 'method'
7777-- lenses to tweak.
7878--
79−-- @
80−-- λ> 'defEndpoint'
81−-- GET /
82−-- λ> 'defEndpoint' & 'path' '<>~' ["foo"]
83−-- GET /foo
84−-- λ> 'defEndpoint' & 'path' '<>~' ["foo"] & 'method' '.~' 'HTTP.methodPost'
85−-- POST /foo
86−-- @
79+-- >>> defEndpoint
80+-- "GET" /
81+--
82+-- >>> defEndpoint & path <>~ ["foo"]
83+-- "GET" /foo
84+--
85+-- >>> defEndpoint & path <>~ ["foo"] & method .~ HTTP.methodPost
86+-- "POST" /foo
87+--
8788data Endpoint = Endpoint
8889 { _path :: [String] -- type collected
8990 , _method :: HTTP.Method -- type collected
@@ -104,14 +105,15 @@ showPath ps = concatMap ('/' :) ps
104105--
105106-- Here's how you can modify it:
106107--
107−-- @
108−-- λ> 'defEndpoint'
109−-- GET /
110−-- λ> 'defEndpoint' & 'path' '<>~' ["foo"]
111−-- GET /foo
112−-- λ> 'defEndpoint' & 'path' '<>~' ["foo"] & 'method' '.~' 'HTTP.methodPost'
113−-- POST /foo
114−-- @
108+-- >>> defEndpoint
109+-- "GET" /
110+--
111+-- >>> defEndpoint & path <>~ ["foo"]
112+-- "GET" /foo
113+--
114+-- >>> defEndpoint & path <>~ ["foo"] & method .~ HTTP.methodPost
115+-- "POST" /foo
116+--
115117defEndpoint :: Endpoint
116118defEndpoint = Endpoint [] HTTP.methodGet
117119
@@ -222,12 +224,14 @@ data ParamKind = Normal | List | Flag
222224-- want to write a 'ToSample' instance for the type that'll be represented
223225-- as encoded data in the response.
224226--
225−-- Can be tweaked with three lenses.
227+-- Can be tweaked with four lenses.
228+--
229+-- >>> defResponse
230+-- Response {_respStatus = 200, _respTypes = [], _respBody = [], _respHeaders = []}
231+--
232+-- >>> defResponse & respStatus .~ 204 & respBody .~ [("If everything goes well", "application/json", "{ \"status\": \"ok\" }")]
233+-- Response {_respStatus = 204, _respTypes = [], _respBody = [("If everything goes well",application/json,"{ \"status\": \"ok\" }")], _respHeaders = []}
226234--
227−-- > λ> defResponse
228−-- > Response {_respStatus = 200, _respTypes = [], _respBody = []}
229−-- > λ> defResponse & respStatus .~ 204 & respBody .~ [("If everything goes well", "{ \"status\": \"ok\" }")]
230−-- > Response {_respStatus = 204, _respTypes = [], _respBody = [("If everything goes well", "{ \"status\": \"ok\" }")]}
231235data Response = Response
232236 { _respStatus :: Int
233237 , _respTypes :: [M.MediaType]
@@ -237,12 +241,14 @@ data Response = Response
237241
238242-- | Default response: status code 200, no response body.
239243--
240−-- Can be tweaked with two lenses.
244+-- Can be tweaked with four lenses.
245+--
246+-- >>> defResponse
247+-- Response {_respStatus = 200, _respTypes = [], _respBody = [], _respHeaders = []}
248+--
249+-- >>> defResponse & respStatus .~ 204
250+-- Response {_respStatus = 204, _respTypes = [], _respBody = [], _respHeaders = []}
241251--
242−-- > λ> defResponse
243−-- > Response {_respStatus = 200, _respBody = Nothing}
244−-- > λ> defResponse & respStatus .~ 204 & respBody .~ Just "[]"
245−-- > Response {_respStatus = 204, _respBody = Just "[]"}
246252defResponse :: Response
247253defResponse = Response
248254 { _respStatus = 200
@@ -288,10 +294,12 @@ Action a c h p n m ts body resp `combineAction` Action a' c' h' p' n' m' _ _ _ =
288294--
289295-- Tweakable with lenses.
290296--
291−-- > λ> defAction
292−-- > Action {_captures = [], _headers = [], _params = [], _mxParams = [], _rqbody = Nothing, _response = Response {_respStatus = 200, _respBody = Nothing}}
293−-- > λ> defAction & response.respStatus .~ 201
294−-- > Action {_captures = [], _headers = [], _params = [], _mxParams = [], _rqbody = Nothing, _response = Response {_respStatus = 201, _respBody = Nothing}}
297+-- >>> defAction
298+-- Action {_authInfo = [], _captures = [], _headers = [], _params = [], _notes = [], _mxParams = [], _rqtypes = [], _rqbody = [], _response = Response {_respStatus = 200, _respTypes = [], _respBody = [], _respHeaders = []}}
299+--
300+-- >>> defAction & response.respStatus .~ 201
301+-- Action {_authInfo = [], _captures = [], _headers = [], _params = [], _notes = [], _mxParams = [], _rqtypes = [], _rqbody = [], _response = Response {_respStatus = 201, _respTypes = [], _respBody = [], _respHeaders = []}}
302+--
295303defAction :: Action
296304defAction =
297305 Action []
@@ -359,7 +367,8 @@ makeLenses ''RenderingOptions
359367-- | Generate the docs for a given API that implements 'HasDocs'. This is the
360368-- default way to create documentation.
361369--
362−-- prop> docs == docsWithOptions defaultDocOptions
370+-- > docs == docsWithOptions defaultDocOptions
371+--
363372docs :: HasDocs api => Proxy api -> API
364373docs p = docsWithOptions p defaultDocOptions
365374
@@ -1046,3 +1055,6 @@ instance ToSample a => ToSample (Product a)
10461055instance ToSample a => ToSample (First a)
10471056instance ToSample a => ToSample (Last a)
10481057instance ToSample a => ToSample (Dual a)
1058+
1059+-- $setup
1060+-- >>> :set -XOverloadedStrings