block-syntax-story Pub

Testing new block syntax

simple block

0 $mock:: test.diesel.block6
   a.a
   . (ctx[="res6"]="ok")

send::  msg test.diesel.block6 

expect::  (res6 is "ok")

Simple if

0 $mock:: test.diesel.block16
   a.a
   $ifc:: (1 == 1) do.this
     . (ctx[="res16"]="ok")
   b.b

send::  msg test.diesel.block16 

expect::  (res16 is "ok")

Simple if if

0 $mock:: test.diesel.block29
   a.a
   $ifc:: (1 == 1) do.this
     . (ctx[="res29"]="ok")
   $ifc:: (1 == 1) do.this
     . (ctx[="res29"]=(res29 + "ok"))

send::  msg test.diesel.block29 

expect::  (res29 is "okok")

Simple if/$else

0 $mock:: test.diesel.block46
   a.a
   $ifc:: (a46 == 1) do.this
     . (ctx[="res46"]="ok")
   $else::  do.that
     . (ctx[="res46"]="notok")
   b.b

send::  msg test.diesel.block46  (a46:Number=1)

expect::  (res46 is "ok")

send::  msg test.diesel.block46  (a46:Number=2)

expect::  (res46 is "notok")

if guard on rule line

$mock test.diesel.block66 $if (a == a) { if (1 == 1) { (ctx.res66 = "ok") } }

send::  msg test.diesel.block66  (a:Number=2)

expect::  (res66 is "ok")

empty block

0 $mock:: test.diesel.block78
   $ifc:: (1 == 1) do.this
   . (ctx[="res78"]="ok")

send::  msg test.diesel.block78  (a:Number=2)

expect::  (res78 is "ok")

Embedded if/$else

$mock test.diesel.block90 (level) { if (level >= 1) { (res90 = 1) if (level >= 2) { (res90 = 2) } else { (res90 = 3) } } else { (res90 = 4) } }

send::  msg test.diesel.block90  (level:Number=0)

expect::  (res90 is 4)
send::  msg test.diesel.block90  (level:Number=1)

expect::  (res90 is 3)
send::  msg test.diesel.block90  (level:Number=2)

expect::  (res90 is 2)
send::  msg test.diesel.block90  (level:Number=1.5)

expect::  (res90 is 3)

diesel.catch

$mock test.diesel.block99 { (res99 = 1)

// diesel.try // diesel.throw (exception="SQL") // see known issues - this will fail test.diesel.throw

diesel.catch { (res99 = 2) } }

send::  msg test.diesel.block99 

expect::  (res99 is 2)

$when:: test.diesel.throw
   . (x=(4 / 0))
   diesel.throw (msg="SQL"="SQL")


Was this useful?    

By: Razie | 2023-03-25 .. 2023-03-26 | Tags: story , dsl , sanity


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

You need to log in to post a comment!

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