Package-level declarations

Types

Link copied to clipboard
sealed class CaseSensitivity

The case sensitivity of a StringMatcher.

Link copied to clipboard
interface Matcher<in T> : Function1<T, MatchResult> , SelfDescribing

Acceptability criteria for a value of type T. A Matcher reports if a value of type T matches the criteria and describes the criteria in human-readable language.

Link copied to clipboard
sealed class MatchResult

The result of matching some actual value against criteria defined by a Matcher.

Link copied to clipboard
interface SelfDescribing

An object that can describe itself.

Link copied to clipboard
abstract class StringMatcher<S : CaseSensitivity>(caseSensitivity: S) : Matcher.Primitive<CharSequence>

A Matcher of strings with a specified case sensitivity.

Link copied to clipboard

A service interface for extensions to the describe function.

Properties

Link copied to clipboard
val anything: Matcher<Any?>

A Matcher that matches anything, always returning MatchResult.Match.

Link copied to clipboard
val isBlank: Matcher<CharSequence>

Matches a char sequence if it is empty or consists solely of whitespace characters.

Link copied to clipboard
val isEmpty: Matcher<Collection<Any>>

Matches an empty collection.

Link copied to clipboard
val isEmptyString: Matcher<CharSequence>

Matches a char sequence if it is empty (contains no characters).

Link copied to clipboard
val isNullOrBlank: Matcher<CharSequence?>

Matches a nullable char sequence if it is either null or empty or consists solely of whitespace characters.

Link copied to clipboard
val isNullOrEmptyString: Matcher<CharSequence?>

Matches a char sequence if it is either null or empty (contains no characters).

Link copied to clipboard
val nothing: Matcher<Any?>

A Matcher that matches nothing, always returning a MatchResult.Mismatch.

Functions

Link copied to clipboard
fun <T> absent(): Matcher<T?>

Returns a matcher that reports if a value is null.

Link copied to clipboard
fun <T> allElements(elementMatcher: Matcher<T>): Matcher.Primitive<Iterable<T>>

Matches an Iterable if all elements are matched by elementMatcher.

fun <T> allElements(elementPredicate: (T) -> Boolean): Matcher.Primitive<Iterable<T>>

Matches an Iterable if all elements are matched by elementPredicate.

Link copied to clipboard
fun <T> allOf(vararg matchers: Matcher<T>): Matcher<T>
fun <T> allOf(matchers: List<Matcher<T>>): Matcher<T>

Returns a matcher that matches if all of the supplied matchers match.

Link copied to clipboard
infix fun <T> Matcher<T>.and(that: Matcher<T>): Matcher<T>
infix fun <T> Matcher<T>.and(that: (T) -> Boolean): Matcher<T>
infix fun <T> (T) -> Boolean.and(that: Matcher<T>): Matcher<T>
infix fun <T> (T) -> Boolean.and(that: (T) -> Boolean): Matcher<T>

Syntactic sugar to create a Matcher.Conjunction

Link copied to clipboard
fun <T> anyElement(elementMatcher: Matcher<T>): Matcher.Primitive<Iterable<T>>

Matches an Iterable if any element is matched by elementMatcher.

fun <T> anyElement(elementPredicate: (T) -> Boolean): Matcher.Primitive<Iterable<T>>

Matches an Iterable if any element is matched by elementPredicate.

Link copied to clipboard
fun <T> anyOf(vararg matchers: Matcher<T>): Matcher<T>
fun <T> anyOf(matchers: List<Matcher<T>>): Matcher<T>

Returns a matcher that matches if any of the supplied matchers match.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
inline fun <T : Any> cast(downcastMatcher: Matcher<T>): Matcher<Any>

Returns a matcher that reports if a value of Any type is of a type compatible with downcastMatcher and, if so, if the value meets its criteria.

Link copied to clipboard
fun closeTo(expected: Double, error: Double = 1.0E-5): Matcher<Double>
fun closeTo(expected: Float, error: Float = 1.0E-5f): Matcher<Float>

Returns a matcher that reports if a value is equal to an expected value, withing a range of +/- error.

Link copied to clipboard
fun contains(r: Regex): Matcher<String>

Matches a char sequence if it contain the given Regex.

Link copied to clipboard

Matches a char sequence if it contains substring.

Link copied to clipboard
fun describe(v: Any?): String

