expr-regex-story Pub

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)

Regex and string built-in functions

send::  msg ctx.set  (re176=matches(a:...)

expect::  (re176 is true)

send::  msg ctx.set  (re176=matches(a:...)

expect::  (re176 is false)

send::  msg ctx.set  (re176=replaceAll...)

expect::  (re176 is "axxzxx")

send::  msg ctx.set  (re185=replaceFir...)

expect::  (re185 is "axxzbc")

send::  msg ctx.set  (res188=trim(a:Str...)

expect::  (res188 is "abc")

Capture groups

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

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

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

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

expect::  (acctId3 is "99")

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

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

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 48 times ( | History | Print ) this page.

You need to log in to post a comment!

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