Skip to content

Commit

Permalink
add test and update snaps
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkMcCulloh committed Apr 12, 2024
1 parent e4674b8 commit 2941a45
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 2 deletions.
6 changes: 6 additions & 0 deletions examples/tests/valid/bring_local.test.w
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,21 @@ bring "./store.w" as file1;
bring "./subdir/subfile.w" as file2;
bring "./subdir/empty.w" as file3;
bring math;
bring expect;

// classes from other files can be used
let store = new file1.Store();
let q = new file2.Q();
expect.equal(file2.Q.preflightGreet("foo"), "Hello foo");

test "add data to store" {
store.store("foo");
}

test "greet" {
expect.equal(file2.Q.greet("bar"), "Hello bar");
}

// structs from other files can be used
let s = file1.Point {
x: 1,
Expand Down
3 changes: 2 additions & 1 deletion examples/tests/valid/subdir/subfile.w
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
bring math;

pub class Q {
extern "./util.ts" static inflight greet(name: str): str;
pub extern "./util.ts" static inflight greet(name: str): str;
pub extern "./util.ts" static preflightGreet(name: str): str;
}
1 change: 1 addition & 0 deletions examples/tests/valid/subdir/util.extern.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export default interface extern {
greet: (name: string) => Promise<string>,
preflightGreet: (name: string) => string,
}
4 changes: 4 additions & 0 deletions examples/tests/valid/subdir/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ import type extern from "./util.extern";

export const greet: extern["greet"] = async (name) => {
return "Hello " + name;
}

export const preflightGreet: extern["preflightGreet"] = (name) => {
return "Hello " + name;
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,26 @@ module.exports = function({ $store }) {
//# sourceMappingURL=inflight.$Closure1-3.cjs.map
```

## inflight.$Closure2-3.cjs
```cjs
"use strict";
const $helpers = require("@winglang/sdk/lib/helpers");
module.exports = function({ $expect_Util, $file2_Q }) {
class $Closure2 {
constructor({ }) {
const $obj = (...args) => this.handle(...args);
Object.setPrototypeOf($obj, this);
return $obj;
}
async handle() {
(await $expect_Util.equal((await $file2_Q.greet("bar")), "Hello bar"));
}
}
return $Closure2;
}
//# sourceMappingURL=inflight.$Closure2-3.cjs.map
```

## inflight.Q-2.cjs
```cjs
"use strict";
Expand Down Expand Up @@ -282,6 +302,7 @@ const file1 = require("./preflight.store-2.cjs");
const file2 = require("./preflight.subfile-3.cjs");
const file3 = require("./preflight.empty-1.cjs");
const math = $stdlib.math;
const expect = $stdlib.expect;
class $Root extends $stdlib.std.Resource {
constructor($scope, $id) {
super($scope, $id);
Expand Down Expand Up @@ -320,6 +341,42 @@ class $Root extends $stdlib.std.Resource {
});
}
}
class $Closure2 extends $stdlib.std.AutoIdResource {
_id = $stdlib.core.closureId();
constructor($scope, $id, ) {
super($scope, $id);
$helpers.nodeof(this).hidden = true;
}
static _toInflightType() {
return `
require("${$helpers.normalPath(__dirname)}/inflight.$Closure2-3.cjs")({
$expect_Util: ${$stdlib.core.liftObject($stdlib.core.toLiftableModuleType(expect.Util, "@winglang/sdk/expect", "Util"))},
$file2_Q: ${$stdlib.core.liftObject($stdlib.core.toLiftableModuleType(file2.Q, "", "Q"))},
})
`;
}
_toInflight() {
return `
(await (async () => {
const $Closure2Client = ${$Closure2._toInflightType()};
const client = new $Closure2Client({
});
if (client.$inflight_init) { await client.$inflight_init(); }
return client;
})())
`;
}
get _liftMap() {
return ({
"handle": [
[$stdlib.core.toLiftableModuleType(file2.Q, "", "Q"), ["greet"]],
],
"$inflight_init": [
[$stdlib.core.toLiftableModuleType(file2.Q, "", "Q"), []],
],
});
}
}
class Triangle extends $stdlib.std.Resource {
constructor($scope, $id, ) {
super($scope, $id);
Expand Down Expand Up @@ -381,7 +438,9 @@ class $Root extends $stdlib.std.Resource {
}
const store = new file1.Store(this, "Store");
const q = new file2.Q(this, "Q");
(expect.Util.equal((file2.Q.preflightGreet("foo")), "Hello foo"));
this.node.root.new("@winglang/sdk.std.Test", std.Test, this, "test:add data to store", new $Closure1(this, "$Closure1"));
this.node.root.new("@winglang/sdk.std.Test", std.Test, this, "test:greet", new $Closure2(this, "$Closure2"));
const s = ({"x": 1, "y": 2});
const c = file1.Color.BLUE;
$helpers.assert($helpers.neq(c, file1.Color.RED), "c != file1.Color.RED");
Expand Down Expand Up @@ -538,6 +597,9 @@ class Q extends $stdlib.std.Resource {
constructor($scope, $id, ) {
super($scope, $id);
}
static preflightGreet(name) {
return ($extern("../../../subdir/util.ts")["preflightGreet"])(name)
}
static _toInflightType() {
return `
require("${$helpers.normalPath(__dirname)}/inflight.Q-2.cjs")({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
## stdout.log
```log
pass ─ bring_local.test.wsim » root/env0/test:add data to store
pass ─ bring_local.test.wsim » root/env1/test:greet
Tests 1 passed (1)
Tests 2 passed (2)
Snapshots 1 skipped
Test Files 1 passed (1)
Duration <DURATION>
Expand Down

0 comments on commit 2941a45

Please sign in to comment.