diff --git a/tests/all/main.rs b/tests/all/main.rs index d05b4c1d1..a58fedfa7 100644 --- a/tests/all/main.rs +++ b/tests/all/main.rs @@ -9,5 +9,4 @@ mod dependencies; mod js_objects; mod imports; mod simple; -mod node; mod typescript; diff --git a/tests/all/node.rs b/tests/all/node.rs deleted file mode 100644 index 7928c70c6..000000000 --- a/tests/all/node.rs +++ /dev/null @@ -1,161 +0,0 @@ -use super::project; - -#[test] -fn works() { - project() - .debug(false) - .nodejs_experimental_modules(false) - .file( - "src/lib.rs", - r#" - #![feature(use_extern_macros)] - - extern crate wasm_bindgen; - - use wasm_bindgen::prelude::*; - - #[wasm_bindgen(module = "./test")] - extern { - static FOO: JsValue; - fn hit(); - } - - #[wasm_bindgen] - pub fn run() { - hit(); - assert_eq!(FOO.as_f64(), Some(1.0)); - } - - #[wasm_bindgen] - pub struct Foo { - contents: u32, - } - - #[wasm_bindgen] - impl Foo { - pub fn new() -> Foo { - Foo::with_contents(0) - } - pub fn with_contents(a: u32) -> Foo { - Foo { contents: a } - } - pub fn add(&mut self, amt: u32) -> u32 { - self.contents += amt; - self.contents - } - } - - #[wasm_bindgen] - pub enum Color { - Green, - Yellow, - Red, - } - #[wasm_bindgen] - pub fn cycle(color: Color) -> Color { - match color { - Color::Green => Color::Yellow, - Color::Yellow => Color::Red, - Color::Red => Color::Green, - } - } - - #[wasm_bindgen] - pub fn math(a: f32, b: f64) -> f64 { - b.acos() + - b.asin() + - b.atan() + - b.atan2(b) + - b.cbrt() + - b.cosh() + - b.exp_m1() + - b.ln_1p() + - b.sinh() + - b.tan() + - b.tanh() + - b.hypot(b) + - b.cos() + - b.exp() + - b.exp2() + - b.mul_add(b, b) + - b.ln() + - b.log(b) + - b.log10() + - b.log2() + - b.powi(8) + - b.powf(b) + - b.round() + - b.sin() + - b.abs() + - b.signum() + - b.floor() + - b.ceil() + - b.trunc() + - b.sqrt() + - (b % (a as f64)) + - ((a.cos() + - a.exp() + - a.exp2() + - a.mul_add(a, a) + - a.ln() + - a.log(a) + - a.log10() + - a.log2() + - a.powi(8) + - a.powf(a) + - a.round() + - a.sin() + - a.abs() + - a.signum() + - a.floor() + - a.ceil() + - a.trunc() + - a.sqrt() + - (a % (b as f32))) as f64) + - (b + 2.0f64.powf(a as f64)) - } - "#, - ) - .file( - "test.js", - r#" - const assert = require('assert'); - - var called = false; - - module.exports.hit = function() { - called = true; - }; - - module.exports.FOO = 1.0; - - const { math, run, Foo, Color, cycle } = require('./out'); - - module.exports.test = function() { - run(); - assert.strictEqual(called, true); - - var r = Foo.new(); - assert.strictEqual(r.add(0), 0); - assert.strictEqual(r.add(1), 1); - assert.strictEqual(r.add(2), 3); - r.free(); - - var r2 = 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(Color.Green, 0); - assert.strictEqual(Color.Yellow, 1); - assert.strictEqual(Color.Red, 2); - assert.strictEqual(Object.keys(Color).length, 3); - assert.strictEqual(cycle(Color.Green), Color.Yellow); - - math(1.0, 2.0); - }; - "#, - ) - .test(); -} diff --git a/tests/wasm/main.rs b/tests/wasm/main.rs index 3a1a373b2..eccf57d02 100644 --- a/tests/wasm/main.rs +++ b/tests/wasm/main.rs @@ -18,6 +18,7 @@ pub mod imports; pub mod import_class; pub mod js_objects; pub mod math; +pub mod node; pub mod option; pub mod optional_primitives; pub mod simple; diff --git a/tests/wasm/node.js b/tests/wasm/node.js new file mode 100644 index 000000000..1887904fa --- /dev/null +++ b/tests/wasm/node.js @@ -0,0 +1,34 @@ +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(Object.keys(wasm.Color).length, 3); + assert.strictEqual(wasm.cycle(wasm.Color.Green), wasm.Color.Yellow); + + wasm.node_math(1.0, 2.0); +}; diff --git a/tests/wasm/node.rs b/tests/wasm/node.rs new file mode 100644 index 000000000..cee7986e1 --- /dev/null +++ b/tests/wasm/node.rs @@ -0,0 +1,105 @@ +use wasm_bindgen_test::*; +use wasm_bindgen::prelude::*; + +#[wasm_bindgen(module = "tests/wasm/node.js", version = "*")] +extern { + fn test_works(); + static FOO: JsValue; + fn hit(); +} + +#[wasm_bindgen_test] +fn works() { + hit(); + assert_eq!(FOO.as_f64(), Some(1.0)); + test_works(); +} + +#[wasm_bindgen] +pub struct Foo { + contents: u32, +} + +#[wasm_bindgen] +impl Foo { + pub fn new() -> Foo { + Foo::with_contents(0) + } + pub fn with_contents(a: u32) -> Foo { + Foo { contents: a } + } + pub fn add(&mut self, amt: u32) -> u32 { + self.contents += amt; + self.contents + } +} + +#[wasm_bindgen] +pub enum Color { + Green, + Yellow, + Red, +} +#[wasm_bindgen] +pub fn cycle(color: Color) -> Color { + match color { + Color::Green => Color::Yellow, + Color::Yellow => Color::Red, + Color::Red => Color::Green, + } +} + +#[wasm_bindgen] +pub fn node_math(a: f32, b: f64) -> f64 { + b.acos() + + b.asin() + + b.atan() + + b.atan2(b) + + b.cbrt() + + b.cosh() + + b.exp_m1() + + b.ln_1p() + + b.sinh() + + b.tan() + + b.tanh() + + b.hypot(b) + + b.cos() + + b.exp() + + b.exp2() + + b.mul_add(b, b) + + b.ln() + + b.log(b) + + b.log10() + + b.log2() + + b.powi(8) + + b.powf(b) + + b.round() + + b.sin() + + b.abs() + + b.signum() + + b.floor() + + b.ceil() + + b.trunc() + + b.sqrt() + + (b % (a as f64)) + + ((a.cos() + + a.exp() + + a.exp2() + + a.mul_add(a, a) + + a.ln() + + a.log(a) + + a.log10() + + a.log2() + + a.powi(8) + + a.powf(a) + + a.round() + + a.sin() + + a.abs() + + a.signum() + + a.floor() + + a.ceil() + + a.trunc() + + a.sqrt() + + (a % (b as f32))) as f64) + + (b + 2.0f64.powf(a as f64)) +}