send::
msg ctx.set (d1=now()
)
expect:: (d1 is Date
)
send::
msg ctx.set (d1=(d1 + "1s")
)
expect:: (d1 is Date
)
send::
msg ctx.set (d1=(now() + "1 s")
)
expect:: (d1 is Date
)
send::
msg ctx.set (d1=(d1 + "1 n")
)
expect:: (d1 is Date
)
send::
msg ctx.set (d1=(d1 + "1 m")
)
expect:: (d1 is Date
)
send::
msg ctx.set (d1=(d1 + "1 h")
)
expect:: (d1 is Date
)
send::
msg ctx.set (d1=(d1 + "1 d")
)
expect:: (d1 is Date
)
send::
msg ctx.set (d1=(d1 + "1M")
)
expect:: (d1 is Date
)
send::
msg ctx.set (d1=(d1 + "1 y")
)
expect:: (d1 is Date
)
ctx.set
is used to set one or more variables in the current context:
send::
msg ctx.set (res="123"
="123"
)
expect:: (res is "123"
)
ctx.setVal
is useful if the name is itself sourced, a variable:
send::
msg ctx.setVal (name="res"
="res"
, value:Number="321"
=321
)
expect:: (res is 321
)
expect:: (res is number
)
ctx.echo
shows all the details about the input arguments - use it to see types, values etc:
send::
msg ctx.echo (res12="123"
="123"
)
expect:: (res12 is "123"
)
Contains:
send::
msg ctx.set (res23="123"
="123"
)
expect:: (res23 contains "2"
)
expect:: (res23 containsNot "4"
)
send::
msg ctx.base64encode (res29="res29"
="res29"
)
expect:: (payload is "cmVzMjk="
)
send::
msg ctx.base64decode (res29=payload
)
expect:: ( ((payload as string) is "res29")
)
send::
msg ctx.sha1 (res35="res35"
="res35"
)
expect:: (payload is "7D509433920201DF3A7EE4363970D83359D826B8"
)
expect:: (res35_sha1 is "7D509433920201DF3A7EE4363970D83359D826B8"
)
send::
msg ctx.sha256 (res35="res35"
="res35"
)
expect:: (payload is "2e994a1eb4aea52f7c059c6b82f05f14777575371f3acf833ef72fb7e294ac71"
)
expect:: (res35_sha256 is "2e994a1eb4aea52f7c059c6b82f05f14777575371f3acf833ef72fb7e294ac71"
)
This will remove a value from the context:
send::
msg ctx.setVal (name="res"
="res"
)
expect:: (res not defined
)
Reset the entire context, with ctx.clear
:
send::
msg ctx.setVal (name="res"
="res"
, value:Number="321"
=321
)
expect:: (res is 321
)
send::
msg ctx.clear
expect:: (res not defined
)
Examples of constants of different types:
send::
msg ctx.set (res:Number="45"
=45
)
expect:: (res is 45
)
expect:: (res is number
)
send::
msg ctx.set (res="astra"
="astra"
)
expect:: (res is "astra"
)
expect:: (res is string
)
String interpolation and escaping of such
send::
msg ctx.set (interpol="x"
="x"
)
send::
msg ctx.set (int1="${interpol}"
)
expect:: (int1 contains "x"
)
send::
msg ctx.set (int1="a${interpol}b"
)
expect:: (int1 contains "x"
)
send::
msg ctx.set (int1="$${interpol}"
)
expect:: (int1 containsNot "x"
)
send::
msg ctx.set (int1="a$${interpol}b"
)
expect:: (int1 containsNot "x"
)
The usual simple expressions are available and they are type aware:
send::
msg ctx.set (ai:Number="1"
=1
, bi:Number="2"
=2
)
send::
msg ctx.set (as="1"
="1"
, bs="2"
="2"
)
send::
msg ctx.set (res53=(ai + bi)
)
expect:: (res53 is 3
)
send::
msg ctx.set (res56=(as + bs)
)
expect:: (res56 is "12"
)
send::
msg ctx.set (res52:Number=(((1 - 2) + (3 * 4)) + 9)
)
expect:: (res52 is 20
)
send::
msg ctx.set (res57="1
2
3
"
="1
2
3
"
)
expect:: (res57:Array)
expect:: (res57[="length"] is 6
)
expect:: ( ((res57[="length"] + 5) is 11)
)
expect:: ( ((sizeOf(res57.lines) + 4) is 7)
)
send::
msg ctx.set (l66=res57[="lines"]
)
By default all strings are templatized in expressions, using ${...}
to match a simpler expression:
send::
msg ctx.setVal (name="template1"
="template1"
, value="is${1+2}"
)
expect:: (template1 is "is3"
)
Use this to configure environment settings like URLs for instance
send::
msg ctx.set (HOST ="https://www.google.c"
...="https://www.google.ca"
)
send::
msg ctx.echo (url="${HOST}/search?q=dieselapps"
)
expect:: (url is "https://www.google.ca/search?q=dieselapps"
)
expect:: ( ("${HOST}/" is "https://www.google.ca/")
)
These are not used:
send::
msg ctx.set (a:Number="1"
=1
, b:Number="2"
=2
)
The input parameters overwrite context above
send::
msg expr.js.sum1 (a:Number="1"
=1
, b:Number="2"
=2
)
expect:: (res39 is 3
)
send::
msg expr.js.sum2 (a:Number="1"
=1
, b:Number="2"
=2
)
expect:: (res42 is 3.0
)
send::
msg expr.js.name1 (email="jane@doe.com"
="jane@doe.com"
)
expect:: (res40 is "jane"
)
/$send ctx.setVal (name="cart", value={})
send::
msg expr.js.validateEmail (email="jane@doe.com"
="jane@doe.com"
)
expect:: (ok25 is true
)
send::
msg ctx.set (ok25:Boolean=false
)
send::
msg expr.js.validateEmail (email="janedoe.com"
="janedoe.com"
)
expect:: (ok25 is false
)
send::
msg expr.source.erase
expect:: (erased not defined
)
send::
msg ctx.set (val192=""
)
expect:: (val192 is defined
)
expect:: (val192 not undefined
)
expect:: (val192 is empty
)
expect:: (val192 not nzlen
)
send::
msg ctx.set (val198:Undefined=null)
expect:: (val198 not defined
)
expect:: (val198 is undefined
)
expect:: (val198 is empty
)
expect:: (val198 not nzlen
)
send::
msg ctx.set (val204="abcd"
="abcd"
)
expect:: (val204 is defined
)
expect:: (val204 not undefined
)
expect:: (val204 not empty
)
expect:: (val204 is nzlen
)
send::
msg ctx.set (res5=js{{ diesel.engineId() }}
)
expect:: (res5 not empty
)
send::
msg ctx.set (res139=js{{ diesel.env() }}
)
expect:: (res139 not empty
)
send::
msg ctx.set (res144=js{{ wix.diesel.env }}
)
expect:: (res144 not empty
)
send::
msg ctx.set (b1:Boolean=true
)
expect:: (b1 is true
)
expect:: (b1 not false
)
expect:: (b1)
expect:: (b1)$ifc::true
expect:: (b1)$ifc::b1
expect:: (b1)$ifc::(b1 is true)
expect:: (b1)$ifc::(b1 not false)
send::
msg expr.bool.test1
expect:: (b2)
expect:: (b3 is true
)
expect:: (b4)
expect:: (b5 not defined
)
send::
msg expr.bool.test1nos
expect:: (b2n)
expect:: (b3n is true
)
expect:: (b4n)
expect:: (b5n not defined
)
send::
msg expr.bool.test2 (a:Number="1"
=1
, b:Number="2"
=2
)
expect:: (b23)
expect:: (b26)
send::
msg expr.bool.test2 (a:Number="2"
=2
, b:Number="1"
=1
)
expect:: (b22)
expect:: (b25)
send::
msg expr.bool.test2 (a:Number="2"
=2
, b:Number="2"
=2
)
expect:: (b24)
expect:: (b25)
expect:: (b26)
send::
msg expr.bool.testAllExpr (a:Number="1"
=1
, bb:Number="2"
=2
)
expect:: (b > 23
)
send::
msg expr.bool.testContains (a="123"
="123"
)
expect:: (b94 is true
)
expect:: (b95 is true
)
send::
msg expr.bool.testAndUndef
expect:: (b47 not defined
)
expect:: (b48 is true
)
expect:: (b49 not defined
)
expect:: (b50 not defined
)
expect:: (b51 is true
)
send::
msg expr.bool.testBra1
expect:: (bb105 is true
)
Range accessor on Strings
send::
msg ctx.set (l3="012345"
="012345"
)
send::
msg ctx.set (l4=l3[:Range=0..None]
)
expect:: (l4 is "012345"
)
send::
msg ctx.set (l8=l3[:Range=0..Some(3)]
)
expect:: (l8 is "0123"
)
send::
msg ctx.set (l11=l3[:Range=0..Some(-1)]
)
expect:: (l11 is "01234"
)
send::
msg ctx.set (l14=l3[:Range=-2..Some(-1)]
)
expect:: (l14 is "34"
)
send::
msg ctx.set (l14=l3[:Range=-1..None]
)
expect:: (l14 is "4"
)
Range accessor on Lists
send::
msg ctx.set (l21:Array=[0,1,2,3,4,5]
)
send::
msg ctx.set (l4=l21[:Range=0..None]
)
expect:: (l4 is [0,1,2,3,4,5]
)
send::
msg ctx.set (l8=l21[:Range=0..Some(3)]
)
expect:: (l8 is [0,1,2,3]
)
send::
msg ctx.echo (l11=l21[:Range=0..Some(-1)]
)
expect:: (l11 is [0,1,2,3,4]
)
send::
msg ctx.set (l239:Array=[]
)
expect:: (l239 is []
)
Accessor in pmatch /expect
send::
msg ctx.set (l14=l21[:Range=-2..Some(-1)]
)
expect:: (l14[="1"=1] is 4
)
send::
msg ctx.set (state281:JSON={source:[0,1,2,3,4,5],dest:[],aux:[]}
)
expect:: (state281[="source"="source"][="0"=0] == 0
)
send::
msg ctx.set (state281:JSON={source:[0,1,2,3,4,5],dest:[],aux:[]}
)
expect:: (state281[="source"="source"][="0"=0] is 0
)
send::
msg test.ctxAccessor
expect:: (payload is ( (90 + 87) )
)
json in context and array sum
send::
msg ctx.set (state294:JSON={source:[0,1,2,3,4,5],dest:[],aux:[]}
)
send::
msg test.jsonAccessorSet (source="source"
="source"
, dest="dest"
="dest"
, aux="aux"
="aux"
)
expect:: (state294[="source"] is [1,2,3,4,5]
)
expect:: (state294[="dest"] is [0]
)
val a217="a217v"
="a217v"
send::
msg ctx.set (a218="${a217}"
)
expect:: (a218 is "a217v"
)
send::
msg expr.captureGroups (path="/getAccount1/67"
="/getAccount1/67"
)
expect:: (payload[="accountId"] is "67"
)
send::
msg ctx.set (payload="/getAccount1/99"
="/getAccount1/99"
)
send::
msg ctx.regex (regex ="/getAccount1/(?<acct"
...="/getAccount1/(?<acctId3>\d+)"
)
expect:: (acctId3 is "99"
)
Don't overwrite payload:
send::
msg ctx.set (payload="pa"
="pa"
)
send::
msg ctx.regex (regex ="/getAccount1/(?<acct"
...="/getAccount1/(?<acctId4>\d+)"
, payload="/getAccount1/999"
="/getAccount1/999"
)
expect:: (acctId4 is "999"
)
expect:: (payload is "pa"
)
Simple javascript - script is independent (no arguments):
send::
msg ctx.set (a225=js{{ 1+4 }}
)
expect:: (a225 is 5
)
Escaping quotes with javascript regex (notice a230 available inside the js expression):
val a230="{"a":32}"
="{"a":32}"
send::
msg ctx.set (a231=js{{ a230.replace(/"/g, "\"") }}
)
expect:: (a231 is "{"a":32}"
)
More JS examples:
send::
msg ctx.set (now=js{{ java.lang.System.currentTimeMillis() }}
)
// $send ctx.set(
// later=js:{var d = new Date(); d.setSeconds(d.getSeconds() + 10); return d.toISOString();}
// )
send::
msg ctx.set (later=js{{ var d = new Date(); d.setSeconds(d.getSeconds() + 10); d.toISOString(); }}
)
send::
msg ctx.set (noweh=js{{ var d = new Date(); d.toISOString(); }}
, later=js{{ var d = new Date(); d.setSeconds(d.getSeconds() + 10); d.toISOString(); }}
)
send::
msg ctx.set (a=(("1234" + "5") as Number)
)
expect:: (a is 12345
)
val p15="p15"
="p15"
val p16=(("p16-" + p15) as "application/pdf")
send::
msg ctx.echo (a=p16
)
expect:: ( (typeOf(p16) is "application/pdf")
)
expect:: (p16 is "p16-p15"
)
as a variable
val p366="Number"
="Number"
send::
msg ctx.set (a=(("1234" + "5") as p366)
)
expect:: (a is 12345
)
send::
msg ctx.set (a:Array=([1,2,3] filter ( x=>(x > 1)() ))
)
expect:: (a is [2,3]
)
send::
msg ctx.set (a278:Array=([1,2,3] map ( x=>(x + 1)() ))
)
expect:: (a278 is [2,3,4]
)
Both filter and map
send::
msg ctx.set (a281:Array=(([1,2,3] filter ( x=>(x > 1)() )) map ( x=>(x + 1)() ))
)
expect:: (a281 is [3,4]
)
send::
msg ctx.set (a284:Array=((([1,2] + [3]) filter ( x=>(x > 1)() )) map ( x=>(x + 1)() ))
)
expect:: (a284 is [3,4]
)
send::
msg ctx.set (a287:Array=(([1,2,3] filter ( x=>((((x - (1 * 1)) + 1) > 1) or (2 > 4))() )) map ( x=>(x + 1)() ))
)
expect:: (a287 is [3,4]
)
Convert to string and use a JS expression for filter lambda
send::
msg ctx.set (a298:Array=(([1,2,3] filter ( x=>(x > 1)() )) map ( x=>(x + "")() ))
)
send::
msg ctx.echo (res299=(res57[="lines"] filter e=>js{{ !a298.contains(e) }}())
)
expect:: (res299 is ["1"]
)
send::
msg expr.oper.sumnum (a:Number="1"
=1
, b:Number="2"
=2
)
expect:: (res is 3
)
send::
msg expr.oper.sumnum2 (a:Number="1"
=1
)
expect:: (res is 3
)
send::
msg expr.oper.sumnum3 (a:Number="1"
=1
)
expect:: (res is 3
)
send::
msg expr.oper.sumstr (first="Jane"
="Jane"
, last="Doe"
="Doe"
)
expect:: (res is "Jane Doe"
)
send::
msg ctx.set (a358:Array=[1,2,3]
)
send::
msg ctx.echo (x=sizeOf(a358)
)
expect:: ( (sizeOf(a358) > 0)
)
send::
msg test.diesel.condif
expect:: (b138 is true
)
Just making sure this parsed:
send::
msg dieseltest.expr151 (env:Number="123"
=123
)
expect:: (res151 >= 1
)
send::
msg testdiesel.bug.overwritectxname (payload="a"
="a"
, a="a"
="a"
)
expect:: (payload is "z"
)
send::
msg testdiesel.bug.overwritectxname (payload="a"
="a"
, a="a"
="a"
)
expect:: (payload is "z"
)
This was an issue - setting and then expanding in a submessage bug
send::
msg test.diesel.testSetExpand
expect:: (yy is "123"
)
0 $mock::
test.diesel.testSetExpand
ctx.set (YY="123"
="123"
)
ctx.set (yy="${YY}"
)
diesel.step (desc =""should have expande"
...="should have expanded by now - running a js regex to mess it up if not expanded"
)
diesel.step (desc =""otherwise the expec"
...="otherwise the expect will evaluate it and it works..."
)
. (yy
=js{{ yy.replace(/$/g, "xx") }}
)
val x477:Array=[]
send::
msg ctx.echo (x472=accessor(obj=x477[="0"=0],accessor:String="a.b.c"="a.b.c")
)
expect:: (x472 is undefined
)
send::
msg testdiesel.lastline
expect:: (payload contains "end of line is parsed here..."
)
MAKE SURE THERE IS NO \n after this line
0 $mock::
testdiesel.lastline
. (payload
="end of line is parsed here..."
)
val query:JSON={key:"elf"}
send::
msg ctx.set (y=(query map ( x=>(((x[="key"] + ":"") + x[="value"]) + """)() ))
)
send::
msg ctx.echo (x=(y mkString " AND ")
)
expect:: (x contains "elf"
)