> For the complete documentation index, see [llms.txt](https://testbox.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://testbox.ortusbooks.com/digging-deeper/expectations/set-expectations.md).

# 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.

{% hint style="info" %}
These matchers require BoxLang. They are not available on Lucee or Adobe ColdFusion.
{% endhint %}

## Creating Sets

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

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

## Membership And Equality

### `toBeASet()`

Asserts the actual value is a `Set`.

```java
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.

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

## Subsets And Supersets

### `toBeSubsetOf()` / `toBeSupersetOf()`

```java
expect( setOf( "admin" ) ).toBeSubsetOf( setOf( "admin", "editor" ) )
expect( setOf( "admin", "editor" ) ).toBeSupersetOf( setOf( "admin" ) )
```

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.

```java
expect( setOf( "read" ) ).toBeDisjointFrom( setOf( "write", "delete" ) )
```

## Set Algebra

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

### `toHaveUnion()`

```java
expect( setOf( 1 ) ).toHaveUnion( setOf( 2 ), setOf( 1, 2 ) )
```

### `toHaveIntersection()`

```java
expect( setOf( 1, 2 ) ).toHaveIntersection( setOf( 2, 3 ), setOf( 2 ) )
```

### `toHaveDifference()`

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

```java
expect( setOf( 1, 2 ) ).toHaveDifference( setOf( 2 ), setOf( 1 ) )
```

### `toHaveSymmetricDifference()`

Members in either set but not both.

```java
expect( setOf( 1, 2 ) ).toHaveSymmetricDifference( setOf( 2, 3 ), setOf( 1, 3 ) )
```

## Negated Forms

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

## A Real Example

```java
describe( "Menu permissions", function(){

    it( "shows only the menu items the user may reach", function(){
        var visible = menuService.visibleFor( user )
        var granted = setOf( "dashboard", "reports" )

        expect( visible ).toBeASet()
        expect( visible ).toEqualSet( granted )
        expect( visible ).toBeDisjointFrom( setOf( "admin", "billing" ) )
    } )

} )
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://testbox.ortusbooks.com/digging-deeper/expectations/set-expectations.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
