dormouse-client 0.1.0.0 → 0.1.0.1
raw patch · 3 files changed
+91/−5 lines, 3 filesdep ~text
Dependency ranges changed: text
Files
- dormouse-client.cabal +7/−5
- test/Dormouse/Client/Generators/Text.hs +21/−0
- test/Dormouse/Client/PayloadSpec.hs +63/−0
dormouse-client.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: ba447e997d78582de45b1d7a4371396f5daed044c73681fa6b1a1e5f06f57aa9+-- hash: 53a8941fce30957b33c0c2573f20f976e663b6a0d21e6feed28a68ff8b5d68e3 name: dormouse-client-version: 0.1.0.0+version: 0.1.0.1 synopsis: Simple, type-safe and testable HTTP client description: An HTTP client designed to be productive, easy to use, easy to test, flexible and safe! .@@ -76,7 +76,7 @@ , streamly >=0.7.2 && <0.8 , streamly-bytestring >=0.1.2 && <0.2 , template-haskell >=2.15.0 && <3.0.0- , text >=1.2.3 && <2.0.0+ , text >=1.2.4 && <2.0.0 default-language: Haskell2010 test-suite dormouse-client-test@@ -96,8 +96,10 @@ Dormouse.Client.Test.Class Dormouse.Client.Types Dormouse.Client.Generators.Json+ Dormouse.Client.Generators.Text Dormouse.Client.Generators.UriComponents Dormouse.Client.Headers.MediaTypeSpec+ Dormouse.Client.PayloadSpec Dormouse.Client.StatusSpec Dormouse.Client.UrlReqSpec Dormouse.ClientSpec@@ -106,7 +108,7 @@ src test default-extensions: OverloadedStrings MultiParamTypeClasses ScopedTypeVariables FlexibleContexts- ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall+ ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall -fdicts-strict build-depends: aeson >=1.4.2 && <2.0.0 , attoparsec >=0.13.2.4 && <0.14@@ -129,6 +131,6 @@ , streamly >=0.7.2 && <0.8 , streamly-bytestring >=0.1.2 && <0.2 , template-haskell >=2.15.0 && <3.0.0- , text >=1.2.3 && <2.0.0+ , text >=1.2.4 && <2.0.0 , vector >=0.12.0.3 && <0.13 default-language: Haskell2010
+ test/Dormouse/Client/Generators/Text.hs view
@@ -0,0 +1,21 @@+module Dormouse.Client.Generators.Text + ( genLatin1BS+ , genUtf8BS+ )+ where++import Hedgehog+import qualified Hedgehog.Gen as Gen+import Data.ByteString+import Data.Text.Encoding+import qualified Data.Text as T+import qualified Data.ByteString.Char8 as BS8++genLatin1BS :: Range Int -> Gen ByteString+genLatin1BS range = do+ t <- Gen.text range Gen.latin1 + pure . BS8.pack . T.unpack $ t++genUtf8BS :: Range Int -> Gen ByteString+genUtf8BS range = + Gen.utf8 range Gen.unicode
+ test/Dormouse/Client/PayloadSpec.hs view
@@ -0,0 +1,63 @@+module Dormouse.Client.PayloadSpec+ ( spec+ ) where++import Control.Monad.IO.Class+import qualified Data.Map as Map+import Data.Text.Encoding+import Dormouse.Client.Types+import Dormouse.Client.Generators.Text+import Dormouse.Client.Payload++import Streamly+import qualified Streamly.Prelude as S++import Data.Proxy++import Test.Hspec+import Test.Hspec.Hedgehog+import qualified Hedgehog.Range as Range+import qualified Streamly.External.ByteString as SEB++spec :: Spec+spec = before setup $ do+ describe "decodeText" $ do+ it "successfully decodes latin-1 text for iso-8859-1 charset" $ \sizeRanges -> do+ hedgehog $ do+ txt <- forAll . genLatin1BS $ sizeRanges+ let + resp = HttpResponse + { responseStatusCode = 200+ , responseHeaders = Map.fromList [("Content-Type", "text/plain; charset=iso-8859-1")]+ , responseBody = S.unfold SEB.read txt+ }+ expectedLatin1Text = decodeLatin1 txt+ resp' <- liftIO . deserialiseRequest html $ resp+ responseBody resp' === expectedLatin1Text+ it "successfully decodes utf8 text for utf8 charset" $ \sizeRanges -> do+ hedgehog $ do+ txt <- forAll . genUtf8BS $ sizeRanges+ let + resp = HttpResponse + { responseStatusCode = 200+ , responseHeaders = Map.fromList [("Content-Type", "text/plain; charset=utf8")]+ , responseBody = S.unfold SEB.read txt+ }+ expectedUtf8Text = decodeUtf8 txt+ resp' <- liftIO . deserialiseRequest html $ resp+ responseBody resp' === expectedUtf8Text+ it "successfully decodes utf8 text if no explicit charset applied" $ \sizeRanges -> do+ hedgehog $ do+ txt <- forAll . genUtf8BS $ sizeRanges+ let + resp = HttpResponse + { responseStatusCode = 200+ , responseHeaders = Map.empty+ , responseBody = S.unfold SEB.read txt+ }+ expectedUtf8Text = decodeUtf8 txt+ resp' <- liftIO . deserialiseRequest html $ resp+ responseBody resp' === expectedUtf8Text+ where+ setup = do+ return $ Range.exponential 0 100000