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
   . (rule69=(rule69 + 1))

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

0 $mock:: dieseltest.excl1
   . (rule69=(rule69 + 1))

0 exclusive:: dieseltest.excl1 (a, b)
   . (rule69=(rule69 + 2))

Eclusive rules

$when:: dieseltest.rnonexcl1
   . (rule69=(rule69 + 1))

$when:: dieseltest.rnonexcl1 (a, b)
   . (rule69=(rule69 + 2))

$when:: dieseltest.rexcl1
   . (rule69=(rule69 + 1))

exclusive:: dieseltest.rexcl1 (a, b)
   . (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.testcatch1
   diesel.try
   dieseltest.failplease
   diesel.catch

$when:: dieseltest.failplease
   diesel.props.file (path<-"nosuch file.*")

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.[="msg"][="ea"])

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

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

$when:: dieseltest.evalonce.*
   dieseltest.evalonce2 (event<-diesel.[="msg"][="ea"], env, source, deviceId, deviceType, message, eventInfo<-diesel.[="msg"][="attrs"])

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, 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)
   . (r193=(r193 + 1))

$when:: testdiesel.inc (r193)
   . (r193=(r193 + 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))


Was this useful?    

By: Razie | 2019-09-03 | Tags: spec , dsl


Viewed 67 times ( | Print ) this page.

You need to log in to post a comment!

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