diff --git a/tools/hangar/__snapshots__/test_corpus/sdk_tests/std/json.test.w_compile_tf-aws.md b/tools/hangar/__snapshots__/test_corpus/sdk_tests/std/json.test.w_compile_tf-aws.md index fba0ff1f8ff..e66362370f7 100644 --- a/tools/hangar/__snapshots__/test_corpus/sdk_tests/std/json.test.w_compile_tf-aws.md +++ b/tools/hangar/__snapshots__/test_corpus/sdk_tests/std/json.test.w_compile_tf-aws.md @@ -1,6 +1,6 @@ # [json.test.w](../../../../../../examples/tests/sdk_tests/std/json.test.w) | compile | tf-aws -## inflight.$Closure1-1.js +## inflight.$Closure1-2.js ```js module.exports = function({ $std_Json }) { class $Closure1 { @@ -20,7 +20,7 @@ module.exports = function({ $std_Json }) { ``` -## inflight.$Closure10-1.js +## inflight.$Closure10-2.js ```js module.exports = function({ $std_Json }) { class $Closure10 { @@ -45,9 +45,9 @@ module.exports = function({ $std_Json }) { ``` -## inflight.$Closure2-1.js +## inflight.$Closure2-2.js ```js -module.exports = function({ }) { +module.exports = function({ $assertions_Assert }) { class $Closure2 { constructor({ }) { const $obj = (...args) => this.handle(...args); @@ -55,29 +55,16 @@ module.exports = function({ }) { return $obj; } async handle() { - const assertThrows = async (expected, block) => { - let error = false; - try { - (await block()); - } - catch ($error_actual) { - const actual = $error_actual.message; - {((cond) => {if (!cond) throw new Error("assertion failed: actual == expected")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(actual,expected)))}; - error = true; - } - {((cond) => {if (!cond) throw new Error("assertion failed: error")})(error)}; - } - ; const JSON_PROPERTY_DOES_NOT_EXIST_ERROR = "Json property \"c\" does not exist"; const obj = ({"a": 1,"b": 2}); const mutObj = ({"a": 1,"b": 2}); {((cond) => {if (!cond) throw new Error("assertion failed: obj.get(\"b\") == 2")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(((obj, args) => { if (obj[args] === undefined) throw new Error(`Json property "${args}" does not exist`); return obj[args] })(obj, "b"),2)))}; {((cond) => {if (!cond) throw new Error("assertion failed: mutObj.get(\"b\") == 2")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(((obj, args) => { if (obj[args] === undefined) throw new Error(`Json property "${args}" does not exist`); return obj[args] })(mutObj, "b"),2)))}; - (await assertThrows(JSON_PROPERTY_DOES_NOT_EXIST_ERROR,async () => { + (await $assertions_Assert.throws(JSON_PROPERTY_DOES_NOT_EXIST_ERROR,async () => { ((obj, args) => { if (obj[args] === undefined) throw new Error(`Json property "${args}" does not exist`); return obj[args] })(obj, "c"); } )); - (await assertThrows(JSON_PROPERTY_DOES_NOT_EXIST_ERROR,async () => { + (await $assertions_Assert.throws(JSON_PROPERTY_DOES_NOT_EXIST_ERROR,async () => { ((obj, args) => { if (obj[args] === undefined) throw new Error(`Json property "${args}" does not exist`); return obj[args] })(mutObj, "c"); } )); @@ -88,9 +75,9 @@ module.exports = function({ }) { ``` -## inflight.$Closure3-1.js +## inflight.$Closure3-2.js ```js -module.exports = function({ }) { +module.exports = function({ $assertions_Assert }) { class $Closure3 { constructor({ }) { const $obj = (...args) => this.handle(...args); @@ -98,25 +85,12 @@ module.exports = function({ }) { return $obj; } async handle() { - const assertThrows = async (expected, block) => { - let error = false; - try { - (await block()); - } - catch ($error_actual) { - const actual = $error_actual.message; - {((cond) => {if (!cond) throw new Error("assertion failed: actual == expected")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(actual,expected)))}; - error = true; - } - {((cond) => {if (!cond) throw new Error("assertion failed: error")})(error)}; - } - ; const INDEX_OUT_OF_BOUNDS_ERROR = "Index out of bounds"; const jsonArray = ["foo", "bar", "baz"]; const mutJsonArray = [1, 2, 3]; {((cond) => {if (!cond) throw new Error("assertion failed: jsonArray.getAt(2) == \"baz\"")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(((obj, args) => { if (obj[args] === undefined) throw new Error("Index out of bounds"); return obj[args] })(jsonArray, 2),"baz")))}; {((cond) => {if (!cond) throw new Error("assertion failed: mutJsonArray.getAt(2) == 3")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(((obj, args) => { if (obj[args] === undefined) throw new Error("Index out of bounds"); return obj[args] })(mutJsonArray, 2),3)))}; - (await assertThrows(INDEX_OUT_OF_BOUNDS_ERROR,async () => { + (await $assertions_Assert.throws(INDEX_OUT_OF_BOUNDS_ERROR,async () => { ((obj, args) => { if (obj[args] === undefined) throw new Error("Index out of bounds"); return obj[args] })(jsonArray, 3); ((obj, args) => { if (obj[args] === undefined) throw new Error("Index out of bounds"); return obj[args] })(mutJsonArray, 3); } @@ -128,7 +102,7 @@ module.exports = function({ }) { ``` -## inflight.$Closure4-1.js +## inflight.$Closure4-2.js ```js module.exports = function({ }) { class $Closure4 { @@ -150,7 +124,7 @@ module.exports = function({ }) { ``` -## inflight.$Closure5-1.js +## inflight.$Closure5-2.js ```js module.exports = function({ }) { class $Closure5 { @@ -172,7 +146,7 @@ module.exports = function({ }) { ``` -## inflight.$Closure6-1.js +## inflight.$Closure6-2.js ```js module.exports = function({ $std_Json }) { class $Closure6 { @@ -194,7 +168,7 @@ module.exports = function({ $std_Json }) { ``` -## inflight.$Closure7-1.js +## inflight.$Closure7-2.js ```js module.exports = function({ $std_Json }) { class $Closure7 { @@ -221,7 +195,7 @@ module.exports = function({ $std_Json }) { ``` -## inflight.$Closure8-1.js +## inflight.$Closure8-2.js ```js module.exports = function({ $std_Json }) { class $Closure8 { @@ -243,7 +217,7 @@ module.exports = function({ $std_Json }) { ``` -## inflight.$Closure9-1.js +## inflight.$Closure9-2.js ```js module.exports = function({ $std_Json }) { class $Closure9 { @@ -268,6 +242,73 @@ module.exports = function({ $std_Json }) { ``` +## inflight.Assert-1.js +```js +module.exports = function({ }) { + class Assert { + static async throws(expected, block) { + let actual = ""; + try { + (await block()); + } + catch ($error_e) { + const e = $error_e.message; + actual = e; + } + if ((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(actual,""))) { + throw new Error("expected error, but none thrown."); + } + if ((((a,b) => { try { return require('assert').notDeepStrictEqual(a,b) === undefined; } catch { return false; } })(actual,expected))) { + throw new Error(String.raw({ raw: ["expected error message: \"", "\" got: \"", "\""] }, expected, actual)); + } + } + static async equalStr(a, b) { + try { + {((cond) => {if (!cond) throw new Error("assertion failed: a == b")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(a,b)))}; + } + catch ($error_e) { + const e = $error_e.message; + throw new Error(String.raw({ raw: ["expected: ", " got: ", ""] }, b, a)); + } + } + static async isNil(a) { + try { + {((cond) => {if (!cond) throw new Error("assertion failed: a == nil")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(a,undefined)))}; + } + catch ($error_e) { + const e = $error_e.message; + {console.log(e)}; + throw new Error(String.raw({ raw: ["expected '", "' to be nil"] }, a)); + } + } + static async equalNum(a, b) { + try { + {((cond) => {if (!cond) throw new Error("assertion failed: a == b")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(a,b)))}; + } + catch ($error_e) { + const e = $error_e.message; + {console.log(e)}; + throw new Error(String.raw({ raw: ["expected: ", " got: ", ""] }, b, a)); + } + } + } + return Assert; +} + +``` + +## inflight.PreflightAssert-1.js +```js +module.exports = function({ }) { + class PreflightAssert { + constructor({ }) { + } + } + return PreflightAssert; +} + +``` + ## main.tf.json ```json { @@ -300,6 +341,81 @@ module.exports = function({ $std_Json }) { } ``` +## preflight.assertions-1.js +```js +module.exports = function({ $stdlib }) { + const std = $stdlib.std; + class Assert extends $stdlib.std.Resource { + constructor(scope, id, ) { + super(scope, id); + } + static _toInflightType(context) { + return ` + require("./inflight.Assert-1.js")({ + }) + `; + } + _toInflight() { + return ` + (await (async () => { + const AssertClient = ${Assert._toInflightType(this)}; + const client = new AssertClient({ + }); + if (client.$inflight_init) { await client.$inflight_init(); } + return client; + })()) + `; + } + _getInflightOps() { + return ["throws", "equalStr", "isNil", "equalNum", "$inflight_init"]; + } + } + class PreflightAssert extends $stdlib.std.Resource { + constructor(scope, id, ) { + super(scope, id); + } + static throws(expected, block) { + let actual = ""; + try { + (block()); + } + catch ($error_e) { + const e = $error_e.message; + actual = e; + } + if ((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(actual,""))) { + throw new Error("expected error, but none thrown."); + } + if ((((a,b) => { try { return require('assert').notDeepStrictEqual(a,b) === undefined; } catch { return false; } })(actual,expected))) { + throw new Error(String.raw({ raw: ["expected error message: \"", "\" got: \"", "\""] }, expected, actual)); + } + } + static _toInflightType(context) { + return ` + require("./inflight.PreflightAssert-1.js")({ + }) + `; + } + _toInflight() { + return ` + (await (async () => { + const PreflightAssertClient = ${PreflightAssert._toInflightType(this)}; + const client = new PreflightAssertClient({ + }); + if (client.$inflight_init) { await client.$inflight_init(); } + return client; + })()) + `; + } + _getInflightOps() { + return ["$inflight_init"]; + } + } + return { Assert, PreflightAssert }; +}; + +``` + ## preflight.js ```js const $stdlib = require('@winglang/sdk'); @@ -308,6 +424,7 @@ const $outdir = process.env.WING_SYNTH_DIR ?? "."; const $wing_is_test = process.env.WING_IS_TEST === "true"; const std = $stdlib.std; const cloud = $stdlib.cloud; +const assertions = require("./preflight.assertions-1.js")({ $stdlib }); class $Root extends $stdlib.std.Resource { constructor(scope, id) { super(scope, id); @@ -318,7 +435,7 @@ class $Root extends $stdlib.std.Resource { } static _toInflightType(context) { return ` - require("./inflight.$Closure1-1.js")({ + require("./inflight.$Closure1-2.js")({ $std_Json: ${context._lift($stdlib.core.toLiftableModuleType(std.Json, "@winglang/sdk/std", "Json"))}, }) `; @@ -345,7 +462,8 @@ class $Root extends $stdlib.std.Resource { } static _toInflightType(context) { return ` - require("./inflight.$Closure2-1.js")({ + require("./inflight.$Closure2-2.js")({ + $assertions_Assert: ${context._lift($stdlib.core.toLiftableModuleType(assertions.Assert, "", "Assert"))}, }) `; } @@ -371,7 +489,8 @@ class $Root extends $stdlib.std.Resource { } static _toInflightType(context) { return ` - require("./inflight.$Closure3-1.js")({ + require("./inflight.$Closure3-2.js")({ + $assertions_Assert: ${context._lift($stdlib.core.toLiftableModuleType(assertions.Assert, "", "Assert"))}, }) `; } @@ -397,7 +516,7 @@ class $Root extends $stdlib.std.Resource { } static _toInflightType(context) { return ` - require("./inflight.$Closure4-1.js")({ + require("./inflight.$Closure4-2.js")({ }) `; } @@ -423,7 +542,7 @@ class $Root extends $stdlib.std.Resource { } static _toInflightType(context) { return ` - require("./inflight.$Closure5-1.js")({ + require("./inflight.$Closure5-2.js")({ }) `; } @@ -449,7 +568,7 @@ class $Root extends $stdlib.std.Resource { } static _toInflightType(context) { return ` - require("./inflight.$Closure6-1.js")({ + require("./inflight.$Closure6-2.js")({ $std_Json: ${context._lift($stdlib.core.toLiftableModuleType(std.Json, "@winglang/sdk/std", "Json"))}, }) `; @@ -476,7 +595,7 @@ class $Root extends $stdlib.std.Resource { } static _toInflightType(context) { return ` - require("./inflight.$Closure7-1.js")({ + require("./inflight.$Closure7-2.js")({ $std_Json: ${context._lift($stdlib.core.toLiftableModuleType(std.Json, "@winglang/sdk/std", "Json"))}, }) `; @@ -503,7 +622,7 @@ class $Root extends $stdlib.std.Resource { } static _toInflightType(context) { return ` - require("./inflight.$Closure8-1.js")({ + require("./inflight.$Closure8-2.js")({ $std_Json: ${context._lift($stdlib.core.toLiftableModuleType(std.Json, "@winglang/sdk/std", "Json"))}, }) `; @@ -530,7 +649,7 @@ class $Root extends $stdlib.std.Resource { } static _toInflightType(context) { return ` - require("./inflight.$Closure9-1.js")({ + require("./inflight.$Closure9-2.js")({ $std_Json: ${context._lift($stdlib.core.toLiftableModuleType(std.Json, "@winglang/sdk/std", "Json"))}, }) `; @@ -557,7 +676,7 @@ class $Root extends $stdlib.std.Resource { } static _toInflightType(context) { return ` - require("./inflight.$Closure10-1.js")({ + require("./inflight.$Closure10-2.js")({ $std_Json: ${context._lift($stdlib.core.toLiftableModuleType(std.Json, "@winglang/sdk/std", "Json"))}, }) `;