summaryrefslogtreecommitdiffstats
path: root/vendor/wasm-bindgen/tests/wasm/node.js
blob: 41baa8b240dcc27addc4f4e097bc42845dc5cd40 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const assert = require('assert');
const wasm = require('wasm-bindgen-test');

var called = false;

exports.hit = function() {
  called = true;
};

exports.FOO = 1.0;

exports.test_works = function() {
  assert.strictEqual(called, true);

  var r = wasm.Foo.new();
  assert.strictEqual(r.add(0), 0);
  assert.strictEqual(r.add(1), 1);
  assert.strictEqual(r.add(2), 3);
  r.free();

  var r2 = wasm.Foo.with_contents(10);
  assert.strictEqual(r2.add(0), 10);
  assert.strictEqual(r2.add(1), 11);
  assert.strictEqual(r2.add(2), 13);
  r2.free();

  assert.strictEqual(wasm.Color.Green, 0);
  assert.strictEqual(wasm.Color.Yellow, 1);
  assert.strictEqual(wasm.Color.Red, 2);
  assert.strictEqual(wasm.Color[0], 'Green');
  assert.strictEqual(wasm.Color[1], 'Yellow');
  assert.strictEqual(wasm.Color[2], 'Red');
  assert.strictEqual(Object.keys(wasm.Color).length, 6);
  assert.strictEqual(wasm.cycle(wasm.Color.Green), wasm.Color.Yellow);

  wasm.node_math(1.0, 2.0);
};