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 (level=0)
     . (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 (level=0)
     . (ctx[="res29"]="ok")
   $ifc:: (1 == 1) do.this (level=0)
     . (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 (level=0)
     . (ctx[="res46"]="ok")
   $else::  do.that (level=0)
     . (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

0 $mock:: test.diesel.block66 $ifc:: (a == a)
   $ifc:: (1 == 1) do.this (level=0)
     . (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 (level=0)
   . (ctx[="res78"]="ok")

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

expect::  (res78 is "ok")

Embedded if/$else

0 $mock:: test.diesel.block90 (level)
   $ifc:: (level >= 1) do.this (level=0)
     . (res90=1)
     $ifc:: (level >= 2) do.this (level=1)
       . (res90=2)
     $else::  do.that (level=1)
       . (res90=3)
   $else::  do.that (level=0)
     . (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

0 $mock:: test.diesel.block99
   . (res99=1)
   test.diesel.throw
   diesel.catch
     do.this (level=1)
       . (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 184 times ( | History | Print ) this page.

You need to log in to post a comment!

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