Skip to content

Commit

Permalink
improved logging of precedence check
Browse files Browse the repository at this point in the history
  • Loading branch information
AjaniBilby committed Mar 24, 2024
1 parent 0e27372 commit e8db5cd
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion tests/e2e/compiler/numeric.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,20 @@ import Project from "~/compiler/project.ts";
import { FuncRef } from "~/wasm/funcRef.ts";

const source = `
fn left(): f32 {
return -2.5 % 2.0 * -3.0;
}
fn right(): f32 {
return 10.0 - 1.0 / 2.0 % 10.0 - 8.0;
}
fn main(): bool {
// (-2.5 % 2.0) * -3.0 == 10.0 - ((1.0 / 2.0) % 10.0) - 8.0;
// 1.5 == 1.5
// true == 1
// doing this in a single expression to also ensure == is applied correctly
return -2.5 % 2.0 * -3.0 == 10.0 - 1.0 / 2.0 % 10.0 - 8.0;
}`;

Expand All @@ -26,6 +36,18 @@ Deno.test(`Numeric logic test`, async () => {
assertNotEquals(mainFunc.ref, null, "Main function hasn't compiled");
project.module.exportFunction("_start", mainFunc.ref as FuncRef);

const left = mainFile.namespace["left"];
assert(left instanceof CompilerFunc.default, "Missing left function");
left.compile();
assertNotEquals(left.ref, null, "Left function hasn't compiled");
project.module.exportFunction("left", left.ref as FuncRef);

const right = mainFile.namespace["left"];
assert(right instanceof CompilerFunc.default, "Missing right function");
right.compile();
assertNotEquals(right.ref, null, "Right function hasn't compiled");
project.module.exportFunction("right", right.ref as FuncRef);

const wasmModule = new WebAssembly.Module(project.module.toBinary());
const instance = await WebAssembly.instantiate(wasmModule, {});

Expand All @@ -37,6 +59,13 @@ Deno.test(`Numeric logic test`, async () => {
: fail(`Expected _start to be a function`);

const code = main() as number;
if (code === 0) fail(`equivalence checks failed`);
if (code === 0) {
const leftFn: () => number = exports.left as any;
assert(leftFn instanceof Function, "Missing left function");

const rightFn: () => number = exports.right as any;
assert(rightFn instanceof Function, "Missing right function");

fail(`equivalence checks failed ${leftFn()} != ${rightFn()}`);
};
});

0 comments on commit e8db5cd

Please sign in to comment.