# Testing Airscript Expressions

When working with Airscript, it's often advantageous to test an Airscript expression before implementing it. This is especially true if the Airscript expressions are long and complicated, or the output of the expression won't appear in the Stage of the Web Flows Builder (which occurs if the Airscript expression is part of a conditional or if the Airscript expression requires user input in order to resolve). In this document, we'll walk through a way to test Airscript expressions and immediately see if they return the expected results.

Testing Airscript expressions requires accessing to the [Airkit Studio](../studio/studio). It doesn't matter what application you have open within it: you can set up your tests directly inside of whatever large application you're working in, or you can create a new app entirely for testing purposes.

This article covers _how_ to test, not _what_ to test. For a deeper discussion into the syntax of Airscript expressions, check out the [Airscript Quickstart](airscript-quick-start).

#### Setting up a designated Data Flow to test Airscript Expressions

1. Toggle over to the [Connections Builder](../studio/builder-bar/connections-builder) by clicking on the associated button within the [Builder Bar](../studio/builder-bar):

![connection builder](https://2093598723-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC2DgLBPTrwoEhWaU24LL%2Fuploads%2Fgit-blob-1bd546aa967cd7a5ee99d57f9e83b62a394b4adb%2Ftesting-airscript-expressions-v180-0.png?alt=media)

2. Create a new [Data Flow](../studio/data-flows) by clicking the '+' icon to the right of **Data Flows** in the Tree:

![new data flow](https://2093598723-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC2DgLBPTrwoEhWaU24LL%2Fuploads%2Fgit-blob-f91332e2bae2de4a68a5034e639150f3ae70dbd7%2Ftesting-airscript-expressions-v180-1.png?alt=media)

3. Click **Create Blank** from the pop-up window that appears:

![create blank](https://2093598723-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC2DgLBPTrwoEhWaU24LL%2Fuploads%2Fgit-blob-af8b009743254b685ee71c99fe5595e6826b99ba%2Ftesting-airscript-expressions-v180-2.png?alt=media)

This will create a new, blank Data Flow.

4. Double-click on the new Data Flow within the Tree and name this new Data Flow "Airscript Testing":

![create blank](https://2093598723-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC2DgLBPTrwoEhWaU24LL%2Fuploads%2Fgit-blob-436983ea1aec07e0f6c956fd79a4c0814713d855%2Ftesting-airscript-expressions-v180-3.png?alt=media)

5. Click on the '+' button between the **Start** and **End** boxes in the Stage:

![](https://2093598723-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC2DgLBPTrwoEhWaU24LL%2Fuploads%2Fgit-blob-0051a36d6fca946058942710e12994f8960bd4a3%2Ftesting-airscript-expressions-v180-4.png?alt=media)

6. Select **Transform** from the pop-up window that appears:

![](https://2093598723-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC2DgLBPTrwoEhWaU24LL%2Fuploads%2Fgit-blob-31fecd802d3b5040cf1e6fc70c0343a153b78400%2Ftesting-airscript-expressions-v180-5.png?alt=media)

7. A [Transform Data Operation](../data-operations/the-transform-data-operation) will appear between the **Start** and **End** boxes in the Stage. Enter the Airscript expression you mean to test under **Transform Expression**. For example, to examine what is returned by the [NOW](../airscript-expressions/datetime-functions/now) function, it should look like this:

![create blank](https://2093598723-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC2DgLBPTrwoEhWaU24LL%2Fuploads%2Fgit-blob-f829807d15fde9600a81917922c1714a707bb21a%2Ftesting-airscript-expressions-v180-6.png?alt=media)

8. Press the **Run** button Under the **Run Results** section of the Transform Data Operation. This will run the Airscript expression entered above and return the output of the expression:

![create blank](https://2093598723-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC2DgLBPTrwoEhWaU24LL%2Fuploads%2Fgit-blob-99cd56a6c6176474332355c8d20115f102cab51d%2Ftesting-airscript-expressions-v180-7.gif?alt=media)

(Note that the output of the [NOW](../airscript-expressions/datetime-functions/now) function is a [DateTime](../airscript-expressions/datetime-functions/datetime).)

Any number of changes can be made to the Airkit expression under **Transform Expression**, and the Transform Data Operation can be run each time a change is made, to confirm that the changes to the Airscript expression resulted in the desired changes in behavior. All future testing of Airscript expressions can be done in this Transform Data Operation, within the Data Flow designated "Airscript Testing".&#x20;

#### Feeding input into an Airscript Expression

The [NOW](../airscript-expressions/datetime-functions/now) function does not require any input in order to run successfully, but many Airscript expressions do. There are two main ways to feed input into an Airscript expression: hardcoding, or calling on variables defined at the **Start** of the Data Flow. Any combination of these two options can be used if an expression requires multiple input parameters.

**Hardcoding**

Airscript expressions can be tested by directly hardcoding the desired input into the expression. For instance, to use the [ISODD](../airscript-expressions/math-functions/isodd) function to test if the number 2 is odd, you could directly enter the expression:

```javascript
ISODD(2)
```

Inside of the Transform Data Operation, this would appear as follows. Note that at the time this screenshot was taken, the expression was run, returning the output **FALSE**, as 2 is not an odd number.

![](https://a01-support.airkit.com/testing-airscript-expressions/2021-11-23_13-13-39.png)

&#x20;

Most Airscript expressions expect input of a certain [data type](../variable-data-types/data-types-overview). All data types can be hardcoded, though some require particular signifiers to be Airscript-parsable. [Text](../variable-data-types/the-text-variable-data-type), for instance, must be designated by surrounding the relevant string with quotation marks. For a deeper dive into the different data types Airscript recognizes, check out the [Data Types Overview](../variable-data-types/data-types-overview).

**Calling on variables**

The Transform Data Operation has access to all variables defined as part of the Airscript Testing Data Flow. When a Data Flow is first created, this section is blank, but new inputs can be defined in the Inspector, under the **Start** section. A Data Flow can keep track of arbitrarily many variables.&#x20;

Click on the '+' icon to the right of **Inputs** to define a new variable:

![](https://a01-support.airkit.com/testing-airscript-expressions/2021-11-23_13-15-08.png)

Upon clicking on the '+', a pop-up window will appear. Select the [Data Type](../variable-data-types/data-types-overview) of the variable you mean to use as input when testing your Airscript expression:&#x20;

![create blank](https://a01-support.airkit.com/testing-airscript-expressions/2021-11-23_13-16-38.png)

After defining selecting a variable type, give that variable a name by entering it in the text box that appears to the immediate right of the data type icon. This name will define how the variable will be designated when called upon by a downstream Airscript expression.

The following example shows two variables, a DateTime called `example_datetime` and a Number called `example_number`:

![](https://a01-support.airkit.com/testing-airscript-expressions/2021-11-23_13-19-01.png)

Upon their creation, variables defined in a Data Flow will be automatically populated with dummy data of the correct type. This dummy data can be both examined and edited in the **Start** box. Select which variable you want to examine at any given time by clicking on the variable names at the top of the **Start** box:

![](https://a01-support.airkit.com/testing-airscript-expressions/2021-11-24_11-58-45.png)

When the Transform Data Operation is run, it will reference the dummy values defined in the **Start** box whenever the variable is called upon.

These variables can now be called on within the Airscript expression in the downstream Transform Data Operation.

As an example, consider testing the function [ADD\_TO\_DATETIME](../airscript-expressions/datetime-functions/add_to_datetime). This function requires a DateTime, a Number, and a string. The following expression uses the value of `example_datetime` as the DateTime, the value of `example_number` as the Number, and hardcodes the string "hour" as the value for the string. (Remember: any combination of these hardcoded and variable parameters can be used if an expression requires multiple input parameters.)

```javascript
ADD_TO_DATETIME(example_datetime, example_number, "hour")
```

Running this within the Transform Data Operation yields the following results:

![](https://2093598723-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC2DgLBPTrwoEhWaU24LL%2Fuploads%2Fgit-blob-6526510aa552cee8d0725a63a3e70be95e572b4e%2Ftesting-airscript-expressions-v180-8.png?alt=media)

Note that this returns a DateTime that looks nearly identical to the value of `example_datetime` shown above, but that the hour attribute has increased by 1 – that is, it increased by the value of `example_number`.

Changing the dummy values defined in the **Start** box and then running the Transform Data Operation again will return results that reflect the changes made. This makes it easy to test how Airscript expressions behave when given different values as input.

For more on defining variables in Data Flows, check out [this article](../studio/data-flows) on the structure of Data Flows.

#### Applying your tests

Airscript expressions can be used in a wide variety of places within your Airkit Application. Whenever a text box contains the ![](https://2093598723-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC2DgLBPTrwoEhWaU24LL%2Fuploads%2Fgit-blob-2e9b9c97002f3159f28c98b5f64fffda5b52e5e8%2Ftesting-airscript-expressions-v180-9.png?alt=media) icon on the bottom right, that means that entered values will be parsed as Airscript by default.

In the case of [Labels](../web-controls/label-web-control), Airscript expressions can also be inserted into a string by applying double curly brackets around them. For instance, given some `example_expression` that returns [Text](../variable-data-types/the-text-variable-data-type), the output of the expression can be displayed seamlessly within the existing string:

```javascript
"The output of the Airscript expression is {{example_expression}}"
```

If, say, the value of `example_expression` is "Hello, World", then this Label will display the text: "The output of the Airscript expression is Hello, World".
