Header menu logo testify

AssertOperators Module

Concise operator syntax for example-based assertions.

The Assert DSL is expression-left: the quoted value stays on the left and the asserted logic reads from left to right.

Recommended usage: |>? for one expectation, <|> and <&> to compose a few reusable expectations, ||? when any expectation from a sequence may pass, and &&? when every expectation from a sequence must pass.

Assert operators are fail-fast. They raise on the first failing assertion instead of collecting multiple failures.

Functions and values

Function or value Description

!?expr

Full Usage: !?expr

Parameters:
    expr : Expr<bool> - The quoted boolean expression under test.

Modifiers: inline

Asserts that a quoted boolean expression evaluates to false.

expr : Expr<bool>

The quoted boolean expression under test.

Exception Raised when the assertion fails.

expr &&? expectations

Full Usage: expr &&? expectations

Parameters:
    expr : Expr<'T> - The quoted expression under test.
    expectations : AssertExpectation<'T> seq - The expectations that must all succeed.

Modifiers: inline
Type parameters: 'T

Asserts that every expectation from a sequence succeeds.

Use this when you want readable sequence-based logic instead of manually folding <&>.

expr : Expr<'T>

The quoted expression under test.

expectations : AssertExpectation<'T> seq

The expectations that must all succeed.

Exception Raised when any supplied expectation fails.
Example

 <@ "Testify" @> &&?
     [ AssertExpectation.startsWith "Test"
       AssertExpectation.endsWith "fy" ]

a <&> b

Full Usage: a <&> b

Parameters:
    a : ^T - The first required expectation.
    b : ^T - The second required expectation.

Returns: ^T A combined expectation that succeeds only when both input expectations succeed.
Modifiers: inline
Type parameters: ^T

Combines two expectations with logical AND.

Use this to build reusable logic before applying it with |>?.

a : ^T

The first required expectation.

b : ^T

The second required expectation.

Returns: ^T

A combined expectation that succeeds only when both input expectations succeed.

expr <=? value

Full Usage: expr <=? value

Parameters:
    expr : Expr<'T> - The quoted expression under test.
    value : 'T - The inclusive upper bound.

Modifiers: inline
Type parameters: 'T

Asserts that a quoted value is less than or equal to a comparison value.

expr : Expr<'T>

The quoted expression under test.

value : 'T

The inclusive upper bound.

Exception Raised when the assertion fails.

expr <>? value

Full Usage: expr <>? value

Parameters:
    expr : Expr<'T> - The quoted expression under test.
    value : 'T - The value that must not be observed.

Modifiers: inline
Type parameters: 'T

Asserts that a quoted value does not equal the provided value.

expr : Expr<'T>

The quoted expression under test.

value : 'T

The value that must not be observed.

Exception Raised when the assertion fails.

expr <? value

Full Usage: expr <? value

Parameters:
    expr : Expr<'T> - The quoted expression under test.
    value : 'T - The exclusive upper bound.

Modifiers: inline
Type parameters: 'T

Asserts that a quoted value is less than a comparison value.

expr : Expr<'T>

The quoted expression under test.

value : 'T

The exclusive upper bound.

Exception Raised when the assertion fails.

a <|> b

Full Usage: a <|> b

Parameters:
    a : ^T - The first alternative expectation.
    b : ^T - The second alternative expectation.

Returns: ^T A combined expectation that succeeds when either input expectation succeeds.
Modifiers: inline
Type parameters: ^T

Combines two expectations with logical OR.

Use this to build reusable logic before applying it with |>?.

a : ^T

The first alternative expectation.

b : ^T

The second alternative expectation.

Returns: ^T

A combined expectation that succeeds when either input expectation succeeds.

expr =? value

Full Usage: expr =? value

Parameters:
    expr : Expr<'T> - The quoted expression under test.
    value : 'T - The expected value.

Modifiers: inline
Type parameters: 'T

Asserts that a quoted value equals the provided value.

expr : Expr<'T>

The quoted expression under test.

value : 'T

The expected value.

Exception Raised when the assertion fails.
Example

 <@ List.length [1; 2; 3] @> =? 3
Multiple items
module List from Microsoft.FSharp.Collections

--------------------
type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T with get member IsEmpty: bool with get member Item: index: int -> 'T with get ...
val length: list: 'T list -> int

