Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Assertions and matchers

Constructor

assert(actual)

Returns Assertion

Begin a fluent assertion on a value: assert(x).equals(y), .is_true(), .greater_than(n), etc. Matchers chain (.at_least(200).at_most(299)) and error (with a value-based message) on a mismatch. Asserting on a getter auto-labels the log line (assert(caller.state)Caller state, assert(res.status)HTTP status); .describe(…) overrides.

Methods

assertion.at_least(n: int)

Receiver Assertion · Returns Assertion

Assert the (numeric) value is >= n.

assertion.at_most(n: int)

Receiver Assertion · Returns Assertion

Assert the (numeric) value is <= n.

assertion.contains(needle: string)

Receiver Assertion · Returns Assertion

Assert the (string) value contains needle.

Example

#![allow(unused)]
fn main() {
assert(a.header("User-Agent")).contains("baresip");
}

assertion.describe(label: string)

Receiver Assertion · Returns Assertion

Label this assertion so the log line names it: assert(caller.registered) .describe("caller registered").is_true()caller registered: ✓ expect ….

assertion.equals(expected)

Receiver Assertion · Returns Assertion

Assert the value equals expected (is is a reserved word in Rhai).

Example

#![allow(unused)]
fn main() {
assert(a.state).equals(State::Established);
}

assertion.greater_than(n: int)

Receiver Assertion · Returns Assertion

Assert the (numeric) value is > n.

assertion.is_absent()

Receiver Assertion · Returns Assertion

Assert the value is absent (()).

assertion.is_empty()

Receiver Assertion · Returns Assertion

Assert the string/array/map value is empty.

assertion.is_false()

Receiver Assertion · Returns Assertion

Assert the value is false.

assertion.is_not_empty()

Receiver Assertion · Returns Assertion

Assert the string/array/map value is not empty.

assertion.is_present()

Receiver Assertion · Returns Assertion

Assert the value is present (not ()), e.g. a received header.

assertion.is_true()

Receiver Assertion · Returns Assertion

Assert the value is true.

Example

#![allow(unused)]
fn main() {
assert(a.registered).is_true();
}

assertion.less_than(n: int)

Receiver Assertion · Returns Assertion

Assert the (numeric) value is < n.

assertion.matches(pattern: string)

Receiver Assertion · Returns Assertion

Assert the (string) value matches the regex pattern.

assertion.not_equals(expected)

Receiver Assertion · Returns Assertion

Assert the value does not equal expected.

assertion.value()

Receiver Assertion · Returns any

The value under assertion, so a verified value can be bound: let id = await_until(|| assert(callee.header("X-Id")).is_present().value());.