on master help sign in
wai-extra: Rely on OverloadedStrings instead of using pack explicitly
commite048a5f6690dc1a46e7c1446d3d67aaa4c277aec authorSimon Hengel <sol@typeful.net> dateSat 1 Nov 2014, 21:58 (12 years ago) parent836c118
1 file changed+44−51
wai-extra/test/WaiExtraSpec.hs+44−51
wai-extra/test/WaiExtraSpec.hs+44−51
@@ -11,12 +11,10 @@ import Network.Wai.Parse
1111import Network.Wai.UrlMap
1212import qualified Data.ByteString as S
1313import qualified Data.ByteString.Char8 as S8
14−import qualified Data.ByteString.Lazy.Char8 as L8
1514import qualified Data.ByteString.Lazy as L
1615import qualified Data.Text.Lazy as T
1716import qualified Data.Text as TS
1817import qualified Data.Text.Encoding as TE
19−import Control.Arrow
2018import Control.Applicative
2119import Control.Monad.Trans.Resource (withInternalState, runResourceT)
2220
@@ -82,8 +80,7 @@ spec = do
8280
8381caseParseQueryString :: Assertion
8482caseParseQueryString = do
85− let go l r =
86− map (S8.pack *** S8.pack) l @=? parseSimpleQuery (S8.pack r)
83+ let go l r = l @=? parseSimpleQuery r
8784
8885 go [] ""
8986 go [("foo", "")] "foo"
@@ -98,9 +95,7 @@ caseParseQueryString = do
9895
9996caseParseQueryStringQM :: Assertion
10097caseParseQueryStringQM = do
101− let go l r =
102− map (S8.pack *** S8.pack) l
103− @=? parseSimpleQuery (S8.pack $ '?' : r)
98+ let go l r = l @=? parseSimpleQuery ("?" <> r)
10499
105100 go [] ""
106101 go [("foo", "")] "foo"
@@ -137,29 +132,29 @@ caseParseRequestBody :: Assertion
137132caseParseRequestBody =
138133 t
139134 where
140− content2 = S8.pack $
141− "--AaB03x\n" ++
142− "Content-Disposition: form-data; name=\"document\"; filename=\"b.txt\"\n" ++
143− "Content-Type: text/plain; charset=iso-8859-1\n\n" ++
144− "This is a file.\n" ++
145− "It has two lines.\n" ++
146− "--AaB03x\n" ++
147− "Content-Disposition: form-data; name=\"title\"\n" ++
148− "Content-Type: text/plain; charset=iso-8859-1\n\n" ++
149− "A File\n" ++
150− "--AaB03x\n" ++
151− "Content-Disposition: form-data; name=\"summary\"\n" ++
152− "Content-Type: text/plain; charset=iso-8859-1\n\n" ++
153− "This is my file\n" ++
154− "file test\n" ++
135+ content2 =
136+ "--AaB03x\n" <>
137+ "Content-Disposition: form-data; name=\"document\"; filename=\"b.txt\"\n" <>
138+ "Content-Type: text/plain; charset=iso-8859-1\n\n" <>
139+ "This is a file.\n" <>
140+ "It has two lines.\n" <>
141+ "--AaB03x\n" <>
142+ "Content-Disposition: form-data; name=\"title\"\n" <>
143+ "Content-Type: text/plain; charset=iso-8859-1\n\n" <>
144+ "A File\n" <>
145+ "--AaB03x\n" <>
146+ "Content-Disposition: form-data; name=\"summary\"\n" <>
147+ "Content-Type: text/plain; charset=iso-8859-1\n\n" <>
148+ "This is my file\n" <>
149+ "file test\n" <>
155150 "--AaB03x--"
156− content3 = S8.pack "------WebKitFormBoundaryB1pWXPZ6lNr8RiLh\r\nContent-Disposition: form-data; name=\"yaml\"; filename=\"README\"\r\nContent-Type: application/octet-stream\r\n\r\nPhoto blog using Hack.\n\r\n------WebKitFormBoundaryB1pWXPZ6lNr8RiLh--\r\n"
151+ content3 = "------WebKitFormBoundaryB1pWXPZ6lNr8RiLh\r\nContent-Disposition: form-data; name=\"yaml\"; filename=\"README\"\r\nContent-Type: application/octet-stream\r\n\r\nPhoto blog using Hack.\n\r\n------WebKitFormBoundaryB1pWXPZ6lNr8RiLh--\r\n"
157152 t = do
158153 let content1 = "foo=bar&baz=bin"
159154 let ctype1 = "application/x-www-form-urlencoded"
160155 result1 <- parseRequestBody' lbsBackEnd $ toRequest ctype1 content1
161156 assertEqual "parsing post x-www-form-urlencoded"
162− (map (S8.pack *** S8.pack) [("foo", "bar"), ("baz", "bin")], [])
157+ ([("foo", "bar"), ("baz", "bin")], [])
163158 result1
164159
165160 let ctype2 = "multipart/form-data; boundary=AaB03x"
@@ -168,11 +163,10 @@ caseParseRequestBody =
168163 [ ("title", "A File")
169164 , ("summary", "This is my file\nfile test")
170165 ]
171− let textPlain = S8.pack $ "text/plain; charset=iso-8859-1"
166+ let textPlain = "text/plain; charset=iso-8859-1"
172167 let expectedfile2 =
173− [(S8.pack "document", FileInfo (S8.pack "b.txt") textPlain $ L8.pack
174− "This is a file.\nIt has two lines.")]
175− let expected2 = (map (S8.pack *** S8.pack) expectedsmap2, expectedfile2)
168+ [("document", FileInfo "b.txt" textPlain "This is a file.\nIt has two lines.")]
169+ let expected2 = (expectedsmap2, expectedfile2)
176170 assertEqual "parsing post multipart/form-data"
177171 expected2
178172 result2
@@ -180,8 +174,7 @@ caseParseRequestBody =
180174 let ctype3 = "multipart/form-data; boundary=----WebKitFormBoundaryB1pWXPZ6lNr8RiLh"
181175 result3 <- parseRequestBody' lbsBackEnd $ toRequest ctype3 content3
182176 let expectedsmap3 = []
183− let expectedfile3 = [(S8.pack "yaml", FileInfo (S8.pack "README") (S8.pack "application/octet-stream") $
184− L8.pack "Photo blog using Hack.\n")]
177+ let expectedfile3 = [("yaml", FileInfo "README" "application/octet-stream" "Photo blog using Hack.\n")]
185178 let expected3 = (expectedsmap3, expectedfile3)
186179 assertEqual "parsing actual post multipart/form-data"
187180 expected3
@@ -202,11 +195,11 @@ caseMultipartPlus = do
202195 result <- parseRequestBody' lbsBackEnd $ toRequest ctype content
203196 result @?= ([("email", "has+plus")], [])
204197 where
205− content = S8.pack $
206− "--AaB03x\n" ++
207− "Content-Disposition: form-data; name=\"email\"\n" ++
208− "Content-Type: text/plain; charset=iso-8859-1\n\n" ++
209− "has+plus\n" ++
198+ content =
199+ "--AaB03x\n" <>
200+ "Content-Disposition: form-data; name=\"email\"\n" <>
201+ "Content-Type: text/plain; charset=iso-8859-1\n\n" <>
202+ "has+plus\n" <>
210203 "--AaB03x--"
211204 ctype = "multipart/form-data; boundary=AaB03x"
212205
@@ -215,11 +208,11 @@ caseMultipartAttrs = do
215208 result <- parseRequestBody' lbsBackEnd $ toRequest ctype content
216209 result @?= ([("email", "has+plus")], [])
217210 where
218− content = S8.pack $
219− "--AaB03x\n" ++
220− "Content-Disposition: form-data; name=\"email\"\n" ++
221− "Content-Type: text/plain; charset=iso-8859-1\n\n" ++
222− "has+plus\n" ++
211+ content =
212+ "--AaB03x\n" <>
213+ "Content-Disposition: form-data; name=\"email\"\n" <>
214+ "Content-Type: text/plain; charset=iso-8859-1\n\n" <>
215+ "has+plus\n" <>
223216 "--AaB03x--"
224217 ctype = "multipart/form-data; charset=UTF-8; boundary=AaB03x"
225218
@@ -229,7 +222,7 @@ caseUrlEncPlus = do
229222 parseRequestBody' (tempFileBackEnd state) $ toRequest ctype content
230223 result @?= ([("email", "has+plus")], [])
231224 where
232− content = S8.pack $ "email=has%2Bplus"
225+ content = "email=has%2Bplus"
233226 ctype = "application/x-www-form-urlencoded"
234227
235228toRequest :: S8.ByteString -> S8.ByteString -> SRequest
@@ -249,20 +242,20 @@ toRequest' ctype content = SRequest defaultRequest
249242{-
250243caseFindBound :: Assertion
251244caseFindBound = do
252− findBound (S8.pack "def") (S8.pack "abcdefghi") @?=
253− FoundBound (S8.pack "abc") (S8.pack "ghi")
254− findBound (S8.pack "def") (S8.pack "ABC") @?= NoBound
255− findBound (S8.pack "def") (S8.pack "abcd") @?= PartialBound
256− findBound (S8.pack "def") (S8.pack "abcdE") @?= NoBound
257− findBound (S8.pack "def") (S8.pack "abcdEdef") @?=
258− FoundBound (S8.pack "abcdE") (S8.pack "")
245+ findBound "def" "abcdefghi" @?=
246+ FoundBound "abc" "ghi"
247+ findBound "def" "ABC" @?= NoBound
248+ findBound "def" "abcd" @?= PartialBound
249+ findBound "def" "abcdE" @?= NoBound
250+ findBound "def" "abcdEdef" @?=
251+ FoundBound "abcdE" ""
259252
260253caseSinkTillBound :: Assertion
261254caseSinkTillBound = do
262255 let iter () _ = return ()
263− let src = S8.pack "this is some text"
264− bound1 = S8.pack "some"
265− bound2 = S8.pack "some!"
256+ let src = "this is some text"
257+ bound1 = "some"
258+ bound2 = "some!"
266259 let enum = enumList 1 [src]
267260 let helper _ _ = return ()
268261 (_, res1) <- run_ $ enum $$ sinkTillBound bound1 helper ()