{-# 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 "barfoobaz" ["barbaz"] , it "handles single chunks, no " $ helper "barfoo" ["bar"] , it "handles whole chunks" $ helper "barfoobaz" ["bar", "", "baz"] , it "handles split chunks" $ helper "barfoobaz" ["bar", "", "baz"] , it "handles many chunks" $ helper "barfoobaz1234567890" ["bar", "", "baz", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0"] , it "handles many pieces" $ helper "barfoobaz" $ map S.singleton $ S.unpack "barbaz" ] helper :: S.ByteString -> [S.ByteString] -> Assertion helper res pieces = do x <- run_ $ enumList 1 pieces $$ joinI $ insideHead "foo" $$ consume S.concat x @?= res