@@ -18,18 +18,19 @@ module Network.Wai.Test
18import Network.Wai
18import Network.Wai
19import qualified Test.HUnit.Base as H
19import qualified Test.HUnit.Base as H
20import Control.Monad.IO.Class (liftIO)
20import Control.Monad.IO.Class (liftIO)
21−import Control.Monad.Trans.Class (lift)
21+import Control.Monad.Trans.State (StateT, evalStateT)
22−import Control.Monad.Trans.State (StateT, evalStateT, get, put)
23import Control.Monad.Trans.Reader (ReaderT, runReaderT, ask)
22import Control.Monad.Trans.Reader (ReaderT, runReaderT, ask)
24import Data.Map (Map)
23import Data.Map (Map)
25import qualified Data.Map as Map
24import qualified Data.Map as Map
26import Data.ByteString (ByteString)
25import Data.ByteString (ByteString)
27−import qualified Data.ByteString as S
28import qualified Data.ByteString.Char8 as S8
26import 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)
30import Blaze.ByteString.Builder.Enumerator (builderToByteString)
29import Blaze.ByteString.Builder.Enumerator (builderToByteString)
31import qualified Data.ByteString.Lazy as L
30import qualified Data.ByteString.Lazy as L
32import qualified Data.ByteString.Lazy.Char8 as L8
31import qualified Data.ByteString.Lazy.Char8 as L8
32+import qualified Network.HTTP.Types as H
33+import qualified Data.Ascii as A
34type Session = ReaderT Application (StateT ClientState IO)
35type Session = ReaderT Application (StateT ClientState IO)
@@ -48,8 +49,8 @@ data SRequest = SRequest
48 , simpleRequestBody :: L.ByteString
49 , simpleRequestBody :: L.ByteString
50data SResponse = SResponse
51data SResponse = SResponse
51− { simpleStatus :: Status
52+ { simpleStatus :: H.Status
52− , simpleHeaders :: [(CIByteString, ByteString)]
53+ , simpleHeaders :: H.ResponseHeaders
53 , simpleBody :: L.ByteString
54 , simpleBody :: L.ByteString
55 deriving (Show, Eq)
56 deriving (Show, Eq)
@@ -78,7 +79,7 @@ assertBool s b = liftIO $ H.assertBool s b
78assertString :: String -> Session ()
79assertString :: String -> Session ()
79assertString s = liftIO $ H.assertString s
80assertString s = liftIO $ H.assertString s
81−assertContentType :: ByteString -> SResponse -> Session ()
82+assertContentType :: A.Ascii -> SResponse -> Session ()
82assertContentType ct SResponse{simpleHeaders = h} =
83assertContentType ct SResponse{simpleHeaders = h} =
83 case lookup "content-type" h of
84 case lookup "content-type" h of
84 Nothing -> assertString $ concat
85 Nothing -> assertString $ concat
@@ -93,7 +94,7 @@ assertContentType ct SResponse{simpleHeaders = h} =
93 , show ct'
94 , show ct'
94 ]) (go ct == go ct')
95 ]) (go ct == go ct')
96− go = S8.takeWhile (/= ';')
97+ go = A.unsafeFromByteString . S8.takeWhile (/= ';') . A.toByteString
98assertStatus :: Int -> SResponse -> Session ()
99assertStatus :: Int -> SResponse -> Session ()
99assertStatus i SResponse{simpleStatus = s} = assertBool (concat
100assertStatus i SResponse{simpleStatus = s} = assertBool (concat
@@ -103,7 +104,7 @@ assertStatus i SResponse{simpleStatus = s} = assertBool (concat
103 , show sc
104 , show sc
104 ]) $ i == sc
105 ]) $ i == sc
106− sc = statusCode s
107+ sc = H.statusCode s
108assertBody :: L.ByteString -> SResponse -> Session ()
109assertBody :: L.ByteString -> SResponse -> Session ()
109assertBody lbs SResponse{simpleBody = lbs'} = assertBool (concat
110assertBody lbs SResponse{simpleBody = lbs'} = assertBool (concat
@@ -113,7 +114,7 @@ assertBody lbs SResponse{simpleBody = lbs'} = assertBool (concat
113 , show $ L8.unpack lbs'
114 , show $ L8.unpack lbs'
114 ]) $ lbs == lbs'
115 ]) $ lbs == lbs'
116−assertHeader :: CIByteString -> S.ByteString -> SResponse -> Session ()
117+assertHeader :: A.CIAscii -> A.Ascii -> SResponse -> Session ()
117assertHeader header value SResponse{simpleHeaders = h} =
118assertHeader header value SResponse{simpleHeaders = h} =
118 case lookup header h of
119 case lookup header h of
119 Nothing -> assertString $ concat
120 Nothing -> assertString $ concat
@@ -132,7 +133,7 @@ assertHeader header value SResponse{simpleHeaders = h} =
132 , show value'
133 , show value'
133 ]) (value == value')
134 ]) (value == value')
135−assertNoHeader :: CIByteString -> SResponse -> Session ()
136+assertNoHeader :: A.CIAscii -> SResponse -> Session ()
136assertNoHeader header SResponse{simpleHeaders = h} =
137assertNoHeader header SResponse{simpleHeaders = h} =
137 case lookup header h of
138 case lookup header h of
138 Nothing -> return ()
139 Nothing -> return ()