Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: name change

...

Warning
titleCompatibility

The contents of this page have not been updated to properly describe the developer interface in version 1.0 of the pico engine.

How to specify tests in the Testing tab

The tests in the Testing tab are generated from information that you, the developer of a ruleset, define in your ruleset. The information must be bound to the name __testing and that name must be shared by a pragma in the meta block of your ruleset. That is, the meta block must specify that the ruleset shares __testing.

...

An event map has keys "domain" and "type" for the domain and type of the event, and if needed, a key "attrs" whose value is an array of attribute names.

Using the Testing tab to experiment with KRL

When you have a question about KRL, you can often set up a quick experiment, using the Testing tab. For example, let's explore the difference between null and the empty string (see also the page of KRL misconceptions and common errors).

...

In order to feed values into the function, we have instrumented the __testing map (which is also shared in line 3) with a couple of queries. The first one (line 8) will exercise the entry function passing it a user-supplied value for the key parameter. The second (line 9) will invoke the function without providing a value for key.

Setting up the experiment

We register this ruleset and install it in the root pico. Now, when selecting the Testing tab for the root pico and clicking the box beside our ruleset identifier, we'll see the simple testing mechanism specified by the __testing map in the test ruleset:

Invoking the function with an empty string

Without entering anything in the box with "key" as the placeholder, click on the the entry link to invoke the function. We'll see the results, showing that the value passed in as key is the empty string, which is not null, nor is it "truthy":

Invoking the function with a null

Next, click on the second entry link (which again invokes the function), and see the result, which is that the value passed in is null (since there wasn't one), which is indeed null, and also not "truthy":

More experiments

We can try passing different string values into the entry function, and in all cases we'll see them echoed, that none of them are null, and that they are all "truthy" (except for the empty string). Some interesting values to try are "0" (did you expect this to be "falsy" (it's not)), "true" and "false" (neither of which is null and both of which are "truthy").

Conclusion

It is very easy to stand up a simple ruleset to check out aspects of KRL which are not clear to you, or for which you cannot find documentation. Once you have learned what you need to know, you can simply discard the ruleset. Share what you have learned with others.

...

Note that the user-supplied values in the __testing UI will always be received as strings, so if you need to work on other data types (numbers, truth values, maps, arrays, etc.) you may want to use the string operator decode(), or some other mechanism.

Adapting the tests in the Testing tab

For some specific uses of a test in the Testing tab, you might feel the need for variations. Some of these can be done by right-clicking on one of the text boxes and clicking "Inspect". Then, some simple edits of the generated HTML can let you adapt a test to your needs.

...

which, after some dragging of the lower-right corner of the textarea box, will look like this.

General notes

Another motivation for changing an input field into a textarea is when you need to paste in a very large string. A 27K string pasted into an input field will not work, but the size limit could be even smaller than that.

In keeping with RESTful principles, each event in the Testing tab is represented by a form using the POST method, while each query are represented by a form using the GET method.

Selecting a channel for a test

By default, each test will run using the pico's private ECI. You may wish to use a particular channel when running a test. To do this, after clicking on the Testing tab, but before opening one of the rulesets, select the desired channel from the dropdown list at the top of the page. To change channels, or if you forgot to select one, simply click on the Testing tab again to get a fresh slate of tests.

...