on master help sign in
WAI 0.4
commitbd7964f43e3f188a0d8a45e7c7dc9476e0829172 authorMichael Snoyman <michael@snoyman.com> dateThu 10 Mar 2011, 10:53 (16 years ago) parent99bca19
2 files changed+18−15
Network/Wai/Test.hs+12−11 wai-test.cabal+6−4
Network/Wai/Test.hs+12−11
@@ -18,18 +18,19 @@ module Network.Wai.Test
1818import Network.Wai
1919import qualified Test.HUnit.Base as H
2020import Control.Monad.IO.Class (liftIO)
21−import Control.Monad.Trans.Class (lift)
22−import Control.Monad.Trans.State (StateT, evalStateT, get, put)
21+import Control.Monad.Trans.State (StateT, evalStateT)
2322import Control.Monad.Trans.Reader (ReaderT, runReaderT, ask)
2423import Data.Map (Map)
2524import qualified Data.Map as Map
2625import Data.ByteString (ByteString)
27−import qualified Data.ByteString as S
2826import qualified Data.ByteString.Char8 as S8
29−import Data.Enumerator (joinI, consume, ($$), run_, enumList)
27+import Data.Enumerator (joinI, ($$), run_, enumList)
28+import Data.Enumerator.List (consume)
3029import Blaze.ByteString.Builder.Enumerator (builderToByteString)
3130import qualified Data.ByteString.Lazy as L
3231import qualified Data.ByteString.Lazy.Char8 as L8
32+import qualified Network.HTTP.Types as H
33+import qualified Data.Ascii as A
3334
3435type Session = ReaderT Application (StateT ClientState IO)
3536
@@ -48,8 +49,8 @@ data SRequest = SRequest
4849 , simpleRequestBody :: L.ByteString
4950 }
5051data SResponse = SResponse
51− { simpleStatus :: Status
52− , simpleHeaders :: [(CIByteString, ByteString)]
52+ { simpleStatus :: H.Status
53+ , simpleHeaders :: H.ResponseHeaders
5354 , simpleBody :: L.ByteString
5455 }
5556 deriving (Show, Eq)
@@ -78,7 +79,7 @@ assertBool s b = liftIO $ H.assertBool s b
7879assertString :: String -> Session ()
7980assertString s = liftIO $ H.assertString s
8081
81−assertContentType :: ByteString -> SResponse -> Session ()
82+assertContentType :: A.Ascii -> SResponse -> Session ()
8283assertContentType ct SResponse{simpleHeaders = h} =
8384 case lookup "content-type" h of
8485 Nothing -> assertString $ concat
@@ -93,7 +94,7 @@ assertContentType ct SResponse{simpleHeaders = h} =
9394 , show ct'
9495 ]) (go ct == go ct')
9596 where
96− go = S8.takeWhile (/= ';')
97+ go = A.unsafeFromByteString . S8.takeWhile (/= ';') . A.toByteString
9798
9899assertStatus :: Int -> SResponse -> Session ()
99100assertStatus i SResponse{simpleStatus = s} = assertBool (concat
@@ -103,7 +104,7 @@ assertStatus i SResponse{simpleStatus = s} = assertBool (concat
103104 , show sc
104105 ]) $ i == sc
105106 where
106− sc = statusCode s
107+ sc = H.statusCode s
107108
108109assertBody :: L.ByteString -> SResponse -> Session ()
109110assertBody lbs SResponse{simpleBody = lbs'} = assertBool (concat
@@ -113,7 +114,7 @@ assertBody lbs SResponse{simpleBody = lbs'} = assertBool (concat
113114 , show $ L8.unpack lbs'
114115 ]) $ lbs == lbs'
115116
116−assertHeader :: CIByteString -> S.ByteString -> SResponse -> Session ()
117+assertHeader :: A.CIAscii -> A.Ascii -> SResponse -> Session ()
117118assertHeader header value SResponse{simpleHeaders = h} =
118119 case lookup header h of
119120 Nothing -> assertString $ concat
@@ -132,7 +133,7 @@ assertHeader header value SResponse{simpleHeaders = h} =
132133 , show value'
133134 ]) (value == value')
134135
135−assertNoHeader :: CIByteString -> SResponse -> Session ()
136+assertNoHeader :: A.CIAscii -> SResponse -> Session ()
136137assertNoHeader header SResponse{simpleHeaders = h} =
137138 case lookup header h of
138139 Nothing -> return ()
wai-test.cabal+6−4
@@ -1,5 +1,5 @@
11name: wai-test
2−version: 0.0.0
2+version: 0.1.0
33license: BSD3
44license-file: LICENSE
55author: Michael Snoyman <michael@snoyman.com>
@@ -13,15 +13,17 @@ homepage: http://github.com/snoyberg/wai-test/
1313
1414library
1515 build-depends: base >= 4 && < 5
16− , wai >= 0.3 && < 0.4
16+ , wai >= 0.4 && < 0.5
1717 , bytestring >= 0.9.1.4 && < 0.10
1818 , blaze-builder >= 0.2.1 && < 0.3
1919 , transformers >= 0.2 && < 0.3
2020 , containers >= 0.2 && < 0.5
21− , enumerator >= 0.4 && < 0.5
22− , cookie >= 0.0 && < 0.1
21+ , enumerator >= 0.4.7 && < 0.5
22+ , cookie >= 0.1 && < 0.2
2323 , blaze-builder-enumerator >= 0.2 && < 0.3
2424 , HUnit >= 1.2 && < 1.3
25+ , http-types >= 0.5 && < 0.6
26+ , ascii >= 0.0.2 && < 0.1
2527 exposed-modules: Network.Wai.Test
2628 ghc-options: -Wall
2729