engine_spec Pub

Testing generation rules with context

msg dieseltest.this.shouldparse  (p1, p2?, p3:Number?=(1 + 2), p4:Array?)

$when:: dieseltest.rule1 (a, b)
   . (rule1ab=(a + b))

$when:: dieseltest.rule1 (a, b, c)
   . (rule1abc=((a + b) + c))

$when:: dieseltest.rule1 (a, b, d)
   . (rule1abd=((a + b) + d))

$when:: *.sendtest
   . (rule12=true)

$when:: dieseltestsendtest.*
   . (rule16=true)

$when:: dieseltest.send.multiple.*
   . (rule18=true)

$when:: dieseltest.send.*
   . (rule18a=true)

$when:: /dieseltestJ..*/.
   . (rule19=true)

$when:: /dieseltestMM.*/.
   ctx.echo (diesel.msg.entity, diesel.msg.action)
   . (rule19a=true)

Comments

$when:: dieseltest.comment1
   . (rule22=22)

diesel.msg specials

$when:: dieseltest.engmsg25
   . (rule25=((diesel[="msg"][="entity"] + diesel[="msg"][="action"]) + diesel[="msg"][="ea"]))

$when:: dieseltest.engmsg27
   . (rule27a=((diesel[="msg"][="entity"] + diesel[="msg"][="action"]) + diesel[="msg"][="ea"]))
   ctx.echo (rule27)
   . (rule27=((diesel[="msg"][="entity"] + diesel[="msg"][="action"]) + diesel[="msg"][="ea"]))

Eclusive mocks

0 $mock:: dieseltest.nonexcl1
   . (dieselScope[="rule69"]=(rule69 + 1))

0 $mock:: dieseltest.nonexcl1 (a, b)
   . (dieselScope[="rule69"]=(rule69 + 2))

0 $mock:: dieseltest.excl1
   . (dieselScope[="rule69"]=(rule69 + 1))

0 exclusive:: dieseltest.excl1 (a, b)
   . (dieselScope[="rule69"]=(rule69 + 2))

Eclusive rules

$when:: dieseltest.rnonexcl1
   . (dieselScope[="rule69"]=(rule69 + 1))

$when:: dieseltest.rnonexcl1 (a, b)
   . (dieselScope[="rule69"]=(rule69 + 2))

$when:: dieseltest.rexcl1
   . (dieselScope[="rule69"]=(rule69 + 1))

exclusive:: dieseltest.rexcl1 (a, b)
   . (dieselScope[="rule69"]=(rule69 + 2))

$when:: dieseltest.opt1 (a?, b?)
   . (rule61=(a + b))

$when:: dieseltest.opt2 (a? ?= 1, b?)
   . (rule64=(a + b))

$when:: dieseltest.ifelse (a? ?= 1, b?)
   $ifc:: (a > b) . (rule67=1)
   $else::  . (rule67=2)

Exceptions, try, catch

$when:: dieseltest.testcatchNoerr
   diesel.try
   step no errors...
   . (x97="oops")
   diesel.catch
     . (x97="haha")

$when:: dieseltest.testcatchWithErr
   diesel.try
   dieseltest.failplease
   . (x97="oops")
   diesel.catch
     . (x97="haha")

$when:: dieseltest.testcatchWithThrow
   diesel.try
   dieseltest.throwplease
   . (x97="oops")
   diesel.catch
     . (x97="haha")

$when:: dieseltest.testcatchnothrow
   diesel.try
   dieseltest.notfail
   . (x99="oops")
   diesel.catch
     . (x99="haha")
     . (x99="haha")

$when:: dieseltest.failplease
   diesel.props.file (path="nosuch file.*"="nosuch fi...)

$when:: dieseltest.throwplease
   diesel.throw (msg="opa!"="opa!")

Parms eval once

This is a big deal, has weird side-effects if engine behavior changes: expr like diesel.msg.ea or diesel.msg.attrs will have unexpected values down the trace.

$when:: dieseltest.evalonce.a1
   dieseltest.evalonce2 (a=diesel[="m...)

$when:: dieseltest.evalonce2 (a)
   dieseltest.evalonce3 (a)

$when:: dieseltest.evalonce3 (a)
   . (res77=a)

$when:: dieseltest.evalonce.*
   dieseltest.evalonce2 (event=diesel[="m..., env, source, deviceId, deviceType, message, eventInfo=diesel[="m...)

TODO THIS TEST FAILS on devblinq ems.event.* if we remove the event setting.

$when:: dieseltest.indetedLambda
   . (aFlag=true)
   $ifc:: aFlag diesel.lambda
     . (embedded91=true)
     dieseltest.embedded
   dieseltest.afterLambda

if-else

$when:: testdiesel.else (branch)
   $ifc:: branch testdiesel.else.if
   $else::  testdiesel.else.else

$when:: testdiesel.else1 (branch)
   $ifc:: branch do.this
     testdiesel.else.if
     . (res131="if")
   $else::  do.this
     testdiesel.else.else
     . (res131="else")

Corner test cases

Testing value in multi-level decmopositions

$when:: testdiesel.expand1
   testdiesel.expand2

$when:: testdiesel.expand2
   testdiesel.expand3

$when:: testdiesel.expand3
   . (res147="ok")

$when:: testdiesel.expand4
   testdiesel.expand2
     testdiesel.expand3
       . (res152="ok")

Fallback

$when:: testdiesel.fback1 (r156 == 3)
   . (r156=(r156 + 2))

fallback:: testdiesel.fback1 (r156)
   . (r156=(r156 + 1))

Variables, contexts and overwriting

Variable once expanded is not overwritten inside the rest of the rule, as most would expect - the result of applying BOTH rules below will be 2, not 3 as one might expect. Think of each as its own separate function call.

$when:: testdiesel.inc (r193 == 1)
   . (dieselScope[="r193"]=(r193 + 1))

$when:: testdiesel.inc (r193)
   . (dieselScope[="r193"]=(r193 + 1))

This version also

$when:: testdiesel.incLOCAL (r202 == 1)
   diesel.nop
   . (r202=(r202 + 1))

$when:: testdiesel.incLOCAL (r202)
   diesel.nop
   . (r202=(r202 + 1))

However, the result of these will be 3:

$when:: testdiesel.incInContext (r196 == 1)
   . (r196=(r196 + 1))

$when:: testdiesel.incInContext (r196 is defined)
   . (r196=(r196 + 1))

$when:: testdiesel.incInContext
   . (r196=(r196 + 1))

Test: overwriting local variables should be allowed.

$when:: testdiesel.bug.overwriteLocalVar (v183)
   . (v183="184")
   . (payload=v183)

msg testdiesel.expr.autoexport 

$when:: testdiesel.expr.autoexport
   nothing.eh
   . (a189=189)
   . (a190=189)

Fork join

0 $mock:: dtest.l251 (stream)
   . (g253=253)
   diesel.stream.put (stream)
   diesel.stream.done (stream)

0 $mock:: dtest.l270
   . (payload=245)
   ctx.sleep (duration:Number=1000=1000)


Was this useful?    

By: Razie | 2019-09-03 .. 2021-02-02 | Tags: spec , dsl , private


Viewed 274 times ( | History | Print ) this page.

You need to log in to post a comment!

© Copyright DieselApps, 2012-2022, all rights reserved.