| 1 |
const wasm = require('wasm-bindgen-test.js'); |
| 2 |
const assert = require('assert'); |
| 3 |
|
| 4 |
exports.pass_struct_vec = () => { |
| 5 |
const el1 = new wasm.ArrayElement(); |
| 6 |
const el2 = new wasm.ArrayElement(); |
| 7 |
const ret = wasm.consume_struct_vec([el1, el2]); |
| 8 |
assert.strictEqual(ret.length, 3); |
| 9 |
|
| 10 |
const ret2 = wasm.consume_optional_struct_vec(ret); |
| 11 |
assert.strictEqual(ret2.length, 4); |
| 12 |
|
| 13 |
assert.strictEqual(wasm.consume_optional_struct_vec(undefined), undefined); |
| 14 |
}; |
| 15 |
|
| 16 |
exports.pass_invalid_struct_vec = () => { |
| 17 |
try { |
| 18 |
wasm.consume_struct_vec(['not a struct']); |
| 19 |
} catch (e) { |
| 20 |
assert.match(e.message, /array contains a value of the wrong type/) |
| 21 |
assert.match(e.stack, /consume_struct_vec/) |
| 22 |
} |
| 23 |
}; |