|
| 1 | +# [match.w](../../../../../../examples/tests/sdk_tests/regex/match.w) | compile | tf-aws |
| 2 | + |
| 3 | +## inflight.$Closure1-1.js |
| 4 | +```js |
| 5 | +module.exports = function({ $regex_Util }) { |
| 6 | + class $Closure1 { |
| 7 | + constructor({ }) { |
| 8 | + const $obj = (...args) => this.handle(...args); |
| 9 | + Object.setPrototypeOf($obj, this); |
| 10 | + return $obj; |
| 11 | + } |
| 12 | + async handle() { |
| 13 | + const matches1 = (await $regex_Util.match("p[a-z]+ch","peach")); |
| 14 | + const matches2 = (await $regex_Util.match("[0-9]+","0923")); |
| 15 | + const matches3 = (await $regex_Util.match("[0-9]+","0a923")); |
| 16 | + const matches4 = ( await $regex_Util. match( "^([a-zA-Z0-9_.-]+)@[a-z]+.[a-z]+\$", "[email protected]")); |
| 17 | + const matches5 = (await $regex_Util.match("p([a-z]+)ch","leach")); |
| 18 | + const matches6 = ( await $regex_Util. match( "^([a-zA-Z0-9_.-]+)@[a-z]+.[a-z]+", "@[email protected]")); |
| 19 | + const matches7 = (await $regex_Util.match("^Mary","Mary had a little lamb")); |
| 20 | + const matches8 = (await $regex_Util.match("lamb\$","Mary had a little lamb")); |
| 21 | + const matches9 = (await $regex_Util.match("lamb\$","Mary had a little hamb")); |
| 22 | + const matches10 = ( await $regex_Util. match( "^([a-zA-Z0-9_.-]+)@[a-z]+.[a-z]+\$", "[email protected]")); |
| 23 | + {((cond) => {if (!cond) throw new Error("assertion failed: matches1 == true ")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(matches1,true)))}; |
| 24 | + {((cond) => {if (!cond) throw new Error("assertion failed: matches2 == true ")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(matches2,true)))}; |
| 25 | + {((cond) => {if (!cond) throw new Error("assertion failed: matches3 == true ")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(matches3,true)))}; |
| 26 | + {((cond) => {if (!cond) throw new Error("assertion failed: matches4 == true ")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(matches4,true)))}; |
| 27 | + {((cond) => {if (!cond) throw new Error("assertion failed: matches5 == false")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(matches5,false)))}; |
| 28 | + {((cond) => {if (!cond) throw new Error("assertion failed: matches6 == false")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(matches6,false)))}; |
| 29 | + {((cond) => {if (!cond) throw new Error("assertion failed: matches7 == true ")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(matches7,true)))}; |
| 30 | + {((cond) => {if (!cond) throw new Error("assertion failed: matches8 == true ")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(matches8,true)))}; |
| 31 | + {((cond) => {if (!cond) throw new Error("assertion failed: matches9 == false")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(matches9,false)))}; |
| 32 | + {((cond) => {if (!cond) throw new Error("assertion failed: matches10 == false")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(matches10,false)))}; |
| 33 | + } |
| 34 | + } |
| 35 | + return $Closure1; |
| 36 | +} |
| 37 | + |
| 38 | +``` |
| 39 | + |
| 40 | +## main.tf.json |
| 41 | +```json |
| 42 | +{ |
| 43 | + "//": { |
| 44 | + "metadata": { |
| 45 | + "backend": "local", |
| 46 | + "stackName": "root", |
| 47 | + "version": "0.17.0" |
| 48 | + }, |
| 49 | + "outputs": { |
| 50 | + "root": { |
| 51 | + "Default": { |
| 52 | + "cloud.TestRunner": { |
| 53 | + "TestFunctionArns": "WING_TEST_RUNNER_FUNCTION_ARNS" |
| 54 | + } |
| 55 | + } |
| 56 | + } |
| 57 | + } |
| 58 | + }, |
| 59 | + "output": { |
| 60 | + "WING_TEST_RUNNER_FUNCTION_ARNS": { |
| 61 | + "value": "[[\"root/Default/Default/test:inflight match\",\"${aws_lambda_function.testinflightmatch_Handler_91AFEF4E.arn}\"]]" |
| 62 | + } |
| 63 | + }, |
| 64 | + "provider": { |
| 65 | + "aws": [ |
| 66 | + {} |
| 67 | + ] |
| 68 | + }, |
| 69 | + "resource": { |
| 70 | + "aws_iam_role": { |
| 71 | + "testinflightmatch_Handler_IamRole_DA813D38": { |
| 72 | + "//": { |
| 73 | + "metadata": { |
| 74 | + "path": "root/Default/Default/test:inflight match/Handler/IamRole", |
| 75 | + "uniqueId": "testinflightmatch_Handler_IamRole_DA813D38" |
| 76 | + } |
| 77 | + }, |
| 78 | + "assume_role_policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Action\":\"sts:AssumeRole\",\"Principal\":{\"Service\":\"lambda.amazonaws.com\"},\"Effect\":\"Allow\"}]}" |
| 79 | + } |
| 80 | + }, |
| 81 | + "aws_iam_role_policy": { |
| 82 | + "testinflightmatch_Handler_IamRolePolicy_B7F9EB14": { |
| 83 | + "//": { |
| 84 | + "metadata": { |
| 85 | + "path": "root/Default/Default/test:inflight match/Handler/IamRolePolicy", |
| 86 | + "uniqueId": "testinflightmatch_Handler_IamRolePolicy_B7F9EB14" |
| 87 | + } |
| 88 | + }, |
| 89 | + "policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":\"none:null\",\"Resource\":\"*\"}]}", |
| 90 | + "role": "${aws_iam_role.testinflightmatch_Handler_IamRole_DA813D38.name}" |
| 91 | + } |
| 92 | + }, |
| 93 | + "aws_iam_role_policy_attachment": { |
| 94 | + "testinflightmatch_Handler_IamRolePolicyAttachment_B8D01B6A": { |
| 95 | + "//": { |
| 96 | + "metadata": { |
| 97 | + "path": "root/Default/Default/test:inflight match/Handler/IamRolePolicyAttachment", |
| 98 | + "uniqueId": "testinflightmatch_Handler_IamRolePolicyAttachment_B8D01B6A" |
| 99 | + } |
| 100 | + }, |
| 101 | + "policy_arn": "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", |
| 102 | + "role": "${aws_iam_role.testinflightmatch_Handler_IamRole_DA813D38.name}" |
| 103 | + } |
| 104 | + }, |
| 105 | + "aws_lambda_function": { |
| 106 | + "testinflightmatch_Handler_91AFEF4E": { |
| 107 | + "//": { |
| 108 | + "metadata": { |
| 109 | + "path": "root/Default/Default/test:inflight match/Handler/Default", |
| 110 | + "uniqueId": "testinflightmatch_Handler_91AFEF4E" |
| 111 | + } |
| 112 | + }, |
| 113 | + "architectures": [ |
| 114 | + "arm64" |
| 115 | + ], |
| 116 | + "environment": { |
| 117 | + "variables": { |
| 118 | + "WING_FUNCTION_NAME": "Handler-c8aa61ca", |
| 119 | + "WING_TARGET": "tf-aws" |
| 120 | + } |
| 121 | + }, |
| 122 | + "function_name": "Handler-c8aa61ca", |
| 123 | + "handler": "index.handler", |
| 124 | + "publish": true, |
| 125 | + "role": "${aws_iam_role.testinflightmatch_Handler_IamRole_DA813D38.arn}", |
| 126 | + "runtime": "nodejs18.x", |
| 127 | + "s3_bucket": "${aws_s3_bucket.Code.bucket}", |
| 128 | + "s3_key": "${aws_s3_object.testinflightmatch_Handler_S3Object_2184865C.key}", |
| 129 | + "timeout": 30, |
| 130 | + "vpc_config": { |
| 131 | + "security_group_ids": [], |
| 132 | + "subnet_ids": [] |
| 133 | + } |
| 134 | + } |
| 135 | + }, |
| 136 | + "aws_s3_bucket": { |
| 137 | + "Code": { |
| 138 | + "//": { |
| 139 | + "metadata": { |
| 140 | + "path": "root/Default/Code", |
| 141 | + "uniqueId": "Code" |
| 142 | + } |
| 143 | + }, |
| 144 | + "bucket_prefix": "code-c84a50b1-" |
| 145 | + } |
| 146 | + }, |
| 147 | + "aws_s3_object": { |
| 148 | + "testinflightmatch_Handler_S3Object_2184865C": { |
| 149 | + "//": { |
| 150 | + "metadata": { |
| 151 | + "path": "root/Default/Default/test:inflight match/Handler/S3Object", |
| 152 | + "uniqueId": "testinflightmatch_Handler_S3Object_2184865C" |
| 153 | + } |
| 154 | + }, |
| 155 | + "bucket": "${aws_s3_bucket.Code.bucket}", |
| 156 | + "key": "<ASSET_KEY>", |
| 157 | + "source": "<ASSET_SOURCE>" |
| 158 | + } |
| 159 | + } |
| 160 | + } |
| 161 | +} |
| 162 | +``` |
| 163 | + |
| 164 | +## preflight.js |
| 165 | +```js |
| 166 | +const $stdlib = require('@winglang/sdk'); |
| 167 | +const $plugins = ((s) => !s ? [] : s.split(';'))(process.env.WING_PLUGIN_PATHS); |
| 168 | +const $outdir = process.env.WING_SYNTH_DIR ?? "."; |
| 169 | +const $wing_is_test = process.env.WING_IS_TEST === "true"; |
| 170 | +const std = $stdlib.std; |
| 171 | +const regex = $stdlib.regex; |
| 172 | +class $Root extends $stdlib.std.Resource { |
| 173 | + constructor(scope, id) { |
| 174 | + super(scope, id); |
| 175 | + class $Closure1 extends $stdlib.std.Resource { |
| 176 | + constructor(scope, id, ) { |
| 177 | + super(scope, id); |
| 178 | + (std.Node.of(this)).hidden = true; |
| 179 | + } |
| 180 | + static _toInflightType(context) { |
| 181 | + return ` |
| 182 | + require("./inflight.$Closure1-1.js")({ |
| 183 | + $regex_Util: ${context._lift(regex.Util)}, |
| 184 | + }) |
| 185 | + `; |
| 186 | + } |
| 187 | + _toInflight() { |
| 188 | + return ` |
| 189 | + (await (async () => { |
| 190 | + const $Closure1Client = ${$Closure1._toInflightType(this)}; |
| 191 | + const client = new $Closure1Client({ |
| 192 | + }); |
| 193 | + if (client.$inflight_init) { await client.$inflight_init(); } |
| 194 | + return client; |
| 195 | + })()) |
| 196 | + `; |
| 197 | + } |
| 198 | + _getInflightOps() { |
| 199 | + return ["handle", "$inflight_init"]; |
| 200 | + } |
| 201 | + } |
| 202 | + const matches1 = (regex.Util.match("p[a-z]+ch","peach")); |
| 203 | + const matches2 = (regex.Util.match("[0-9]+","0923")); |
| 204 | + const matches3 = (regex.Util.match("[0-9]+","0a923")); |
| 205 | + const matches4 = ( regex. Util. match( "^([a-zA-Z0-9_.-]+)@[a-z]+.[a-z]+\$", "[email protected]")); |
| 206 | + const matches5 = (regex.Util.match("p([a-z]+)ch","leach")); |
| 207 | + const matches6 = ( regex. Util. match( "^([a-zA-Z0-9_.-]+)@[a-z]+.[a-z]+", "@[email protected]")); |
| 208 | + const matches7 = (regex.Util.match("^Mary","Mary had a little lamb")); |
| 209 | + const matches8 = (regex.Util.match("lamb\$","Mary had a little lamb")); |
| 210 | + const matches9 = (regex.Util.match("lamb\$","Mary had a little hamb")); |
| 211 | + const matches10 = ( regex. Util. match( "^([a-zA-Z0-9_.-]+)@[a-z]+.[a-z]+\$", "[email protected]")); |
| 212 | + {((cond) => {if (!cond) throw new Error("assertion failed: matches1 == true ")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(matches1,true)))}; |
| 213 | + {((cond) => {if (!cond) throw new Error("assertion failed: matches2 == true ")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(matches2,true)))}; |
| 214 | + {((cond) => {if (!cond) throw new Error("assertion failed: matches3 == true ")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(matches3,true)))}; |
| 215 | + {((cond) => {if (!cond) throw new Error("assertion failed: matches4 == true ")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(matches4,true)))}; |
| 216 | + {((cond) => {if (!cond) throw new Error("assertion failed: matches5 == false")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(matches5,false)))}; |
| 217 | + {((cond) => {if (!cond) throw new Error("assertion failed: matches6 == false")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(matches6,false)))}; |
| 218 | + {((cond) => {if (!cond) throw new Error("assertion failed: matches7 == true ")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(matches7,true)))}; |
| 219 | + {((cond) => {if (!cond) throw new Error("assertion failed: matches8 == true ")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(matches8,true)))}; |
| 220 | + {((cond) => {if (!cond) throw new Error("assertion failed: matches9 == false")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(matches9,false)))}; |
| 221 | + {((cond) => {if (!cond) throw new Error("assertion failed: matches10 == false")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(matches10,false)))}; |
| 222 | + this.node.root.new("@winglang/sdk.std.Test",std.Test,this,"test:inflight match",new $Closure1(this,"$Closure1")); |
| 223 | + } |
| 224 | +} |
| 225 | +const $App = $stdlib.core.App.for(process.env.WING_TARGET); |
| 226 | +new $App({ outdir: $outdir, name: "match", rootConstruct: $Root, plugins: $plugins, isTestEnvironment: $wing_is_test, entrypointDir: process.env['WING_SOURCE_DIR'], rootId: process.env['WING_ROOT_ID'] }).synth(); |
| 227 | + |
| 228 | +``` |
| 229 | +
|
0 commit comments