{-# LANGUAGE OverloadedStrings #-}moduleSnap.Internal.Test.Assertionswhere------------------------------------------------------------------------------importBlaze.ByteString.BuilderimportControl.Monad(liftM)importData.ByteString.Char8(ByteString)importData.Maybe(fromJust)importData.Monoid(mconcat)importTest.HUnit(Assertion,assertBool,assertEqual)importText.Regex.Posix((=~))------------------------------------------------------------------------------importSnap.Internal.Http.TypesimportSnap.Iteratee(run_,consume,($$))------------------------------------------------------------------------------getResponseBody::Response->IOByteStringgetResponseBodyrsp=run_$enum$$liftMtoBSconsumewhereenum=rspBodyToEnum$rspBodyrsptoBS=toByteString.mconcat-------------------------------------------------------------------------------- | Given a Response, asserts that its HTTP status code is 200 (success).assertSuccess::Response->AssertionassertSuccessrsp=assertEqualmessage200statuswheremessage="Expected success (200) but got ("++(showstatus)++")"status=rspStatusrsp-------------------------------------------------------------------------------- | Given a Response, asserts that its HTTP status code is 404 (Not Found).assert404::Response->Assertionassert404rsp=assertEqualmessage404statuswheremessage="Expected Not Found (404) but got ("++(showstatus)++")"status=rspStatusrsp-------------------------------------------------------------------------------- | Given a Response, asserts that its HTTP status code is between 300 and-- 399 (a redirect), and that the Location header of the Response points to-- the specified URI.assertRedirectTo::ByteString-- ^ The Response should redirect to this-- URI->Response->AssertionassertRedirectTourirsp=doassertRedirectrspassertEqualmessageurirspUriwhererspUri=fromJust$getHeader"Location"rspmessage="Expected redirect to "++showuri++" but got redirected to "++showrspUri++" instead"-------------------------------------------------------------------------------- | Given a Response, asserts that its HTTP status code is between 300 and-- 399 (a redirect).assertRedirect::Response->AssertionassertRedirectrsp=assertBoolmessage(300<=status&&status<=399)wheremessage="Expected redirect but got status code ("++showstatus++")"status=rspStatusrsp-------------------------------------------------------------------------------- | Given a Response, asserts that its body matches the given regular-- expression.assertBodyContains::ByteString-- ^ Regexp that will match the body content->Response->AssertionassertBodyContainsmatchrsp=dobody<-getResponseBodyrspassertBoolmessage(body=~match)wheremessage="Expected body to match regexp \""++showmatch++"\", but didn't"