script-monad-0.0.1: Transformer stack of error, reader, writer, state, and prompt monads

Copyright2018 Automattic Inc.
LicenseBSD3
MaintainerNathan Bloomfield (nbloomf@gmail.com)
Stabilityexperimental
PortabilityPOSIX
Safe HaskellNone
LanguageHaskell2010

Data.MockIO

Contents

Description

A fake IO monad for testing.

Synopsis

MockIO

data MockIO s a Source #

A state monad over MockWorld.

Constructors

MockIO 

Fields

Instances

Monad (MockIO s) Source # 

Methods

(>>=) :: MockIO s a -> (a -> MockIO s b) -> MockIO s b #

(>>) :: MockIO s a -> MockIO s b -> MockIO s b #

return :: a -> MockIO s a #

fail :: String -> MockIO s a #

Functor (MockIO s) Source # 

Methods

fmap :: (a -> b) -> MockIO s a -> MockIO s b #

(<$) :: a -> MockIO s b -> MockIO s a #

Applicative (MockIO s) Source # 

Methods

pure :: a -> MockIO s a #

(<*>) :: MockIO s (a -> b) -> MockIO s a -> MockIO s b #

liftA2 :: (a -> b -> c) -> MockIO s a -> MockIO s b -> MockIO s c #

(*>) :: MockIO s a -> MockIO s b -> MockIO s b #

(<*) :: MockIO s a -> MockIO s b -> MockIO s a #

Show (MockIO s a) Source # 

Methods

showsPrec :: Int -> MockIO s a -> ShowS #

show :: MockIO s a -> String #

showList :: [MockIO s a] -> ShowS #

Arbitrary a => Arbitrary (MockIO s a) Source # 

Methods

arbitrary :: Gen (MockIO s a) #

shrink :: MockIO s a -> [MockIO s a] #

getMockWorld :: MockIO s (MockWorld s) Source #

Retrieve the current MockWorld.

putMockWorld :: MockWorld s -> MockIO s () Source #

Replace the current MockWorld.

modifyMockWorld :: (MockWorld s -> MockWorld s) -> MockIO s () Source #

Mutate the current MockWorld strictly.

incrementTimer :: Int -> MockIO s () Source #

Bump the timer by a given number of microseconds.

MockWorld

data MockWorld s Source #

Just enough state to mock out a basic filesystem and HTTP server.

Instances

newtype MockServer s Source #

Type representing the internal state of an HTTP server.

Constructors

MockServer 

Fields

Instances

Eq s => Eq (MockServer s) Source # 

Methods

(==) :: MockServer s -> MockServer s -> Bool #

(/=) :: MockServer s -> MockServer s -> Bool #

Show s => Show (MockServer s) Source # 

epoch :: UTCTime Source #

1970-01-01 00:00:00

basicMockWorld :: s -> MockWorld s Source #

Empty filesystem and trivial HTTP responses

MockNetwork

data MockNetwork s a Source #

State monad representing network interaction.

Instances

Monad (MockNetwork s) Source # 

Methods

(>>=) :: MockNetwork s a -> (a -> MockNetwork s b) -> MockNetwork s b #

(>>) :: MockNetwork s a -> MockNetwork s b -> MockNetwork s b #

return :: a -> MockNetwork s a #

fail :: String -> MockNetwork s a #

Functor (MockNetwork s) Source # 

Methods

fmap :: (a -> b) -> MockNetwork s a -> MockNetwork s b #

(<$) :: a -> MockNetwork s b -> MockNetwork s a #

Applicative (MockNetwork s) Source # 

Methods

pure :: a -> MockNetwork s a #

(<*>) :: MockNetwork s (a -> b) -> MockNetwork s a -> MockNetwork s b #

liftA2 :: (a -> b -> c) -> MockNetwork s a -> MockNetwork s b -> MockNetwork s c #

(*>) :: MockNetwork s a -> MockNetwork s b -> MockNetwork s b #

(<*) :: MockNetwork s a -> MockNetwork s b -> MockNetwork s a #

Show (MockNetwork s a) Source # 

Methods

showsPrec :: Int -> MockNetwork s a -> ShowS #

show :: MockNetwork s a -> String #

showList :: [MockNetwork s a] -> ShowS #

Arbitrary a => Arbitrary (MockNetwork s a) Source # 

Methods

arbitrary :: Gen (MockNetwork s a) #

shrink :: MockNetwork s a -> [MockNetwork s a] #

getMockServer :: MockNetwork s s Source #

Retrieve the internal state of the fake HTTP server.

putMockServer :: s -> MockNetwork s () Source #

Replace the internal state of the fake HTTP server.

modifyMockServer :: (s -> s) -> MockNetwork s () Source #

Mutate the internal state of the fake HTTP server (strictly).

Responses

_200ok :: ByteString -> HttpResponse Source #

Status 200; no headers

_400badRequest :: ByteString -> HttpResponse Source #

Status 400; no headers

_404notFound :: ByteString -> HttpResponse Source #

Status 404; no headers

_408requestTimeout :: ByteString -> HttpResponse Source #

Status 408; no headers