expr-js-story Pub

These are tested separately, for performance testing reasons

simple scripting

send::  msg test.util.todayjs 

expect::  (payload ~= "....-..-..")

send::  msg test.util.addMonths  (mths:Number=1=1)

expect::  (payload ~= "....-..-..")

send::  msg ctx.set  (payload=test.util....)

expect::  (payload contains "UTC")$ifc:: NOT (diesel[="isLocaldevbox"])
expect::  (payload is Exception)$ifc:: diesel[="isLocaldevbox"]

The diesel object:

send::  msg ctx.set  (res5=js{{ diese...)

expect::  (res5 not empty)

send::  msg ctx.set  (res139=js{{ diese...)

expect::  (res139 not empty)

The wix object:

send::  msg ctx.set  (res144=js{{ wix.d...)

expect::  (res144 not empty)

Javascript and regex

These are not used: send::  msg ctx.set  (a:Number=1=1, b:Number=2=2)

The input parameters overwrite context above send::  msg expr.js.sum1  (a:Number=1=1, b:Number=2=2)

expect::  (res39 is 3)

send::  msg expr.js.sum2  (a:Number=1=1, b:Number=2=2)

expect::  (res42 is 3.0)

send::  msg expr.js.name1  (email="jane@doe.com"="jane@doe....)

expect::  (res40 is "jane")

/$send ctx.setVal (name="cart", value={})

send::  msg expr.js.validateEmail  (email="jane@doe.com"="jane@doe....)

expect::  (ok25 is true)

send::  msg ctx.set  (ok25:Boolean=false)

send::  msg expr.js.validateEmail  (email="janedoe.com"="janedoe.c...)

expect::  (ok25 is false)

Javascript expressions

Simple javascript - script is independent (no arguments):

send::  msg ctx.set  (a225=js{{ 1+4 }...)

expect::  (a225 is 5)

Escaping quotes with javascript regex (notice a230 available inside the js expression):

val a230="{"a":32}"="{"a":32}" send::  msg ctx.set  (a231=js{{ a230....)

expect::  (a231 is "{"a":32}")

More JS examples:

send::  msg ctx.set  (now=js{{ java....)

send::  msg ctx.set  (later=js{{ var d...)

send::  msg ctx.set  (later=js{{ var d...)

send::  msg ctx.set  (noweh=js{{ var d..., later=js{{ var d...)

expect::  (now is number)

JS as lambdas

send::  msg ctx.set  (res57="1 2 3 "="1 2 3 ")

Convert to string and use a JS expression for filter lambda send::  msg ctx.set  (a298:Array=(([1,2,3] ...)

send::  msg ctx.echo  (res299=(res57[="l...)

expect::  (res299 is ["1"])


Was this useful?    

By: Razie | 2020-01-10 .. 2022-03-17 | Tags: story , dsl , sanity


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

You need to log in to post a comment!

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