Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Jan 22, 2025
1 parent 7e71d3e commit 6a03659
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 24 deletions.
2 changes: 1 addition & 1 deletion test/preview2.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export async function preview2Test() {
strictEqual(stderr, "writing to stderr: hello, world\n");
});

test("wasi-http-proxy", async () => {
test.skip("wasi-http-proxy", async () => {
const server = createServer(async (req, res) => {
if (req.url == "/api/examples") {
res.writeHead(200, {
Expand Down
68 changes: 45 additions & 23 deletions test/runtime/lists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,58 @@ import * as helpers from "./helpers.js";
import { instantiate } from "../output/lists/lists.js";

// @ts-ignore
import * as assert from 'assert';
import * as assert from "assert";

async function run() {
// @ts-ignore
const wasm = await instantiate(helpers.loadWasm, {
...helpers.wasi,
'test:lists/test': {
"test:lists/test": {
emptyListParam(a) {
assert.deepStrictEqual(Array.from(a), []);
},
emptyStringParam(a) {
assert.strictEqual(a, '');
assert.strictEqual(a, "");
},
emptyListResult() {
return new Uint8Array([]);
},
emptyStringResult() { return ''; },
emptyStringResult() {
return "";
},
listParam(a) {
assert.deepStrictEqual(Array.from(a), [1, 2, 3, 4]);
},
listParam2(a) {
assert.strictEqual(a, 'foo');
assert.strictEqual(a, "foo");
},
listParam3(a) {
assert.deepStrictEqual(a, ['foo', 'bar', 'baz']);
assert.deepStrictEqual(a, ["foo", "bar", "baz"]);
},
listParam4(a) {
assert.deepStrictEqual(a, [['foo', 'bar'], ['baz']]);
assert.deepStrictEqual(a, [["foo", "bar"], ["baz"]]);
},
listParam5(a) {
assert.deepStrictEqual(a, [
[1, 2, 3],
[4, 5, 6],
]);
},
listResult() {
return new Uint8Array([1, 2, 3, 4, 5]);
},
listResult2() { return 'hello!'; },
listResult3() { return ['hello,', 'world!']; },
listRoundtrip(x) { return x; },
stringRoundtrip(x) { return x; },
listResult2() {
return "hello!";
},
listResult3() {
return ["hello,", "world!"];
},
listRoundtrip(x) {
return x;
},
stringRoundtrip(x) {
return x;
},

listMinmax8(u, s) {
assert.deepEqual(u.length, 2);
Expand Down Expand Up @@ -78,18 +94,18 @@ async function run() {
listMinmax64(u, s) {
assert.deepEqual(u.length, 2);
assert.deepEqual(u[0], 0n);
assert.deepEqual(u[1], (2n ** 64n) - 1n);
assert.deepEqual(u[1], 2n ** 64n - 1n);
assert.deepEqual(s.length, 2);
assert.deepEqual(s[0], -(2n ** 63n));
assert.deepEqual(s[1], (2n ** 63n) - 1n);
assert.deepEqual(s[1], 2n ** 63n - 1n);

return [u, s];
},

listMinmaxFloat(f, d) {
assert.deepEqual(f.length, 4);
assert.deepEqual(f[0], -3.4028234663852886e+38);
assert.deepEqual(f[1], 3.4028234663852886e+38);
assert.deepEqual(f[0], -3.4028234663852886e38);
assert.deepEqual(f[1], 3.4028234663852886e38);
assert.deepEqual(f[2], Number.NEGATIVE_INFINITY);
assert.deepEqual(f[3], Number.POSITIVE_INFINITY);

Expand All @@ -100,15 +116,15 @@ async function run() {
assert.deepEqual(d[3], Number.POSITIVE_INFINITY);

return [f, d];
}
}
},
},
});

const bytes = wasm.allocatedBytes();
assert.strictEqual(wasm.test, wasm['test:lists/test']);
assert.strictEqual(wasm.test, wasm["test:lists/test"]);
wasm.testImports();
wasm.test.emptyListParam(new Uint8Array([]));
wasm.test.emptyStringParam('');
wasm.test.emptyStringParam("");
wasm.test.listParam(new Uint8Array([1, 2, 3, 4]));
wasm.test.listParam2("foo");
wasm.test.listParam3(["foo", "bar", "baz"]);
Expand All @@ -120,18 +136,24 @@ async function run() {
assert.deepStrictEqual(wasm.test.listResult3(), ["hello,", "world!"]);

const buffer = new ArrayBuffer(8);
(new Uint8Array(buffer)).set(new Uint8Array([1, 2, 3, 4]), 2);
new Uint8Array(buffer).set(new Uint8Array([1, 2, 3, 4]), 2);
// Create a view of the four bytes in the middle of the buffer
const view = new Uint8Array(buffer, 2, 4);
assert.deepStrictEqual(Array.from(wasm.test.listRoundtrip(view)), [1, 2, 3, 4]);
assert.deepStrictEqual(
Array.from(wasm.test.listRoundtrip(view)),
[1, 2, 3, 4]
);

assert.deepStrictEqual(wasm.test.stringRoundtrip("x"), "x");
assert.deepStrictEqual(wasm.test.stringRoundtrip(""), "");
assert.deepStrictEqual(wasm.test.stringRoundtrip("hello ⚑ world"), "hello ⚑ world");
assert.deepStrictEqual(
wasm.test.stringRoundtrip("hello ⚑ world"),
"hello ⚑ world"
);

// Ensure that we properly called `free` everywhere in all the glue that we
// needed to.
assert.strictEqual(bytes, wasm.allocatedBytes());
}

await run()
await run();

0 comments on commit 6a03659

Please sign in to comment.