For the complete documentation index, see llms.txt. This page is also available as Markdown.

Range Expectations

Matchers for BoxLang Range objects

BoxLang has a native Range type covering containment, ordering, bounds, stepping and clamping. TestBox 7.1 adds matchers that assert against ranges directly instead of picking them apart into endpoints first.

These matchers require BoxLang. On CFML engines they are guarded and report unsupported behavior cleanly rather than erroring.

Creating Ranges

Ranges are built with the .. operator and stepped with .step( n ). There is no rangeNew() built-in.

var base    = 1..10
var stepped = ( 0..100 ).step( 5 )
var chars   = "a".."z"
var dates   = createDate( 2024, 1, 1 )..createDate( 2024, 1, 31 )

var openEnd   = 1..     // half bounded
var openStart = ..10    // half bounded
var open      = ..      // unbounded

Containment

toBeRange()

expect( 1..10 ).toBeRange()

toContainValue()

Asserts a value falls inside the range.

toContainRange()

Asserts an entire range fits inside another.

toBeInRange()

The inverse reading of toContainValue(), with the value as the subject. Use whichever makes the sentence read better.

toBeBeforeRange() / toBeAfterRange()

Shape And Direction

toBeBounded(), toBeUnbounded(), toBeHalfBounded()

toBeIterable()

A range is iterable when it can actually be walked, which an unbounded range cannot.

toBeAscending() / toBeDescending()

Step And Clamp

toHaveStep()

toClampTo()

Asserts what the range clamps a given value to. Takes the input value and the expected clamped result.

Native Equivalents

These matchers sit on top of the native Range API, so the following are equivalent to the assertions above:

A Real Example

Last updated

Was this helpful?