mockcat-1.0.1.0: Declarative mocking with a single arrow `~>`.
Safe HaskellNone
LanguageHaskell2010

Test.MockCat.Param

Description

This module provides types and functions for representing mock parameters. Parameters are used both for setting up expectations and for verification.

Synopsis

Documentation

data Param v where Source #

Constructors

ExpectValue :: forall v. (Show v, Eq v) => v -> String -> Param v

A parameter that expects a specific value.

ExpectCondition :: forall v. (v -> Bool) -> String -> Param v

A parameter that expects a value satisfying a condition.

ValueWrapper :: forall v. v -> String -> Param v

A parameter that wraps a value without Eq or Show constraints.

Instances

Instances details
(ResolvableMockWithParams m (Param a), Eq (Param a), Show (Param a)) => ShouldBeCalled m (Param a) Source #

Instance for single Param (e.g., param "a")

Instance details

Defined in Test.MockCat.Verify

Methods

shouldBeCalled :: m -> Param a -> IO () Source #

(ResolvableMockWithParams m (Param a :> rest), Eq (Param a :> rest), Show (Param a :> rest)) => ShouldBeCalled m (Param a :> rest) Source #

Instance for Param chains (e.g., "a" ~> "b")

Instance details

Defined in Test.MockCat.Verify

Methods

shouldBeCalled :: m -> (Param a :> rest) -> IO () Source #

Show (Param v) Source # 
Instance details

Defined in Test.MockCat.Param

Methods

showsPrec :: Int -> Param v -> ShowS #

show :: Param v -> String #

showList :: [Param v] -> ShowS #

Eq (Param a) Source # 
Instance details

Defined in Test.MockCat.Param

Methods

(==) :: Param a -> Param a -> Bool #

(/=) :: Param a -> Param a -> Bool #

ToParamArg (Param a) Source # 
Instance details

Defined in Test.MockCat.Param

Methods

toParamArg :: Param a -> Normalize (Param a) Source #

ToNormalizedArg (Param a) Source # 
Instance details

Defined in Test.MockCat.Verify

StubBuilder (Param r) r Source #

Instance for building a mock for a function with a single parameter.

Instance details

Defined in Test.MockCat.Internal.Builder

Methods

buildStub :: Maybe MockName -> Param r -> r Source #

(WrapParam a, fn ~ (a -> r)) => BuildCurried (Param a) r fn Source # 
Instance details

Defined in Test.MockCat.Internal.Builder

Methods

buildCurriedImpl :: (Param a -> IO r) -> fn Source #

(WrapParam a, fn ~ (a -> IO r)) => BuildCurriedIO (Param a) r fn Source # 
Instance details

Defined in Test.MockCat.Internal.Builder

Methods

buildCurriedIOImpl :: (Param a -> IO r) -> fn Source #

(WrapParam a, fn ~ (a -> r)) => BuildCurriedPure (Param a) r fn Source # 
Instance details

Defined in Test.MockCat.Internal.Builder

Methods

buildCurriedPureImpl :: (Param a -> r) -> fn Source #

MockBuilder (Param r) r () Source #

Instance for building a stub for a value (backward compatibility).

Instance details

Defined in Test.MockCat.Internal.Builder

Methods

build :: MonadIO m => Maybe MockName -> Param r -> m (BuiltMock r ()) Source #

ProjectionArgs (Head :> Param r) Source # 
Instance details

Defined in Test.MockCat.Param

Methods

projArgs :: (Head :> Param r) -> ArgsOf (Head :> Param r) Source #

ProjectionArgs (Param a :> Param r) Source # 
Instance details

Defined in Test.MockCat.Param

Methods

projArgs :: (Param a :> Param r) -> ArgsOf (Param a :> Param r) Source #

(ProjectionArgs rest, ArgsOf (Param a :> rest) ~ (Param a :> ArgsOf rest)) => ProjectionArgs (Param a :> rest) Source # 
Instance details

Defined in Test.MockCat.Param

Methods

projArgs :: (Param a :> rest) -> ArgsOf (Param a :> rest) Source #

ProjectionReturn (Head :> Param r) Source # 
Instance details

Defined in Test.MockCat.Param

ProjectionReturn (Param a :> Param r) Source # 
Instance details

Defined in Test.MockCat.Param

Methods

projReturn :: (Param a :> Param r) -> ReturnOf (Param a :> Param r) Source #

