engine_story Pub

Testing built-in messages and executors

overwriting the diesel.env

msg ctx.echo  (e<-diesel.[="env"])

expect::  (e not empty)
msg ctx.set  (diesel.env<-"testing")

msg ctx.echo  (e<-diesel.[="env"])

expect::  (e == "testing")
msg ctx.set  (diesel.env<-"local")

Context echo

msg ctx.echo  (ha<-"haha")

expect::  (ha == "haha")

send::  msg ctx.echo  (x:Number<-1)

Testing constants

// $when diesel.before // => ctx.set(DONE_BEFORE="diesel.before yeah")

// $send ctx.echo(msg = DONE_BEFORE) // $expect (DONE_BEFORE contains "diesel.before yeah")

Testing generation rules in context

send::  msg ctx.set  (c<-"c")

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)

Matching messages

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")

Comments

send::  msg dieseltest.comment1 

expect::  (rule22 is 22)

Specific diesel attributes

send::  msg dieseltest.engmsg25 

expect::  (rule25 is "dieseltestengmsg25dieseltest.engmsg25")

send::  msg dieseltest.engmsg27 

expect::  (rule27 is "dieseltestengmsg27dieseltest.engmsg27")

Exclusive mock

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)

Exclusive rules

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)

If/else

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)

Comments

val TESTVAL1:Number<-1

send::  msg ctx.echo  (m<-TESTVAL1)

// $send ctx.echo(m=TESTVAL1) LEAVE THIS COMMENTED ITS A TEST

expect::  (TESTVAL1 is 1)

Exceptions, try/catch

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<-(1 / 0))

send::  msg diesel.catch 

This is a sample rule that has a try-catch block:

send::  msg dieseltest.testcatch1 

parm values are evaluated once:

send::  msg dieseltest.evalonce.a1 

expect::  (res77 is "dieseltest.evalonce.a1")

send::  msg dieseltest.indetedLambda 

expect::  (embedded91)

if-else

There is an $else construct

send::  msg testdiesel.else  (branch:Boolean<-true)

expect::  testdiesel.else.if

send::  msg testdiesel.else  (branch:Boolean<-false)

expect::  testdiesel.else.else

send::  msg testdiesel.else1  (branch:Boolean<-true)

expect::  (res131 is "if")
expect::  testdiesel.else.if

send::  msg testdiesel.else1  (branch:Boolean<-false)

expect::  (res131 is "else")
expect::  testdiesel.else.else

send::  msg testdiesel.expand1 

expect::  (res147 is "ok")

send::  msg testdiesel.expand4 

expect::  (res152 is "ok")

Fallback rules

send::  msg testdiesel.fback1  (r156:Number<-1)

expect::  (r156 is 2)

send::  msg testdiesel.fback1  (r156:Number<-3)

expect::  (r156 is 5)

Contexts and variable overwriting

Variable once expanded is not overwritten, as most would expect - the reason is that:

  • it's passed to each rule separately as an argument
  • it's set by each rule, in the common context, overwriting 2 basically - see the trace for this:

send::  msg testdiesel.inc  (r193:Number<-1)

expect::  (r193 is 2)

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)


Was this useful?    

By: Razie | 2017-04-03 .. 2019-11-07 | Tags: story , dsl , engine


Viewed 110 times ( | Print ) this page.

You need to log in to post a comment!

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