hspec-core-2.4.4: A Testing Framework for Haskell

Stabilityunstable
Safe HaskellSafe
LanguageHaskell2010

Test.Hspec.Core.Util

Contents

Description

 

Synopsis

String functions

pluralize :: Int -> String -> String Source #

pluralize count singular pluralizes the given singular word unless given count is 1.

Examples:

>>> pluralize 0 "example"
"0 examples"
>>> pluralize 1 "example"
"1 example"
>>> pluralize 2 "example"
"2 examples"

strip :: String -> String Source #

Strip leading and trailing whitespace

lineBreaksAt :: Int -> String -> [String] Source #

ensure that lines are not longer than given n, insert line breaks at word boundaries

Working with paths

type Path = ([String], String) Source #

A Path represents the location of an example within the spec tree.

It consists of a list of group descriptions and a requirement description.

formatRequirement :: Path -> String Source #

Try to create a proper English sentence from a path by applying some heuristics.

filterPredicate :: String -> Path -> Bool Source #

A predicate that can be used to filter a spec tree.

Working with exception

safeTry :: IO a -> IO (Either SomeException a) Source #

safeTry evaluates given action and returns its result. If an exception occurs, the exception is returned instead. Unlike try it is agnostic to asynchronous exceptions.

formatException :: SomeException -> String Source #

The function formatException converts an exception to a string.

This is different from show. The type of the exception is included, e.g.:

>>> formatException (toException DivideByZero)
"ArithException (divide by zero)"

For IOExceptions the IOErrorType is included, as well.