expr-regex-story Pub

Javascript and regex

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

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

expect::  (res39 is 3)

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

expect::  (res42 is 3.0)

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

expect::  (res40 is "jane")

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

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

expect::  (ok25 is true)

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

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

expect::  (ok25 is false)

Regex and string built-in functions

send::  msg ctx.set  (re176)

expect::  (re176 is true)

send::  msg ctx.set  (re176)

expect::  (re176 is false)

send::  msg ctx.set  (re176)

expect::  (re176 is "axxzxx")

send::  msg ctx.set  (re185)

expect::  (re185 is "axxzbc")

send::  msg ctx.set  (res188)

expect::  (res188 is "abc")

Capture groups

send::  msg expr.captureGroups  (path="/getAccount1/67")

expect::  (payload[="accountId"] is "67")

send::  msg ctx.set  (payload="/getAccount1/99")

send::  msg ctx.regex  (regex ="/getAccount1/(?<acctId3>\d+)"...)

expect::  (acctId3 is "99")

Don't overwrite payload: send::  msg ctx.set  (payload="pa")

send::  msg ctx.regex  (regex ="/getAccount1/(?<acctId4>\d+)"..., payload="/getAccount1/999")

expect::  (acctId4 is "999")
expect::  (payload is "pa")

regex map - testing the engine decomp

0 $mock:: a.p
   . (users="u1:p1:f1 u2:p2:f2")
   . (y=js{{ users.split(' ') }})
   . (z=(y map ( x=>test.diesel.parse.item(x)() )))

send::  msg a.p 

expect::  (z[="0"=0][:String="server"] is "u1")


Was this useful?    

By: Razie | 2021-11-12 .. 2022-03-20 | Tags: story , dsl , sanity


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

You need to log in to post a comment!

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