Contains test
Learn how to check if a collection contains a certain element.
This test checks whether a collection contains a certain element. It works the same way as the in test, but with the operands reversed.
You can use any collection type, including lists and maps. Keys are ignored when checking whether a map contains an element.
When comparing elements, this test uses the same equivalence rules as the equal operation to ensure consistency in how it determines whether two items are equal.
Syntax
This test has the following syntax:
/*<collection>*/ contains /*<element>*/
You can alternatively use the following syntax:
/*<collection>*/ includes /*<element>*/
Both forms have the same semantics. You can use whichever makes your query more expressive and easier to read.
You can negate the test to verify the contrary:
/*<collection>*/ does not contain /*<element>*/
The same applies to the alternative syntax:
/*<collection>*/ does not include /*<element>*/
Parameters
These are the supported parameters:
- collection
The collection to check.
- elementany
The element to search for in the collection.
Examples
Here is a simple example that checks whether a list contains a certain element:
["a", "b", "c"] contains "b" // true
To negate the test, you can write:
["a", "b", "c"] does not contain "b" // false