git.iko.soy/servant-quickcheck
on master help sign in
QueryParams: fix ampersand, improve test

* Simplify test API to use `()` - no awkward values at all. * The test asserts on _entire_ of resulting path now... * ...and fix the ampersand placement, but preserving the order of params left to right. The code also reads a bit better this way...

commit6be669716544e279fc248c0bc5e4d1d4fb6a1563 authorNick B <nick@declension.net> dateTue 7 Mar 2017, 21:25 (10 years ago) parenta522427
2 files changed+5−5
src/Servant/QuickCheck/Internal/HasGenRequest.hs+2−1 test/Servant/QuickCheck/InternalSpec.hs+3−4
src/Servant/QuickCheck/Internal/HasGenRequest.hs+2−1
@@ -92,8 +92,9 @@ instance (KnownSymbol x, Arbitrary c, ToHttpApiData c, HasGenRequest b)
9292 new' <- new
9393 old' <- old
9494 return $ \burl -> let r = old' burl
95+ newExpr = param <> "=" <> cs (toQueryParam new')
9596 qs = queryString r in r {
96− queryString = (if BS.null qs then "" else "&") <> qs <> param <> "=" <> cs (toQueryParam new') }
97+ queryString = if BS.null qs then newExpr else newExpr <> "&" <> qs }
9798 where
9899 old = genRequest (Proxy :: Proxy b)
99100 param = cs $ symbolVal (Proxy :: Proxy x)
test/Servant/QuickCheck/InternalSpec.hs+3−4
@@ -4,7 +4,7 @@ module Servant.QuickCheck.InternalSpec (spec) where
44import Control.Concurrent.MVar (newMVar, readMVar, swapMVar)
55import Control.Monad.IO.Class (liftIO)
66import qualified Data.ByteString as BS
7−import qualified Data.ByteString.Char8 as C
7+import qualified Data.ByteString.Char8 as C
88import Prelude.Compat
99import Servant
1010import Test.Hspec (Spec, context, describe, it, shouldBe,
@@ -121,8 +121,7 @@ queryParamsSpec = describe "QueryParams" $ do
121121 gen = genRequest paramsAPI
122122 req = (unGen gen rng 0) burl
123123 qs = C.unpack $ queryString req
124− qs `shouldContain` ("one=")
125− qs `shouldContain` ("&two=")
124+ qs `shouldBe` "one=&two="
126125
127126------------------------------------------------------------------------------
128127-- APIs
@@ -135,7 +134,7 @@ type API = ReqBody '[JSON] String :> Post '[JSON] String
135134api :: Proxy API
136135api = Proxy
137136
138−type ParamsAPI = QueryParam "one" String :> QueryParam "two" String :> Get '[JSON] String
137+type ParamsAPI = QueryParam "one" String :> QueryParam "two" String :> Get '[JSON] ()
139138
140139paramsAPI :: Proxy ParamsAPI
141140paramsAPI = Proxy