Safe Haskell | None |
---|
This module defines an api for matchers: rules that can pass or fail, and describe their failure and success conditions for humans to read.
This module also exports some useful matchers for things in the Prelude, and some combinators that are useful for combining several matchers into one.
- data Matcher a = Matcher {
- match :: a -> Bool
- description :: String
- describeMismatch :: a -> String
- expect :: a -> Matcher a -> Assertion
- runMatch :: Matcher a -> a -> Match
- is :: (Show a, Eq a) => a -> Matcher a
- equalTo :: (Show a, Eq a) => a -> Matcher a
- isEmpty :: Show a => Matcher [a]
- hasSize :: Show a => Int -> Matcher [a]
- everyItem :: Matcher a -> Matcher [a]
- hasItem :: Matcher a -> Matcher [a]
- greaterThan :: (Ord a, Show a) => a -> Matcher a
- greaterThanOrEqual :: (Ord a, Show a) => a -> Matcher a
- lessThan :: (Ord a, Show a) => a -> Matcher a
- lessThanOrEqual :: (Ord a, Show a) => a -> Matcher a
- isJust :: Show a => Matcher (Maybe a)
- isNothing :: Show a => Matcher (Maybe a)
- isRight :: (Show a, Show b) => Matcher (Either a b)
- isLeft :: (Show a, Show b) => Matcher (Either a b)
- no :: Matcher a -> Matcher a
- allOf :: [Matcher a] -> Matcher a
- anyOf :: [Matcher a] -> Matcher a
- matcherOn :: Show a => String -> (a -> a -> Bool) -> a -> Matcher a
- matchList :: [Matcher a] -> a -> [Bool]
- standardMismatch :: Show a => a -> String
Documentation
The basic api for a matcher
Matcher | |
|
Useful functions for running matchers
expect :: a -> Matcher a -> AssertionSource
Run a matcher as an HUnit assertion
Example output:
Expected: equalTo "a" but: was "b"
Basic Matchers
Matchers on lists
hasItem :: Matcher a -> Matcher [a]Source
Matches if any of the items in the input list passes the provided matcher
Matchers on Ord
greaterThan :: (Ord a, Show a) => a -> Matcher aSource
Matches if the input is greater than the required number
greaterThanOrEqual :: (Ord a, Show a) => a -> Matcher aSource
Matches if the input is greater than or equal to the required number
lessThan :: (Ord a, Show a) => a -> Matcher aSource
Matches if the input is less than the required number
lessThanOrEqual :: (Ord a, Show a) => a -> Matcher aSource
Matches if the input is less than or equal to the required number
Matchers on Maybe
Matchers on Either
Matcher combinators
no :: Matcher a -> Matcher aSource
Inverts a matcher, so success becomes failure, and failure becomes success
Utility functions for writing your own matchers
matcherOn :: Show a => String -> (a -> a -> Bool) -> a -> Matcher aSource
Builds a Matcher a out of a name and a function from (a -> a -> Bool) Succeeds if the function returns true, fails if the function returns false
standardMismatch :: Show a => a -> StringSource
A standard mismatch description on (Show a): standardMismatch 1 == was 1