Test.Hspec.Core.Util

hspec-core-2.4.2: A Testing Framework for Haskell

Stability | unstable
Safe Haskell | Safe
Language | Haskell2010

Test.Hspec.Core.Util

Contents

- String functions
- Working with paths
- Working with exception

Description

Synopsis

- pluralize :: Int -> String -> String
- strip :: String -> String
- lineBreaksAt :: Int -> String -> [String]
- type Path = ([String], String)
- formatRequirement :: Path -> String
- filterPredicate :: String -> Path -> Bool
- safeTry :: IO a -> IO (Either SomeException a)
- formatException :: SomeException -> String

# String functions

pluralize :: Int -> String -> String #

`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 #

Strip leading and trailing whitespace

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

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

# Working with paths

type Path = ([String], String) #

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 #

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

filterPredicate :: String -> Path -> Bool #

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

# Working with exception

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

`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 #

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 `IOException`s the `IOErrorType` is included, as well.