@@ -5,7 +5,7 @@ import Test.Framework (defaultMain, testGroup, Test)
5import Test.Framework.Providers.HUnit
5import Test.Framework.Providers.HUnit
6import Test.HUnit hiding (Test)
6import Test.HUnit hiding (Test)
8−import Network.Wai.Handler.Warp (takeLineMax, takeHeaders, InvalidRequest (..))
8+import Network.Wai.Handler.Warp (takeHeaders, InvalidRequest (..))
9import Data.Enumerator (run_, ($$), enumList, run)
9import Data.Enumerator (run_, ($$), enumList, run)
10import Control.Exception (fromException)
10import Control.Exception (fromException)
@@ -14,54 +14,21 @@ main = defaultMain [testSuite]
15testSuite :: Test
15testSuite :: Test
16testSuite = testGroup "Text.Hamlet"
16testSuite = testGroup "Text.Hamlet"
17− [ testCase "takeLineMax safe" caseTakeLineMaxSafe
18− , testCase "takeUntilBlank safe" caseTakeUntilBlankSafe
17+ [ testCase "takeUntilBlank safe" caseTakeUntilBlankSafe
19− , testCase "takeLineMax unsafe" caseTakeLineMaxUnsafe
20− , testCase "takeLineMax incomplete" caseTakeLineMaxIncomplete
21 , testCase "takeUntilBlank too many lines" caseTakeUntilBlankTooMany
18 , testCase "takeUntilBlank too many lines" caseTakeUntilBlankTooMany
22 , testCase "takeUntilBlank too large" caseTakeUntilBlankTooLarge
19 , testCase "takeUntilBlank too large" caseTakeUntilBlankTooLarge
25−caseTakeLineMaxSafe = do
26− x <- run_ $ (enumList 1 ["f", "oo\n\n", "bar\n\r\nbaz\n"]) $$ do
27− a <- takeLineMax 0 id
28− b <- takeLineMax 0 id
29− c <- takeLineMax 0 id
30− d <- takeLineMax 0 id
31− e <- takeLineMax 0 id
32− return (a, b, c, d, e)
33− x @?= ("foo", "", "bar", "", "baz")
35caseTakeUntilBlankSafe = do
22caseTakeUntilBlankSafe = do
36 x <- run_ $ (enumList 1 ["f", "oo\n", "bar\nbaz\n\r\n"]) $$ takeHeaders
23 x <- run_ $ (enumList 1 ["f", "oo\n", "bar\nbaz\n\r\n"]) $$ takeHeaders
37 x @?= ["foo", "bar", "baz"]
24 x @?= ["foo", "bar", "baz"]
39−caseTakeLineMaxUnsafe = do
40− x <- run $ (enumList 1 $ repeat "abc") $$ do
41− a <- takeLineMax 0 id
42− b <- takeLineMax 0 id
43− c <- takeLineMax 0 id
44− d <- takeLineMax 0 id
45− e <- takeLineMax 0 id
46− return (a, b, c, d, e)
47− assertException OverLargeHeader x
49assertException x (Left se) =
26assertException x (Left se) =
50 case fromException se of
27 case fromException se of
51 Just e -> e @?= x
28 Just e -> e @?= x
52 Nothing -> assertFailure "Not an exception"
29 Nothing -> assertFailure "Not an exception"
53assertException _ _ = assertFailure "Not an exception"
30assertException _ _ = assertFailure "Not an exception"
55−caseTakeLineMaxIncomplete = do
56− x <- run $ (enumList 1 ["f", "oo\n\n", "bar\n\nbaz"]) $$ do
57− a <- takeLineMax 0 id
58− b <- takeLineMax 0 id
59− c <- takeLineMax 0 id
60− d <- takeLineMax 0 id
61− e <- takeLineMax 0 id
62− return (a, b, c, d, e)
63− assertException IncompleteHeaders x
65caseTakeUntilBlankTooMany = do
32caseTakeUntilBlankTooMany = do
66 x <- run $ (enumList 1 $ repeat "f\n") $$ takeHeaders
33 x <- run $ (enumList 1 $ repeat "f\n") $$ takeHeaders
67 assertException OverLargeHeader x
34 assertException OverLargeHeader x