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.
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 = .. // unboundedContainment
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?