Skip to content

Commit 8c2e624

Browse files
Willem WyndhamColinEberhardt
Willem Wyndham
authored andcommitted
chore: add as-pect tests and asbuild
also fixed virtual method issue I found.
1 parent 6847db1 commit 8c2e624

File tree

13 files changed

+761
-20
lines changed

13 files changed

+761
-20
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
node_modules
2-
build
2+
build
3+
assembly/__tests__/index.spec.wat
4+
assembly/__tests__/spec.spec.wat

__spec_tests__/data.test.js

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
const { RegExp } = require("../__tests__/util");
2+
const fs = require("fs");
3+
const { fail } = require("assert");
4+
5+
const data = fs.readFileSync("./__spec_tests__/test.dat", "utf8");
6+
const lines = data.split("\n");
7+
8+
const matches = (regex, value) => {
9+
const regexp = new RegExp(regex);
10+
return regexp.exec(value);
11+
};
12+
13+
const unescape = (str) => str.replace("\\n", "\n");
14+
const escape = (str) => str.replace(/[\n]/g, "\\n");
15+
16+
describe("test data", () => {
17+
lines.forEach((line) => {
18+
try {
19+
const parts = line.split("\t").filter((f) => f !== "");
20+
if (parts.length < 4) return;
21+
22+
const regex = unescape(parts[1]);
23+
const str = parts[2] !== "NULL" ? unescape(parts[2]) : "";
24+
it(`matches ${escape(regex)} against "${escape(str)}"`, () => {
25+
if (parts[3] == "BADBR") {
26+
expect(() => new RegExp(regex)).toThrow();
27+
} else {
28+
const match = matches(regex, str);
29+
const captures = parts[3].match(/\((\d{1,2}|\?),(\d{1,2}|\?)\)+/g);
30+
31+
captures.forEach((capture, index) => {
32+
const digits = capture.match(/\((\d{1,2}|\?),(\d{1,2}|\?)\)/);
33+
const expected =
34+
digits[0] == "?"
35+
? ""
36+
: str.substring(Number(digits[1]), Number(digits[2]));
37+
if (parts[2] === "NULL" ) {
38+
console.log(`match ${match.matches}, parts ${parts}`)
39+
}
40+
expect(match.matches[index]).toEqual(expected);
41+
});
42+
}
43+
});
44+
} catch {
45+
it(`parsing error - ${line}`, () => {
46+
fail("");
47+
});
48+
}
49+
});
50+
});

__spec_tests__/test.dat

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,4 +211,4 @@ E .*(\\XXX).* \XXX (0,4)(0,4)
211211
E \\XXX \XXX (0,4)
212212
E .*(/000).* /000 (0,4)(0,4)
213213
E .*(\\000).* \000 (0,4)(0,4)
214-
E \\000 \000 (0,4)
214+
E \\000 \000 (0,4)

__tests__/util.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const loader = require("@assemblyscript/loader/umd/index");
55
class RegExp {
66
constructor(regex, flags = "") {
77
this.wasmModule = loader.instantiateSync(
8-
fs.readFileSync("./build/untouched.wasm"),
8+
fs.readFileSync("./build/debug/assemblyscript-regex.wasm"),
99
{
1010
env: {
1111
log: (strPtr) => {

as-pect.config.js

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
module.exports = {
2+
/**
3+
* A set of globs passed to the glob package that qualify typescript files for testing.
4+
*/
5+
include: ["assembly/__tests__/**/*.spec.ts"],
6+
/**
7+
* A set of globs passed to the glob package that quality files to be added to each test.
8+
*/
9+
add: ["assembly/__tests__/**/*.include.ts"],
10+
/**
11+
* All the compiler flags needed for this test suite. Make sure that a binary file is output.
12+
*/
13+
flags: {
14+
/** To output a wat file, uncomment the following line. */
15+
// "--textFile": ["output.wat"],
16+
/** A runtime must be provided here. */
17+
"--runtime": ["stub"], // Acceptable values are: full, half, stub (arena), and none
18+
"--target": "test",
19+
},
20+
/**
21+
* A set of regexp that will disclude source files from testing.
22+
*/
23+
disclude: [/node_modules/],
24+
/**
25+
* Add your required AssemblyScript imports here.
26+
*/
27+
imports(memory, createImports, instantiateSync, binary) {
28+
let instance; // Imports can reference this
29+
const myImports = {
30+
// put your web assembly imports here, and return the module
31+
};
32+
instance = instantiateSync(binary, createImports(myImports));
33+
return instance;
34+
},
35+
/**
36+
* Add a custom reporter here if you want one. The following example is in typescript.
37+
*
38+
* @example
39+
* import { TestReporter, TestGroup, TestResult, TestContext } from "as-pect";
40+
*
41+
* export class CustomReporter extends TestReporter {
42+
* // implement each abstract method here
43+
* public abstract onStart(suite: TestContext): void;
44+
* public abstract onGroupStart(group: TestGroup): void;
45+
* public abstract onGroupFinish(group: TestGroup): void;
46+
* public abstract onTestStart(group: TestGroup, result: TestResult): void;
47+
* public abstract onTestFinish(group: TestGroup, result: TestResult): void;
48+
* public abstract onFinish(suite: TestContext): void;
49+
* }
50+
*/
51+
// reporter: new CustomReporter(),
52+
/**
53+
* Specify if the binary wasm file should be written to the file system.
54+
*/
55+
outputBinary: false,
56+
};

asconfig.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@
1414
"shrinkLevel": 1,
1515
"converge": false,
1616
"noAssert": false
17+
},
18+
"test": {
19+
"debug": true
1720
}
1821
},
19-
"options": {}
22+
"options": {
23+
"transform": ["visitor-as/dist/examples/includeBytesTransform"]
24+
}
2025
}

assembly/__tests__/as-pect.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/// <reference types="@as-pect/assembly/types/as-pect" />
2+
3+
declare function includeBytes(filename: string): StaticArray<u8>;

0 commit comments

Comments
 (0)