-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtests.js
66 lines (55 loc) · 1.8 KB
/
tests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
define(["base", "wasm/desugar", "v8/backend", "compiletests"], function(base, desugar, wasm_backend_v8, compiletests) {
var parser = null;
var systemJSSrc = null;
var systemWASMSrc = null;
var externs = {
addI8: function(a, b) {
return (a + b) << 24 >> 24;
},
};
var createNormal = function(text, assert, suppress_v8) {
var status = new base.Status(function(message) { assert.ok(false, message); });
var ast = base.frontend(systemWASMSrc, "test", text, parser, status);
assert.notEqual(ast, null, "frontend");
ast = desugar.process(ast);
var module = base.astToCompiledJS(ast, systemJSSrc, {}, status);
assert.notEqual(module, null, "backend");
if (!suppress_v8) {
// Smoke test the V8 backend.
wasm_backend_v8.generate(ast);
}
return module(externs);
};
var defineTests = function(mode_name, create) {
for (var m = 0; m < compiletests.testDefinitions.length; m++) {
var module = compiletests.testDefinitions[m];
QUnit.module(mode_name + " " + module.name);
for (var t = 0; t < module.tests.length; t++) {
var test = module.tests[t];
(function(test) {
QUnit.test(test.name, function(assert) {
var m = create(test.source, assert, !test.v8);
test.verify(m, assert);
});
})(test);
}
}
}
defineTests("polyfill", createNormal);
var run = function() {
Promise.all([
base.getURL("wasm.pegjs"),
base.getURL("system.js"),
base.getURL("system.wasm"),
]).then(function(values) {
var status = new base.Status(function(message) { throw message; });
parser = base.createParser(values[0], status);
systemJSSrc = values[1];
systemWASMSrc = values[2];
QUnit.start();
});
};
return {
run: run,
};
});