(ProjectionReturn rest, ReturnOf (Param a :> rest) ~ ReturnOf rest) => ProjectionReturn (Param a :> rest) Source # 
Instance details

Defined in Test.MockCat.Param

Methods

projReturn :: (Param a :> rest) -> ReturnOf (Param a :> rest) Source #

ToNormalizedArg (Param a :> rest) Source # 
Instance details

Defined in Test.MockCat.Verify

Methods

toNormalizedArg :: (Param a :> rest) -> NormalizeWithArg (Param a :> rest) Source #

(p ~ (Param a :> rest), ParamConstraints p args r, BuildCurried args r fn, BuildCurriedPure args r fn) => StubBuilder (Param a :> rest) fn Source # 
Instance details

Defined in Test.MockCat.Internal.Builder

Methods

buildStub :: Maybe MockName -> (Param a :> rest) -> fn Source #

(BuildCurried rest r fn, WrapParam a, fn' ~ (a -> fn)) => BuildCurried (Param a :> rest) r fn' Source # 
Instance details

Defined in Test.MockCat.Internal.Builder

Methods

buildCurriedImpl :: ((Param a :> rest) -> IO r) -> fn' Source #

(BuildCurriedIO rest r fn, WrapParam a, fn' ~ (a -> fn)) => BuildCurriedIO (Param a :> rest) r fn' Source # 
Instance details

Defined in Test.MockCat.Internal.Builder

Methods

buildCurriedIOImpl :: ((Param a :> rest) -> IO r) -> fn' Source #

(BuildCurriedPure rest r fn, WrapParam a, fn' ~ (a -> fn)) => BuildCurriedPure (Param a :> rest) r fn' Source # 
Instance details

Defined in Test.MockCat.Internal.Builder

Methods

buildCurriedPureImpl :: ((Param a :> rest) -> r) -> fn' Source #

MockBuilder (Head :> Param r) r () Source #

Instance for building a stub for a constant value (with Head marker).

Instance details

Defined in Test.MockCat.Internal.Builder

Methods

build :: MonadIO m => Maybe MockName -> (Head :> Param r) -> m (BuiltMock r ()) Source #

(p ~ (Param a :> rest), ParamConstraints p args r, BuildCurried args r fn) => MockBuilder (Param a :> rest) fn args Source #

Overlapping instance for building a stub defined via chained Param.

Instance details

Defined in Test.MockCat.Internal.Builder

Methods

build :: MonadIO m => Maybe MockName -> (Param a :> rest) -> m (BuiltMock fn args) Source #

(p ~ (Param a :> rest), ParamConstraints p args r, BuildCurriedIO args r fn) => MockIOBuilder (Param a :> rest) fn args Source # 
Instance details

Defined in Test.MockCat.Internal.Builder

Methods

buildIO :: MonadIO m => Maybe MockName -> (Param a :> rest) -> m (BuiltMock fn args) Source #

class WrapParam a where Source #

Class for wrapping raw values into Param. For types with Show and Eq, it uses ExpectValue to enable comparison and display. For other types, it uses ValueWrapper.

Methods

wrap :: a -> Param a Source #

Instances

Instances details
WrapParam Text Source # 
Instance details

Defined in Test.MockCat.Param

Methods

wrap :: Text -> Param Text Source #

WrapParam String Source # 
Instance details

Defined in Test.MockCat.Param

WrapParam Integer Source # 
Instance details

Defined in Test.MockCat.Param

WrapParam Bool Source # 
Instance details

Defined in Test.MockCat.Param

Methods

wrap :: Bool -> Param Bool Source #

WrapParam Char Source # 
Instance details

Defined in Test.MockCat.Param

Methods

wrap :: Char -> Param Char Source #

WrapParam Double Source # 
Instance details

Defined in Test.MockCat.Param

WrapParam Float Source # 
Instance details

Defined in Test.MockCat.Param

Methods

wrap :: Float -> Param Float Source #

WrapParam Int Source # 
Instance details

Defined in Test.MockCat.Param

Methods

wrap :: Int -> Param Int Source #

WrapParam a Source # 
Instance details

Defined in Test.MockCat.Param

Methods

wrap :: a -> Param a Source #

(Show a, Eq a) => WrapParam (Maybe a) Source # 
Instance details

Defined in Test.MockCat.Param

Methods

wrap :: Maybe a -> Param (Maybe a) Source #

(Show a, Eq a) => WrapParam [a] Source # 
Instance details

Defined in Test.MockCat.Param

Methods

wrap :: [a] -> Param [a] Source #

value :: Param v -> v Source #

param :: (Show v, Eq v) => v -> Param v Source #

Create a Param from a value. Requires Eq and Show.

class ConsGen a b where Source #

Methods

(~>) :: a -> b -> Normalize a :> Normalize b infixr 0 Source #

Instances

Instances details
(ToParamArg a, ToParamResult b) => ConsGen a b Source # 
Instance details

Defined in Test.MockCat.Param

Methods

(~>) :: a -> b -> Normalize a :> Normalize b Source #

expect :: (a -> Bool) -> String -> Param a Source #

Create a conditional parameter with a label. When calling a mock function, if the argument does not satisfy this condition, an error occurs. In this case, the specified label is included in the error message.

expect (>5) ">5"

expect_ :: (a -> Bool) -> Param a Source #

Create a conditional parameter without a label. The error message is displayed as "[some condition]".

expect_ (>5)

any :: Param a Source #

Make a parameter to which any value is expected to apply. Use with type application to specify the type: any @String

f <- mock $ any ~> True

type family ArgsOf params where ... Source #

The type of the argument parameters of the parameters.

Equations

ArgsOf (Head :> Param r) = () 
ArgsOf (Param a :> Param r) = Param a 
ArgsOf (Param a :> rest) = Param a :> ArgsOf rest 

class ProjectionArgs params Source #

Class for projecting the arguments of the parameter.

Minimal complete definition

projArgs

Instances

Instances details
ProjectionArgs (Head :> Param r) Source # 
Instance details

Defined in Test.MockCat.Param

Methods

projArgs :: (Head :> Param r) -> ArgsOf (Head :> Param r) Source #

ProjectionArgs (Param a :> Param r) Source # 
Instance details

Defined in Test.MockCat.Param

Methods

projArgs :: (Param a :> Param r) -> ArgsOf (Param a :> Param r) Source #

(ProjectionArgs rest, ArgsOf (Param a :> rest) ~ (Param a :> ArgsOf rest)) => ProjectionArgs (Param a :> rest) Source # 
Instance details

Defined in Test.MockCat.Param

Methods

projArgs :: (Param a :> rest) -> ArgsOf (Param a :> rest) Source #

projArgs :: ProjectionArgs params => params -> ArgsOf params Source #

type family ReturnOf params where ... Source #

The type of the return parameter of the parameters.

Equations

ReturnOf (Head :> Param r) = Param r 
ReturnOf (Param a :> Param r) = Param r 
ReturnOf (Param a :> rest) = ReturnOf rest 

class ProjectionReturn param Source #

Minimal complete definition

projReturn

Instances

Instances details
ProjectionReturn (Head :> Param r) Source # 
Instance details

Defined in Test.MockCat.Param

ProjectionReturn (Param a :> Param r) Source # 
Instance details

Defined in Test.MockCat.Param

Methods

projReturn :: (Param a :> Param r) -> ReturnOf (Param a :> Param r) Source #

(ProjectionReturn rest, ReturnOf (Param a :> rest) ~ ReturnOf rest) => ProjectionReturn (Param a :> rest) Source # 
Instance details

Defined in Test.MockCat.Param

Methods

projReturn :: (Param a :> rest) -> ReturnOf (Param a :> rest) Source #

projReturn :: ProjectionReturn param => param -> ReturnOf param Source #

returnValue :: (ProjectionReturn params, ReturnOf params ~ Param r) => params -> r Source #

type family Normalize a where ... Source #

Type family to untie the knot for ConsGen instances

Equations

Normalize (a :> b) = a :> b 
Normalize (Param a) = Param a 
Normalize a = Param a 

class ToParamArg a where Source #

Methods

toParamArg :: a -> Normalize a Source #

Instances

Instances details
(Normalize a ~ Param a, WrapParam a) => ToParamArg a Source # 
Instance details

Defined in Test.MockCat.Param

Methods

toParamArg :: a -> Normalize a Source #

ToParamArg (Param a) Source # 
Instance details

Defined in Test.MockCat.Param

Methods

toParamArg :: Param a -> Normalize (Param a) Source #

Typeable (a -> b) => ToParamArg (a -> b) Source # 
Instance details

Defined in Test.MockCat.Param

Methods

toParamArg :: (a -> b) -> Normalize (a -> b) Source #