| 1 |
const wasm = require('wasm-bindgen-test.js'); |
| 2 |
const assert = require('assert'); |
| 3 |
|
| 4 |
exports.call_ok = function() { |
| 5 |
assert.doesNotThrow(() => { |
| 6 |
let five = wasm.return_ok(); |
| 7 |
assert.strictEqual(five, 5); |
| 8 |
}) |
| 9 |
} |
| 10 |
|
| 11 |
exports.call_err = function() { |
| 12 |
assert.throws(() => wasm.return_err(), { |
| 13 |
message: "MyError::Variant" |
| 14 |
}); |
| 15 |
} |
| 16 |
|
| 17 |
exports.call_make_an_error = function() { |
| 18 |
assert.doesNotThrow(() => { |
| 19 |
let e = wasm.make_an_error() |
| 20 |
assert.strictEqual(e.message, "un-thrown error"); |
| 21 |
}); |
| 22 |
} |
| 23 |
|
| 24 |
function check_inflight(struct) { |
| 25 |
assert.strictEqual(struct.is_inflight(), false); |
| 26 |
} |
| 27 |
|
| 28 |
exports.all_struct_methods = function() { |
| 29 |
let struct; |
| 30 |
assert.throws(() => wasm.MyStruct.new_err(), { |
| 31 |
message: "MyError::Variant" |
| 32 |
}); |
| 33 |
assert.doesNotThrow(() => { |
| 34 |
struct = wasm.MyStruct.new(); |
| 35 |
}); |
| 36 |
check_inflight(struct); |
| 37 |
assert.doesNotThrow(() => { |
| 38 |
let five = struct.return_ok(); |
| 39 |
assert.strictEqual(five, 5); |
| 40 |
}); |
| 41 |
check_inflight(struct); |
| 42 |
assert.throws(() => struct.return_err(), { |
| 43 |
message: "MyError::Variant" |
| 44 |
}); |
| 45 |
check_inflight(struct); |
| 46 |
} |
| 47 |
|
| 48 |
exports.call_return_string = function() { |
| 49 |
assert.doesNotThrow(() => { |
| 50 |
let ok = wasm.jserror_return_string(); |
| 51 |
assert.strictEqual(ok, "string here"); |
| 52 |
}) |
| 53 |
} |
| 54 |
|