Formats v to be included in a description. Strings are delimited with quotes and elements of tuples, ranges, iterable collections and maps are (recursively) described. A null reference is described as null. For anything else, the result of Any.toString is used.

Link copied to clipboard
fun <T> Matcher<T>.describedBy(fn: () -> String): Matcher<T>
Link copied to clipboard

Matches a char sequence if it ends with suffix.

Link copied to clipboard
fun <T> equalTo(expected: T?): Matcher<T?>

Returns a matcher that reports if a value is equal to an expected value. Handles null comparisons, just as the == operator does.

Link copied to clipboard
fun equalToIgnoringCase(expected: String?): Matcher<String?>

Matches a string if it is the same as the given string, ignoring case differences.

Link copied to clipboard
fun <N : Comparable<N>> greaterThan(n: N): Matcher<N>

Returns a matcher that reports if a Comparable value is greater than n

Link copied to clipboard
fun <N : Comparable<N>> greaterThanOrEqualTo(n: N): Matcher<N>

Returns a matcher that reports if a Comparable value is greater than or equal to n

Link copied to clipboard
fun <T, R> has(feature: (T) -> R, featureMatcher: Matcher<R>): Matcher<T>

Returns a matcher that applies featureMatcher to the result of applying feature to a value.

fun <T, R> has(property: KProperty1<T, R>, propertyMatcher: Matcher<R>): Matcher<T>

Returns a matcher that applies propertyMatcher to the current value of property of an object.

fun <T, R> has(name: String, feature: (T) -> R, featureMatcher: Matcher<R>): Matcher<T>

Returns a matcher that applies featureMatcher to the result of applying feature to a value. The description of the matcher uses name to describe the feature.

Link copied to clipboard
fun <T> hasElement(element: T): Matcher<Collection<T>>

Matches a collection that contains element

Link copied to clipboard
fun hasSize(sizeMatcher: Matcher<Int>): Matcher<Collection<Any>>

Matches a collection with a size that matches sizeMatcher.

Link copied to clipboard
fun identifierToWords(s: String): List<String>
Link copied to clipboard
inline fun <T : Any> isA(downcastMatcher: Matcher<T>? = null): Matcher<Any>

Returns a matcher that reports if a value of Any type is of a type compatible with downcastMatcher and, if so, if the value meets its criteria.

Link copied to clipboard
fun <T> isIn(vararg elements: T): Matcher<T>
fun <T> isIn(i: Iterable<T>): Matcher<T>
Link copied to clipboard
fun <T : Comparable<T>> isWithin(range: ClosedRange<T>): Matcher<T>

Returns a matcher that reports if a kotlin.Comparable value falls within the given range.

Link copied to clipboard
fun <N : Comparable<N>> lessThan(n: N): Matcher<N>

Returns a matcher that reports if a Comparable value is less than n

Link copied to clipboard
fun <N : Comparable<N>> lessThanOrEqualTo(n: N): Matcher<N>

Returns a matcher that reports if a Comparable value is less than or equal to n

Link copied to clipboard
fun matches(r: Regex): Matcher<CharSequence>

Matches a char sequence if it all characters matches the given Regex.

Link copied to clipboard
infix fun <T> Matcher<T>.or(that: Matcher<T>): Matcher<T>
infix fun <T> Matcher<T>.or(that: (T) -> Boolean): Matcher<T>
infix fun <T> (T) -> Boolean.or(that: Matcher<T>): Matcher<T>
infix fun <T> (T) -> Boolean.or(that: (T) -> Boolean): Matcher<T>

Syntactic sugar to create a Matcher.Disjunction

Link copied to clipboard
fun <T> present(valueMatcher: Matcher<T>? = null): Matcher<T?>

Returns a matcher that reports if a value is not null and meets the criteria of the valueMatcher

Link copied to clipboard
fun <T> sameInstance(expected: T): Matcher<T>

Returns a matcher that reports if a value is the same instance as expected value.

Link copied to clipboard

Matches a char sequence if it starts with prefix.

Link copied to clipboard
inline fun <T : Throwable> throws(exceptionCriteria: Matcher<T>? = null): Matcher<() -> Unit>

Returns a matcher that reports if a block throws an exception of type T and, if exceptionCriteria is given, the exception matches the exceptionCriteria.