Chapter 11
[ 293 ]
binding.result = (storeResult || binding.result)
}
binding.and = storeAnd
}
This gives us a very flexible conditional logic that we can include in the DSL, which
is still very legible to a general audience. We can test the effectiveness of this with
a few assertions. The result binding variable is available to the DSL script, so we
can use that to assert that the result is as expected. Next we want try out some of the
ways to use our conditional DSL, but first let's put our DSL into a script that we can
run from the command line.
This script sets up our mini DSL by adding some closure to the binding. It then
invokes the reward script passed to it via the command line. We can test out the
validity of our conditional logic by passing some of the following conditional scripts:
- A reward defined without any conditions should always be true.
reward ( "No conditions" ) {
assert result == true
} - With a single condition, the state of the reward is dictated by that
one condition.
reward ( "One false condition" ) {
condition {
false
}
assert result == false
} - By using allOf and anyOf combined with a condition, we can nest to any
depth without losing legibility.
reward ( "nested anyOf and allOf conditions" ) {
anyOf {
allOf {
condition {
true
}
condition {
false
}
}
condition {
false