-
Notifications
You must be signed in to change notification settings - Fork 8
/
runtests.hs
38 lines (31 loc) · 1.24 KB
/
runtests.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE OverloadedStrings #-}
import Test.Framework (defaultMain, testGroup, Test)
import Test.Framework.Providers.HUnit
import Test.HUnit hiding (Test)
import Network.Wai.Handler.Warp (takeHeaders, InvalidRequest (..))
import Data.Enumerator (run_, ($$), enumList, run)
import Control.Exception (fromException)
main :: IO ()
main = defaultMain [testSuite]
testSuite :: Test
testSuite = testGroup "Text.Hamlet"
[ testCase "takeUntilBlank safe" caseTakeUntilBlankSafe
, testCase "takeUntilBlank too many lines" caseTakeUntilBlankTooMany
, testCase "takeUntilBlank too large" caseTakeUntilBlankTooLarge
]
caseTakeUntilBlankSafe = do
x <- run_ $ (enumList 1 ["f", "oo\n", "bar\nbaz\n\r\n"]) $$ takeHeaders
x @?= ["foo", "bar", "baz"]
assertException x (Left se) =
case fromException se of
Just e -> e @?= x
Nothing -> assertFailure "Not an exception"
assertException _ _ = assertFailure "Not an exception"
caseTakeUntilBlankTooMany = do
x <- run $ (enumList 1 $ repeat "f\n") $$ takeHeaders
assertException OverLargeHeader x
caseTakeUntilBlankTooLarge = do
x <- run $ (enumList 1 $ repeat "f") $$ takeHeaders
assertException OverLargeHeader x