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:

TestDescription
DefinedChecks whether a value is defined.
EmptyChecks whether a value is empty.

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.

Croct's mascot neutral
Defined values may still be empty

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
Try in Playground

You can alternatively use the following syntax:

/*<value>*/ is known
Try in Playground

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
Try in Playground

Parameters

These are the supported parameters:

value
any

The value to validate.

Examples

Here is a practical example of the defined test:

page's query's code is defined
Try in Playground

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
Try in Playground

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
Try in Playground

To negate the test, use the following syntax:

/*<value>*/ is not empty
Try in Playground

Parameters

These are the supported parameters:

value
any

The value to validate.

Examples

Here is an example of how to check if a string is empty:

"Hello, world!" is empty // false
Try in Playground

And this is how you can check if a collection is empty:

[] is empty // true
Try in Playground