servant-quickcheck 0.0.2.3 → 0.0.2.4
raw patch · 4 files changed
+35/−4 lines, 4 files
Files
- CHANGELOG.yaml +8/−0
- servant-quickcheck.cabal +1/−1
- src/Servant/QuickCheck/Internal/HasGenRequest.hs +6/−1
- test/Servant/QuickCheck/InternalSpec.hs +20/−2
CHANGELOG.yaml view
@@ -2,6 +2,14 @@ releases: + - version: "0.0.2.4"+ changes:++ - description: Don't append slashes to paths+ issue: 22+ authors: declension+ date: 2017-03-11+ - version: "0.0.2.3" changes:
servant-quickcheck.cabal view
@@ -1,5 +1,5 @@ name: servant-quickcheck-version: 0.0.2.3+version: 0.0.2.4 synopsis: QuickCheck entire APIs description: This packages provides QuickCheck properties that are tested across an entire
src/Servant/QuickCheck/Internal/HasGenRequest.hs view
@@ -17,6 +17,7 @@ import Test.QuickCheck (Arbitrary (..), Gen, elements, oneof) import qualified Data.ByteString as BS+import qualified Data.ByteString.Internal as BS (c2w) class HasGenRequest a where@@ -31,7 +32,11 @@ instance (KnownSymbol path, HasGenRequest b) => HasGenRequest (path :> b) where genRequest _ = do old' <- old- return $ \burl -> let r = old' burl in r { path = new <> path r }+ return $ \burl -> let r = old' burl+ oldPath = path r+ oldPath' = BS.dropWhile (== BS.c2w '/') oldPath+ paths = filter (not . BS.null) [new, oldPath']+ in r { path = "/" <> BS.intercalate "/" paths } where old = genRequest (Proxy :: Proxy b) new = cs $ symbolVal (Proxy :: Proxy path)
test/Servant/QuickCheck/InternalSpec.hs view
@@ -13,7 +13,7 @@ defaultParams, evaluateExample) import Test.QuickCheck.Gen (unGen) import Test.QuickCheck.Random (mkQCGen)-import Network.HTTP.Client (queryString)+import Network.HTTP.Client (queryString, path) #if MIN_VERSION_servant(0,8,0) import Servant.API.Internal.Test.ComprehensiveAPI (comprehensiveAPIWithoutRaw)@@ -34,6 +34,7 @@ notLongerThanSpec queryParamsSpec queryFlagsSpec+ deepPathSpec serversEqualSpec :: Spec serversEqualSpec = describe "serversEqual" $ do@@ -52,7 +53,7 @@ evalExample $ serversEqual api2 burl1 burl2 args bodyEquality show err `shouldContain` "Body: 1" show err `shouldContain` "Body: 2"- show err `shouldContain` "Path: failplz/"+ show err `shouldContain` "Path: /failplz" serverSatisfiesSpec :: Spec serverSatisfiesSpec = describe "serverSatisfies" $ do@@ -113,6 +114,17 @@ let _g = genRequest comprehensiveAPIWithoutRaw True `shouldBe` True -- This is a type-level check +deepPathSpec :: Spec+deepPathSpec = describe "Path components" $ do++ it "are separated by slashes, without a trailing slash" $ do+ let rng = mkQCGen 0+ burl = BaseUrl Http "localhost" 80 ""+ gen = genRequest deepAPI+ req = (unGen gen rng 0) burl+ path req `shouldBe` ("/one/two/three")++ queryParamsSpec :: Spec queryParamsSpec = describe "QueryParams" $ do @@ -169,6 +181,12 @@ api2 :: Proxy API2 api2 = Proxy++type DeepAPI = "one" :> "two" :> "three":> Get '[JSON] ()++deepAPI :: Proxy DeepAPI+deepAPI = Proxy+ server2 :: IO (Server API2) server2 = return $ return 1