Expect

fun interface Expect<out Value>(source)

A type representing a value under assertion.

The Expect interface wraps a value and provides a way to expose it for assertion checks. It serves as the foundation for the assertion DSL, allowing for chained assertion calls in a type-safe manner.

Implementations of this functional interface must provide the exposeValue function, which returns the underlying value being asserted on.

Type Parameters

Value

The type of the value being asserted on. This is a covariant type parameter, allowing for flexible subtyping in assertion chains.

Types

Link copied to clipboard
object Companion

Companion object for the Expect interface, providing factory methods for creating assertions.

Link copied to clipboard
annotation class Dsl

DSL marker annotation to prevent unwanted implicit receivers in assertion lambdas.

Functions

Link copied to clipboard
context(assertionScope: AssertionScope)
inline fun <Value> Expect<Value>.assert(checker: (Value) -> AssertionScope.Assertion)

Executes the given assertion checker on the value exposed by this Expect instance.

Link copied to clipboard
abstract fun exposeValue(): Value

Exposes the underlying value being asserted on.

Link copied to clipboard
context(assertionScope: AssertionScope)
infix fun Expect<Any?>.notToBe(expected: Any?)

Asserts that the exposed value is not equal to the expected value using == comparison.

Link copied to clipboard
context(assertionScope: AssertionScope)
infix fun Expect<Any?>.notToBeTheSameInstanceAs(expected: Any?)

Asserts that the exposed value is not the same instance as the expected value using !== comparison.

Link copied to clipboard
context(assertionScope: AssertionScope)
infix fun Expect<Any?>.toBe(expected: Any?)

Asserts that the exposed value is equal to the expected value using == comparison.

Link copied to clipboard
context(assertionScope: AssertionScope)
infix fun <Element : Comparable<Element>> Expect<Element>.toBeGreaterThan(expected: Element)

Asserts that the exposed value is greater than the expected value.

Link copied to clipboard
context(assertionScope: AssertionScope)
infix fun <Element : Comparable<Element>> Expect<Element>.toBeGreaterThanOrEqualTo(expected: Element)

Asserts that the exposed value is greater than or equal to the expected value.

Link copied to clipboard
context(assertionScope: AssertionScope)
infix fun <Element : Comparable<Element>> Expect<Element>.toBeLessThan(expected: Element)

Asserts that the exposed value is less than the expected value.

Link copied to clipboard
context(assertionScope: AssertionScope)
infix fun <Element : Comparable<Element>> Expect<Element>.toBeLessThanOrEqualTo(expected: Element)

Asserts that the exposed value is less than or equal to the expected value.

Link copied to clipboard
context(assertionScope: AssertionScope)
infix fun Expect<Any?>.toBeTheSameInstanceAs(expected: Any?)

Asserts that the exposed value is the same instance as the expected value using === comparison.

Link copied to clipboard

Transforms an Expect assertion from one value type to another using a provider function.

inline fun <OldValue, NewValue> Expect<OldValue>.using(noinline provider: (OldValue) -> NewValue, block: Expect<NewValue>.() -> Unit)

Transforms an Expect assertion from one value type to another using a provider function and executes the assertion block on the transformed value.

Link copied to clipboard

Transforms an Expect assertion from one value type to another using a lazily-evaluated provider function.

inline fun <OldValue, NewValue> Expect<OldValue>.usingLazily(noinline provider: (OldValue) -> NewValue, block: Expect<NewValue>.() -> Unit)

Transforms an Expect assertion from one value type to another using a lazily-evaluated provider function and executes the assertion block on the transformed value.