From 27c60464911a1266525a55119e86c6c5e15e13a1 Mon Sep 17 00:00:00 2001 From: Gary Sassano <10464497+garysassano@users.noreply.github.com> Date: Fri, 18 Aug 2023 18:55:53 +0200 Subject: [PATCH] chore(sdk): update `queue.pop()` sdk test (#3875) Updating the test with the `nil` type and `Queue.push()` variadic argument instead of for loop. *By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*. --- examples/tests/sdk_tests/queue/pop.w | 19 ++++++---------- .../sdk_tests/queue/pop.w_compile_tf-aws.md | 22 +++++++------------ 2 files changed, 15 insertions(+), 26 deletions(-) diff --git a/examples/tests/sdk_tests/queue/pop.w b/examples/tests/sdk_tests/queue/pop.w index d00b1d82624..8988c3ae8e3 100644 --- a/examples/tests/sdk_tests/queue/pop.w +++ b/examples/tests/sdk_tests/queue/pop.w @@ -1,20 +1,15 @@ bring cloud; -let NIL = "<>"; - let q = new cloud.Queue(); test "pop" { - let msgs = ["Foo", "Bar"]; - for msg in msgs { - q.push(msg); - } + q.push("Foo", "Bar"); - let first = q.pop() ?? NIL; - let second = q.pop() ?? NIL; - let third = q.pop() ?? NIL; + let first = q.pop(); + let second = q.pop(); + let third = q.pop(); - assert(msgs.contains(first)); - assert(msgs.contains(second)); - assert(third == NIL); + assert(first == "Foo"); + assert(second == "Bar"); + assert(third == nil); } \ No newline at end of file diff --git a/tools/hangar/__snapshots__/test_corpus/sdk_tests/queue/pop.w_compile_tf-aws.md b/tools/hangar/__snapshots__/test_corpus/sdk_tests/queue/pop.w_compile_tf-aws.md index a0fc9985be6..bc920fe8eb6 100644 --- a/tools/hangar/__snapshots__/test_corpus/sdk_tests/queue/pop.w_compile_tf-aws.md +++ b/tools/hangar/__snapshots__/test_corpus/sdk_tests/queue/pop.w_compile_tf-aws.md @@ -2,7 +2,7 @@ ## inflight.$Closure1-1.js ```js -module.exports = function({ $NIL, $q }) { +module.exports = function({ $q }) { class $Closure1 { constructor({ }) { const $obj = (...args) => this.handle(...args); @@ -10,16 +10,13 @@ module.exports = function({ $NIL, $q }) { return $obj; } async handle() { - const msgs = ["Foo", "Bar"]; - for (const msg of msgs) { - (await $q.push(msg)); - } - const first = ((await $q.pop()) ?? $NIL); - const second = ((await $q.pop()) ?? $NIL); - const third = ((await $q.pop()) ?? $NIL); - {((cond) => {if (!cond) throw new Error("assertion failed: msgs.contains(first)")})(msgs.includes(first))}; - {((cond) => {if (!cond) throw new Error("assertion failed: msgs.contains(second)")})(msgs.includes(second))}; - {((cond) => {if (!cond) throw new Error("assertion failed: third == NIL")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(third,$NIL)))}; + (await $q.push("Foo","Bar")); + const first = (await $q.pop()); + const second = (await $q.pop()); + const third = (await $q.pop()); + {((cond) => {if (!cond) throw new Error("assertion failed: first == \"Foo\"")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(first,"Foo")))}; + {((cond) => {if (!cond) throw new Error("assertion failed: second == \"Bar\"")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(second,"Bar")))}; + {((cond) => {if (!cond) throw new Error("assertion failed: third == nil")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(third,undefined)))}; } } return $Closure1; @@ -179,7 +176,6 @@ class $Root extends $stdlib.std.Resource { static _toInflightType(context) { return $stdlib.core.NodeJsCode.fromInline(` require("./inflight.$Closure1-1.js")({ - $NIL: ${context._lift(NIL)}, $q: ${context._lift(q)}, }) `); @@ -197,13 +193,11 @@ class $Root extends $stdlib.std.Resource { } _registerBind(host, ops) { if (ops.includes("handle")) { - $Closure1._registerBindObject(NIL, host, []); $Closure1._registerBindObject(q, host, ["pop", "push"]); } super._registerBind(host, ops); } } - const NIL = "<>"; const q = this.node.root.newAbstract("@winglang/sdk.cloud.Queue",this,"cloud.Queue"); this.node.root.new("@winglang/sdk.std.Test",std.Test,this,"test:pop",new $Closure1(this,"$Closure1")); }