Other tests
Explore the other tests available in CQL.
Tests are natural language conditions that you can use to check whether a value meets certain criteria.
Typically, they are categorized by the data type they operate on. However, some tests are not specific to a particular data type or category, as is the case with the tests described in this section.
The following table summarizes these other tests for quick reference:
Defined
This test checks whether the value of an operand is defined.
An operand is considered defined when it can be resolved to a value, meaning it is not null or undefined. If an operand throws an error, it is considered undefined. For example, if you try to access a property that does not exist, such as a query parameter that does not exist in the current URL, the result is false, not an error.
This test does not check if the value is empty, only if it is defined. For empty checks, use the empty test instead.
Syntax
This test has the following syntax:
/*<value>*/ is defined
You can alternatively use the following syntax:
/*<value>*/ is known
Both forms have the same semantics. You can use whichever makes your query more expressive and easier to read.
To negate the test, use the following syntax:
/*<value>*/ is not defined
Parameters
These are the supported parameters:
- valueany
The value to validate.
Examples
Here is a practical example of the defined test:
page's query's code is defined
The above expression returns true if the current page URL contains a query parameter named code, regardless of its value.
You can also use the alternative syntax to achieve the same result:
page's query's code is known
Empty
This test checks whether a value is empty.
An operand is considered empty if it is null, an empty string, or a collection with no elements. Anything else is considered not empty.
Syntax
This test has the following syntax:
/*<value>*/ is empty
To negate the test, use the following syntax:
/*<value>*/ is not empty
Parameters
These are the supported parameters:
- valueany
The value to validate.
Examples
Here is an example of how to check if a string is empty:
"Hello, world!" is empty // false
And this is how you can check if a collection is empty:
[] is empty // true