Expression syntax

The syntax described here can be applied to assert.expression and setvar.expression keys as well as to the when clause (click here for info about the when clause).

Expressions are strings that can contain scalar values (int, float, string, bool), standard operators and variables. Variable names are not surrounded by a ${...}, they are named as is.

The evaluation of the expression must return an int, a string or a bool (floats are converted to ints).

The supported operators are described here: https://github.com/Knetic/govaluate/blob/master/MANUAL.md

Syntactic rules:

  • allowed types are: float64, int, bool, string and arrays
  • strings that matches date format are converted into a float64
  • + operator can be used with numbers and string (concatenation)
  • -, *, /, ** and % only work with numbers
  • >>, <<, |, & and ^ use int64 (float64 will be converted)
  • - as unary operator works with numbers
  • ! works with bool
  • ~ (bitwise not) works with numbers
  • ||, && work with bool
  • ? (ternary true) uses a bool, any type and returns the 3rd op or nil
  • : (ternary false) uses any type, any type and returns the 3rd op or nil
  • ?? (null coalescence) returns the left-side if non-nil otherwise returns the right-side
  • >, <, >=, <= are comparators, both ops must have the same type (number or string)
  • =~, !~ are used for regexp matching, both ops are strings
The supported functions are:

  • strlen(string)
  • substr(string, start, end)
  • random(start, end) which returns an integer between start and end, included
Examples:

  expression: "var1 + 3 > 4 * var2"
  expression: "strlen(var3) > 0"
  expression: "random(1990, 2020)"