on wai-extra/3.0.1.2 help sign in
22 lines 1.0 kB history raw
1{-# LANGUAGE OverloadedStrings #-}
2import Network.Wai.Handler.Launch (insideHead)
3import Test.Hspec
4import Test.Hspec.HUnit
5import Data.Enumerator hiding (map)
6import Test.HUnit
7import qualified Data.ByteString as S
9main :: IO ()
10main = hspec $ describe "insideHead"
11 [ it "handles single chunks" $ helper "bar<head>foobaz" ["bar<head>baz"]
12 , it "handles single chunks, no <head>" $ helper "barfoo" ["bar"]
13 , it "handles whole chunks" $ helper "bar<head>foobaz" ["bar", "<head>", "baz"]
14 , it "handles split chunks" $ helper "bar<head>foobaz" ["bar", "<he", "ad>", "baz"]
15 , it "handles many chunks" $ helper "bar<head>foobaz1234567890" ["bar", "<he", "ad>", "baz", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0"]
16 , it "handles many pieces" $ helper "bar<head>foobaz" $ map S.singleton $ S.unpack "bar<head>baz"
17 ]
19helper :: S.ByteString -> [S.ByteString] -> Assertion
20helper res pieces = do
21 x <- run_ $ enumList 1 pieces $$ joinI $ insideHead "foo" $$ consume
22 S.concat x @?= res