A First Fandango Spec#
To create test inputs, Fandango needs a Fandango spec – a file that describes how the input should be structured.
A Fandango specification contains three types of elements:
A grammar describing the syntax of the inputs to be generated;
Optionally, constraints that specify additional properties; and
Optionally, definitions of functions and constants within these constraints.
Only the first of these (the grammar) is actually required. Here is a very simple Fandango grammar that will get us started:
<start> ::= <digit>+
<digit> ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
This grammar defines a sequence of digits:
The first line in our grammar defines
<start>
– this is the input to be generated.What is
<start>
? This comes on the right-hand side of the “define” operator (::=
).We see that
<start>
is defined as<digit>+
, which means a non-empty sequence of<digit>
symbols.
What is a
<digit>
? This is defined in the next line: one of ten alternative strings, separated by|
, each representing a single digit.
To produce inputs from the grammar, Fandango
starts with the start symbol (
<start>
)repeatedly replaces symbols (in
<...>
) by one of their definitions (= one of the alternatives separated by|
) on the right-hand side;until no symbols are left.
So,
<start>
first becomes<digit><digit><digit>...
(any number of digits, but at least one);each
<digit>
becomes a digit from zero to nine;and in the end, we get a string such as
8347
,66
,2
, or others.
Let us try this right away by invoking Fandango.