Add tests for static variables

This commit is contained in:
Maik Klein 2020-01-07 19:37:24 +01:00
parent 093fb856a3
commit a526c8d7fd
2 changed files with 20 additions and 7 deletions

View file

@ -2,3 +2,6 @@
#[no_mangle]
pub extern fn foo() {}
#[no_mangle]
pub static FOO: u64 = 42;

View file

@ -8,21 +8,31 @@ let list = WebAssembly.Module.exports(m);
console.log('exports', list);
const my_exports = {};
let nexports = 0;
let nexports_fn = 0;
let nexports_global = 0;
for (const entry of list) {
if (entry.kind !== 'function')
continue;
my_exports[entry.name] = true;
nexports += 1;
if (entry.kind == 'function'){
nexports_fn += 1;
}
if (entry.kind == 'global'){
nexports_global += 1;
}
my_exports[entry.name] = true;
}
if (my_exports.foo === undefined)
throw new Error("`foo` wasn't defined");
if (my_exports.FOO === undefined)
throw new Error("`FOO` wasn't defined");
if (my_exports.main === undefined) {
if (nexports != 1)
if (nexports_fn != 1)
throw new Error("should only have one function export");
} else {
if (nexports != 2)
if (nexports_fn != 2)
throw new Error("should only have two function exports");
}
if (nexports_global != 1)
throw new Error("should only have one static export");