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