Testing built-in messages and executors
diesel.env
will be overwritten in the current context
msg ctx.echo (e)
expect:: (e not empty
)
"testing"
)"testing"
)"local"
)send::
msg testdiesel.setlocal (env="local"
)
0 $mock::
testdiesel.setlocal (env)
. (ctx[="diesel"][="env"]
=env
)
msg ctx.echo (ha="haha"
)
expect:: (ha == "haha"
)
send::
msg ctx.echo (x:Number=1
)
// $when diesel.before // => ctx.set(DONE_BEFORE="diesel.before yeah") // $send ctx.echo(msg = DONE_BEFORE) // $expect (DONE_BEFORE contains "diesel.before yeah")
send::
msg dieseltest.rule1 (a:Number=79
, b="b"
)
expect:: (rule1ab is "79b"
)
expect:: (rule1abc is undefined
)
expect:: (rule1abd is undefined
)
send::
msg dieseltest.rule1 (a:Number=85
, b="b"
, c="cc"
)
expect:: (rule1ab is "85b"
)
expect:: (rule1abc is "85bcc"
)
expect:: (rule1abd is undefined
)
expect:: (c is "oops"
)
send::
msg aha.haha.sendtest
expect:: (rule12 is true
)
send::
msg dieseltestsendtest.aha
expect:: (rule16 is true
)
send::
msg dieseltest.send.multiple.aha
expect:: (rule18 is true
)
expect:: (rule18a not defined
)
send::
msg dieseltestMM.send.multiple.aha
expect:: (rule19a is true
)
send::
msg dieseltestJhaha.sendtest18
expect:: (rule19 not defined
)
send::
msg dieseltestJ.haha.sendtest18
expect:: (rule19 is true
)
send::
msg dieseltest.opt1 (b="2"
)
expect:: (rule61 is "2"
)
send::
msg dieseltest.opt2 (b="2"
)
expect:: (rule64 is "12"
)
send::
msg dieseltest.comment1
expect:: (rule22 is 22
)
send::
msg dieseltest.engmsg25
expect:: (rule25 is "dieseltestengmsg25dieseltest.engmsg25"
)
send::
msg dieseltest.engmsg27
expect:: (rule27 is "dieseltestengmsg27dieseltest.engmsg27"
)
send::
msg ctx.set (rule69:Number=0
)
send::
msg dieseltest.nonexcl1
expect:: (rule69 is 1
)
send::
msg dieseltest.nonexcl1 (a:Number=1
, b:Number=1
)
expect:: (rule69 is 4
)
Start again, for excl:
send::
msg ctx.set (rule69:Number=0
)
send::
msg dieseltest.excl1
expect:: (rule69 is 1
)
send::
msg dieseltest.excl1 (a:Number=1
, b:Number=1
)
expect:: (rule69 is 3
)
send::
msg ctx.set (rule69:Number=0
)
send::
msg dieseltest.rnonexcl1
expect:: (rule69 is 1
)
send::
msg dieseltest.rnonexcl1 (a:Number=1
, b:Number=1
)
expect:: (rule69 is 4
)
Start again, for excl:
send::
msg ctx.set (rule69:Number=0
)
send::
msg dieseltest.rexcl1
expect:: (rule69 is 1
)
send::
msg dieseltest.rexcl1 (a:Number=1
, b:Number=1
)
expect:: (rule69 is 3
)
send::
msg dieseltest.ifelse (a:Number=2
, b:Number=1
)
expect:: (rule67 is 1
)
// $send dieseltest.ifelse (a=2, b=3)
// $expect (rule67 is 2)
val TESTVAL1:Number=1
=1
send::
msg ctx.echo (m)
// $send ctx.echo(m=TESTVAL1) LEAVE THIS COMMENTED ITS A TEST
This is during a story - define a try-catch block
send::
msg diesel.try
send::
msg dieseltest.failplease
expect:: (payload is exception
)
send::
msg ctx.set (oops:Number)
send::
msg diesel.catch
This is a sample rule that has a try-catch block:
send::
msg dieseltest.testcatchNoerr
expect:: (x97 is "oops"
)
send::
msg dieseltest.testcatchWithErr
expect:: (x97 is "haha"
)
// $send dieseltest.testcatchWithThrow
// $expect (x97 is "haha")
send::
msg dieseltest.testcatchnothrow
expect:: (x99 is "oops"
)
send::
msg dieseltest.evalonce.a1
expect:: (res77 is "dieseltest.evalonce.a1"
)
send::
msg dieseltest.indetedLambda
expect:: (embedded91)
There is an $else
construct
send::
msg testdiesel.else (branch:Boolean)
expect:: testdiesel.else.if
send::
msg testdiesel.else (branch:Boolean)
expect:: testdiesel.else.else
send::
msg testdiesel.else1 (branch:Boolean)
expect:: (res131 is "if"
)
expect:: testdiesel.else.if
send::
msg testdiesel.else1 (branch:Boolean)
expect:: (res131 is "else"
)
expect:: testdiesel.else.else
send::
msg testdiesel.expand1
expect:: (res147 is "ok"
)
send::
msg testdiesel.expand4
expect:: (res152 is "ok"
)
send::
msg testdiesel.fback1 (r156:Number=1
)
expect:: (r156 is 2
)
send::
msg testdiesel.fback1 (r156:Number=3
)
expect:: (r156 is 5
)
Single exported variables act as most would expect
val r193:Number=1
=1
send::
msg testdiesel.inc (r193)
expect:: (r193 is 3
)
// most people would expect it to be 3 - but for that, you have to export it between runs, with dieselScope.
This version is not exported, but it works because the same rule shares the same context:
send::
msg testdiesel.incLOCAL (r202:Number=1
)
expect:: (r202 is 3
)
// most people would expect it to be 2 but the two rules with the same name
// share the same local context
This one, being set only in the common context, it is shared between the rules. Careful when using parallel rules, you will have the same issues common with multi-threading access to common variables. Use channels or streams-story for parallel rules.
send::
msg ctx.set (r196:Number=1
)
send::
msg testdiesel.incInContext
expect:: (r196 is 4
)
// most people would expect it to be 3, but since it's in context to begin with, all 3 rules are decomposed
send::
msg testdiesel.bug.overwriteLocalVar (v183="183"
)
expect:: (payload is "184"
)
send::
msg testdiesel.expr.autoexport
expect:: (a189 is 189
)
send::
msg diesel.stream.new (stream="dtest247"
)
0 $mock::
dtest.l249
dtest.l251 (stream="dtest247"
="dtest247")
0 $mock::
dtest.l251
. (g253
=253
)
diesel.stream.put (stream="dtest247"
="dtest247")
diesel.stream.done (stream="dtest247"
="dtest247")
send::
msg diesel.stream.consume (stream="dtest247"
)
//$expect a.b
0 $mock::
dtest.l267
dtest.l270 (stream="x"
="x")
send::
msg snakk.text (url ="/diesel/rest/dieseltest/resour"
...)
expect:: (payload is "before-r1-read-after"
)
send::
msg snakk.text (url ="/diesel/rest/dieseltest/resour"
...)
expect:: (payload is "before-r1-update-after"
)
send:: msg (payload
=4
)
send::
msg testdiesel.erasepayload
send::
msg ctx.set (x)
expect:: (payload not defined
)
expect:: (x not defined
)
send::
msg snakk.text (url ="/diesel/engine/script"
..., verb="POST"
, body ="$msg testdiesel.api.public()"
..., X-Api-Key)
send::
msg snakk.text (url ="/diesel/engine/script"
..., verb="POST"
, body ="$msg testdiesel.api.private()"
..., X-Api-Key)
send::
msg diesel.catch
expect:: (payload not defined
)
You need to log in to post a comment!