on master help sign in
WAI 0.4
bd7964fMichael Snoyman
Network/Wai/Test.hs+12−11
@@ -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
33
34
34type Session = ReaderT Application (StateT ClientState IO)
35type Session = ReaderT Application (StateT ClientState IO)
35
36
@@ -48,8 +49,8 @@ data SRequest = SRequest
48 , simpleRequestBody :: L.ByteString
49 , simpleRequestBody :: L.ByteString
49 }
50 }
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
54 }
55 }
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
80
81
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')
95 where
96 where
96− go = S8.takeWhile (/= ';')
97+ go = A.unsafeFromByteString . S8.takeWhile (/= ';') . A.toByteString
97
98
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
105 where
106 where
106− sc = statusCode s
107+ sc = H.statusCode s
107
108
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'
115
116
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')
134
135
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 ()
wai-test.cabal+6−4
@@ -1,5 +1,5 @@
1name: wai-test
1name: wai-test
2−version: 0.0.0
2+version: 0.1.0
3license: BSD3
3license: BSD3
4license-file: LICENSE
4license-file: LICENSE
5author: Michael Snoyman <michael@snoyman.com>
5author: Michael Snoyman <michael@snoyman.com>
@@ -13,15 +13,17 @@ homepage: http://github.com/snoyberg/wai-test/
13
13
14library
14library
15 build-depends: base >= 4 && < 5
15 build-depends: base >= 4 && < 5
16− , wai >= 0.3 && < 0.4
16+ , wai >= 0.4 && < 0.5
17 , bytestring >= 0.9.1.4 && < 0.10
17 , bytestring >= 0.9.1.4 && < 0.10
18 , blaze-builder >= 0.2.1 && < 0.3
18 , blaze-builder >= 0.2.1 && < 0.3
19 , transformers >= 0.2 && < 0.3
19 , transformers >= 0.2 && < 0.3
20 , containers >= 0.2 && < 0.5
20 , containers >= 0.2 && < 0.5
21− , enumerator >= 0.4 && < 0.5
21+ , enumerator >= 0.4.7 && < 0.5
22− , cookie >= 0.0 && < 0.1
22+ , cookie >= 0.1 && < 0.2
23 , blaze-builder-enumerator >= 0.2 && < 0.3
23 , blaze-builder-enumerator >= 0.2 && < 0.3
24 , HUnit >= 1.2 && < 1.3
24 , HUnit >= 1.2 && < 1.3
25+ , http-types >= 0.5 && < 0.6
26+ , ascii >= 0.0.2 && < 0.1
25 exposed-modules: Network.Wai.Test
27 exposed-modules: Network.Wai.Test
26 ghc-options: -Wall
28 ghc-options: -Wall
27
29