Debian Codegraph @

.cargo/vendor/wasm-bindgen/tests/wasm/api.js

raw
1 const wasm = require('wasm-bindgen-test.js');
2 const assert = require('assert');
3
4 exports.assert_null = x => {
5 assert.strictEqual(x, null);
6 };
7
8 exports.js_works = () => {
9 assert.strictEqual(wasm.api_foo(), 'foo');
10 assert.strictEqual(wasm.api_bar('a'), 'a');
11 assert.strictEqual(wasm.api_baz(), 1);
12 wasm.api_baz2(2, 'a');
13
14 assert.strictEqual(wasm.api_js_null(), null);
15 assert.strictEqual(wasm.api_js_undefined(), undefined);
16
17 wasm.api_test_is_null_undefined(null, undefined, 1.0);
18
19 assert.strictEqual(wasm.api_get_true(), true);
20 assert.strictEqual(wasm.api_get_false(), false);
21 wasm.api_test_bool(true, false, 1.0);
22
23 assert.strictEqual(typeof (wasm.api_mk_symbol()), 'symbol');
24 assert.strictEqual(typeof (wasm.api_mk_symbol2('a')), 'symbol');
25 assert.strictEqual(Symbol.keyFor(wasm.api_mk_symbol()), undefined);
26 assert.strictEqual(Symbol.keyFor(wasm.api_mk_symbol2('b')), undefined);
27
28 wasm.api_assert_symbols(Symbol(), 'a');
29 wasm.api_acquire_string('foo', null);
30 assert.strictEqual(wasm.api_acquire_string2(''), '');
31 assert.strictEqual(wasm.api_acquire_string2('a'), 'a');
32
33 let arr = [1, 2, 3, 4, {}, ['a', 'b', 'c']]
34 wasm.api_completely_variadic(...arr).forEach((element, index) => {
35 assert.strictEqual(element, arr[index]);
36 });
37 assert.strictEqual(
38 wasm.api_completely_variadic().length,
39 0
40 );
41 wasm.api_variadic_with_prefixed_params([], {}, ...arr).forEach((element, index) => {
42 assert.strictEqual(element, arr[index]);
43 });
44 };
45
46 exports.js_eq_works = () => {
47 assert.strictEqual(wasm.eq_test('a', 'a'), true);
48 assert.strictEqual(wasm.eq_test('a', 'b'), false);
49 assert.strictEqual(wasm.eq_test(NaN, NaN), false);
50 assert.strictEqual(wasm.eq_test({ a: 'a' }, { a: 'a' }), false);
51 assert.strictEqual(wasm.eq_test1(NaN), false);
52 let x = { a: 'a' };
53 assert.strictEqual(wasm.eq_test(x, x), true);
54 assert.strictEqual(wasm.eq_test1(x), true);
55 };
56
57 exports.debug_values = () => ([
58 null,
59 undefined,
60 0,
61 1.0,
62 true,
63 [1, 2, 3],
64 "string",
65 { test: "object" },
66 [1.0, [2.0, 3.0]],
67 () => (null),
68 new Set(),
69 ]);
70
71 exports.assert_function_table = (x, i) => {
72 const rawWasm = require('wasm-bindgen-test.js').__wasm;
73 assert.ok(x instanceof WebAssembly.Table);
74 assert.strictEqual(x.get(i), rawWasm.function_table_lookup);
75 };