wai/wai-handler-launch/runtests.hs
Michael Snoyman 027a09e3e8 Add 'wai-handler-launch/' from commit 'bf2844de5e2612a6c2ce962a91664da203b8aaf6'
git-subtree-dir: wai-handler-launch
git-subtree-mainline: 745eba8d63
git-subtree-split: bf2844de5e
2011-07-22 16:52:42 +03:00

23 lines
1016 B
Haskell

{-# LANGUAGE OverloadedStrings #-}
import Network.Wai.Handler.Launch (insideHead)
import Test.Hspec
import Test.Hspec.HUnit
import Data.Enumerator hiding (map)
import Test.HUnit
import qualified Data.ByteString as S
main :: IO ()
main = hspec $ describe "insideHead"
[ it "handles single chunks" $ helper "bar<head>foobaz" ["bar<head>baz"]
, it "handles single chunks, no <head>" $ helper "barfoo" ["bar"]
, it "handles whole chunks" $ helper "bar<head>foobaz" ["bar", "<head>", "baz"]
, it "handles split chunks" $ helper "bar<head>foobaz" ["bar", "<he", "ad>", "baz"]
, it "handles many chunks" $ helper "bar<head>foobaz1234567890" ["bar", "<he", "ad>", "baz", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0"]
, it "handles many pieces" $ helper "bar<head>foobaz" $ map S.singleton $ S.unpack "bar<head>baz"
]
helper :: S.ByteString -> [S.ByteString] -> Assertion
helper res pieces = do
x <- run_ $ enumList 1 pieces $$ joinI $ insideHead "foo" $$ consume
S.concat x @?= res