wasm-bindgen/tests/wasm/option.js

29 lines
809 B
JavaScript
Raw Normal View History

2018-08-03 08:23:11 +03:00
const wasm = require('wasm-bindgen-test.js');
const assert = require('assert');
2018-08-03 08:23:11 +03:00
class MyType {
}
2018-08-03 08:23:11 +03:00
exports.MyType = MyType;
exports.take_none_byval = x => {
assert.strictEqual(x, undefined);
2018-08-03 08:23:11 +03:00
};
exports.take_some_byval = x => {
assert.ok(x !== null && x !== undefined);
assert.ok(x instanceof MyType);
2018-08-03 08:23:11 +03:00
};
exports.return_undef_byval = () => undefined;
exports.return_null_byval = () => null;
exports.return_some_byval = () => new MyType();
2018-08-03 08:23:11 +03:00
exports.test_option_values = () => {
wasm.rust_take_none_byval(null);
wasm.rust_take_none_byval(undefined);
wasm.rust_take_some_byval(new MyType());
assert.strictEqual(wasm.rust_return_none_byval(), undefined);
const x = wasm.rust_return_some_byval();
assert.ok(x !== null && x !== undefined);
assert.ok(x instanceof MyType);
2018-08-03 08:23:11 +03:00
};