expr >=? value

Full Usage: expr >=? value

Parameters:
    expr : Expr<'T> - The quoted expression under test.
    value : 'T - The inclusive lower bound.

Modifiers: inline
Type parameters: 'T

Asserts that a quoted value is greater than or equal to a comparison value.

expr : Expr<'T>

The quoted expression under test.

value : 'T

The inclusive lower bound.

Exception Raised when the assertion fails.

expr >>? expectation

Full Usage: expr >>? expectation

Parameters:
    expr : Expr<'T> - The quoted expression under test.
    expectation : AssertExpectation<'T> - The expectation to apply.

Returns: Expr<'T> The original quoted expression.
Modifiers: inline
Type parameters: 'T

Runs one assertion, then returns the original quotation for further chaining.

This is the chain-friendly Assert operator. It supports readable left-to-right pipelines while preserving fail-fast behavior.

The returned quotation is not cached. If it is checked again later in the chain, it will be evaluated again.

expr : Expr<'T>

The quoted expression under test.

expectation : AssertExpectation<'T>

The expectation to apply.

Returns: Expr<'T>

The original quoted expression.

Exception Raised when expr does not satisfy expectation.
Example

 open Testify.AssertOperators

 <@ 5 @>
 >>? AssertExpectation.greaterThan 0
 >>? AssertExpectation.lessThan 10
 |> ignore
val ignore: value: 'T -> unit

expr >? value

Full Usage: expr >? value

Parameters:
    expr : Expr<'T> - The quoted expression under test.
    value : 'T - The exclusive lower bound.

Modifiers: inline
Type parameters: 'T

Asserts that a quoted value is greater than a comparison value.

expr : Expr<'T>

The quoted expression under test.

value : 'T

The exclusive lower bound.

Exception Raised when the assertion fails.

?expr

Full Usage: ?expr

Parameters:
    expr : Expr<bool> - The quoted boolean expression under test.

Modifiers: inline

Asserts that a quoted boolean expression evaluates to true.

expr : Expr<bool>

The quoted boolean expression under test.

Exception Raised when the assertion fails.

^!?expr

Full Usage: ^!?expr

Parameters:
    expr : Expr<'T> - The quoted expression under test.

Modifiers: inline
Type parameters: 'T

Asserts that evaluating the quoted expression completes without throwing.

expr : Expr<'T>

The quoted expression under test.

Exception Raised when an exception is observed.

^?expr

Full Usage: ^?expr

Parameters:
    expr : Expr<'T> - The quoted expression under test.

Modifiers: inline
Type parameters: 'T

Asserts that evaluating the quoted expression throws an exception.

expr : Expr<'T>

The quoted expression under test.

Exception Raised when no exception is observed.

expr |>? expectation

Full Usage: expr |>? expectation

Parameters:
    expr : Expr<'T> - The quoted expression under test.
    expectation : AssertExpectation<'T> - The expectation to apply.

Modifiers: inline
Type parameters: 'T

Applies one expectation to a quoted expression and raises immediately on failure.

This is the primary Assert DSL operator. Use it for one expectation, or for a small composed expectation built with <|> or <&>.

expr : Expr<'T>

The quoted expression under test.

expectation : AssertExpectation<'T>

The expectation to apply.

Exception Raised when expr does not satisfy expectation.
Example

 open Testify.AssertOperators

 <@ 2 + 3 @> |>? AssertExpectation.equalTo 5

Example

 <@ 5 @> |>? (AssertExpectation.greaterThan 0 <&> AssertExpectation.lessThan 10)

expr ||? expectations

Full Usage: expr ||? expectations

Parameters:
    expr : Expr<'T> - The quoted expression under test.
    expectations : AssertExpectation<'T> seq - The expectations to try.

Modifiers: inline
Type parameters: 'T

Asserts that at least one expectation from a sequence succeeds.

Use this when you have several alternative expectations and the expression may satisfy any one of them.

expr : Expr<'T>

The quoted expression under test.

expectations : AssertExpectation<'T> seq

The expectations to try.

Exception Raised when no supplied expectation succeeds.
Example

 <@ 5 @> ||? [ AssertExpectation.equalTo 4
             AssertExpectation.equalTo 5 ]

Type something to start searching.