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

Set Expectations

Matchers for BoxLang Set objects

BoxLang ships a native Set type. Asserting against one with array matchers means sorting first and hoping the ordering is stable, which obscures what the test actually means. TestBox 7.1 adds a family of matchers that speak set semantics directly.

These matchers require BoxLang. They are not available on Lucee or Adobe ColdFusion.

Creating Sets

Use the setOf() built-in to build a set inline:

var roles = setOf( "admin", "editor", "viewer" )

Membership And Equality

toBeASet()

Asserts the actual value is a Set.

expect( setOf( 1, 2 ) ).toBeASet()
expect( [ 1, 2 ] ).notToBeASet()

toEqualSet()

Asserts two sets contain the same members. Order is irrelevant, which is the whole point of a set.

expect( setOf( 1, 2 ) ).toEqualSet( setOf( 2, 1 ) )

Subsets And Supersets

toBeSubsetOf() / toBeSupersetOf()

Use these for permission checks, where the assertion is "the granted roles include at least these" rather than an exact match.

toBeDisjointFrom()

Asserts the two sets share no members at all.

Set Algebra

Each of these takes the other operand and the expected result.

toHaveUnion()

toHaveIntersection()

toHaveDifference()

Members in the actual set that are not in the other set.

toHaveSymmetricDifference()

Members in either set but not both.

Negated Forms

Every matcher here has a negated counterpart: notToBeASet(), notToEqualSet(), notToBeSubsetOf(), notToBeSupersetOf(), notToHaveUnion(), notToHaveIntersection(), notToHaveDifference() and notToHaveSymmetricDifference().

A Real Example

Last updated

Was this helpful?