-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Recently a new validator was written: here is how it works.
validate
is either a single element or an array of either string
or object
If an element is a string it'll be considered a regex, if it's an object it'll be validated depending on the type. For the moment we only have type: fn
which will contain a function
which can receive a string representing the line that it's validating.
**NOTE ** The prefix @@
tells the validator that it has to escape the string to be a RegExp
.
You might want to use @@
when validating against something like @@mosquito = (x,y) ->
If the array contains more than one element, the validator will check more than 1 line.
"steps": [
{
"validate": "^for *"
},
{
"validate": [
{
"type": "function",
"fn" : "function (str) {return str.length===3;}"
}
]
},
{
"validate": [
"color white",
{
"type": "function",
"fn" : "function (str) {return str.length===3;}"
}
]
},
]
#Examples By starting to play with Regular Expressions one can make the validation a bit smarter: optional spaces, escaped characters etc.
A good site to play with RegExes is https://regex101.com/
Optional space needs a *
*
{
"hint": "Move down by 100 - **type** `move 0, 100`",
"solution": "move 0, 100",
"validate": "^move 0, *100$"
}
{
"hint": "Draw the knot - **type** `polygon 15, 15, -15, 15`",
"solution": "polygon 15, 15, -15, 15",
"validate": "^polygon 15, *15, *\\-15, *15$"
}
{
"hint": "Now open a loop - **type** `for x in [ 0 .. 25 ]`",
"solution": "for x in [ 0 .. 25 ]",
"validate": "for x in \\[ *0 *\\.\\. *25 *\\ *]"
},
{
"hint": "Inside this loop, open a second loop - **type** `for y in [ 0 .. 25 ]`",
"solution": " for y in [ 0 .. 25 ]",
"validate": "^ for y in \\[ *0 *\\.\\. *25 *\\]$"
},
{
"hint": "Move around, **type** `moveTo x * 20, y * 20`",
"solution": " moveTo x * 20, y * 20",
"validate": "^ moveTo x *\\* *20, *y *\\* *20$"
},
{
"hint": "Now for the dots - **type** `circle 6`",
"solution": " circle 6",
"validate": "^ circle 6$"
}