on wai-extra/3.0.8.0 help sign in
typeable/wai/warp/test/ReadIntSpec.hs
26 lines 981 B history raw
1module ReadIntSpec (main, spec) where
3import Data.ByteString (ByteString)
4import Test.Hspec
5import Network.Wai.Handler.Warp.ReadInt
6import qualified Data.ByteString.Char8 as B
7import qualified Test.QuickCheck as QC
9main :: IO ()
10main = hspec spec
12spec :: Spec
13spec = describe "readInt64" $ do
14 it "converts ByteString to Int" $ QC.property (prop_read_show_idempotent readInt64)
16-- A QuickCheck property. Test that for a number >= 0, converting it to
17-- a string using show and then reading the value back with the function
18-- under test returns the original value.
19-- The functions under test only work on Natural numbers (the Conent-Length
20-- field in a HTTP header is always >= 0) so we check the absolute value of
21-- the value that QuickCheck generates for us.
22prop_read_show_idempotent :: (Integral a, Show a) => (ByteString -> a) -> a -> Bool
23prop_read_show_idempotent freader x = px == freader (toByteString px)
24 where
25 px = abs x
26 toByteString = B.pack . show