Skip to content

Commit

Permalink
chore(sdk): update queue.pop() sdk test (#3875)
Browse files Browse the repository at this point in the history
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)*.
  • Loading branch information
garysassano authored Aug 18, 2023
1 parent c3aab87 commit 27c6046
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 26 deletions.
19 changes: 7 additions & 12 deletions examples/tests/sdk_tests/queue/pop.w
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
bring cloud;

let NIL = "<<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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,21 @@

## inflight.$Closure1-1.js
```js
module.exports = function({ $NIL, $q }) {
module.exports = function({ $q }) {
class $Closure1 {
constructor({ }) {
const $obj = (...args) => this.handle(...args);
Object.setPrototypeOf($obj, this);
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;
Expand Down Expand Up @@ -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)},
})
`);
Expand All @@ -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 = "<<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"));
}
Expand Down

0 comments on commit 27c6046

Please sign in to comment.