From df7bcc4e036259cdbf911cfc634b29ecfcff874f Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sat, 4 Aug 2018 11:25:29 -0700 Subject: [PATCH] Migrate wasm-bindgen `char` test to `wasm` --- tests/all/char.rs | 66 ---------------------------------------------- tests/all/main.rs | 1 - tests/wasm/char.js | 23 ++++++++++++++++ tests/wasm/char.rs | 29 ++++++++++++++++++++ tests/wasm/main.rs | 1 + 5 files changed, 53 insertions(+), 67 deletions(-) delete mode 100644 tests/all/char.rs create mode 100644 tests/wasm/char.js create mode 100644 tests/wasm/char.rs diff --git a/tests/all/char.rs b/tests/all/char.rs deleted file mode 100644 index a8392fc02..000000000 --- a/tests/all/char.rs +++ /dev/null @@ -1,66 +0,0 @@ -use super::project; - -#[test] -fn works() { - project() - .file( - "src/lib.rs", - r#" - #![feature(use_extern_macros)] - - extern crate wasm_bindgen; - - use wasm_bindgen::prelude::*; - - #[wasm_bindgen(module = "./test")] - extern { - fn js_parrot(c: char) -> char; - } - - #[wasm_bindgen] - pub fn single_char() -> char { 'a' } - #[wasm_bindgen] - pub fn wide_char() -> char { '💩' } - - #[wasm_bindgen] - pub fn parrot(c: char) -> char { c } - - #[wasm_bindgen] - pub fn short_test(a: char) { assert_eq!(a, 'a'); } - #[wasm_bindgen] - pub fn wide_test(p: char) { assert_eq!(p, '💩'); } - - #[wasm_bindgen] - pub fn char_round(c: char)-> char { js_parrot(c) } - "#, - ) - .file( - "test.js", - r#" - import * as wasm from './out'; - - function assertEq(a, b) { - console.log(a, '?=', b); - if (a === b) - return; - throw new Error('not equal'); - } - - export function test() { - assertEq(wasm.single_char(), 'a'); - assertEq(wasm.wide_char(), '💩'); - assertEq(wasm.parrot('Ղ'), 'Ղ'); - assertEq(wasm.parrot('ҝ'), 'ҝ'); - assertEq(wasm.parrot('Δ'), 'Δ'); - assertEq(wasm.parrot('䉨'), '䉨'); - assertEq(wasm.char_round('a'), 'a'); - assertEq(wasm.char_round('㊻'), '㊻'); - wasm.short_test('a'); - wasm.wide_test('💩'); - } - - export function js_parrot(a) { return a; } - "#, - ) - .test(); -} diff --git a/tests/all/main.rs b/tests/all/main.rs index ea2f150bd..4f7bc2f72 100644 --- a/tests/all/main.rs +++ b/tests/all/main.rs @@ -4,7 +4,6 @@ extern crate wasm_bindgen_test_project_builder as project_builder; use project_builder::{project, run}; -mod char; mod classes; mod closures; mod comments; diff --git a/tests/wasm/char.js b/tests/wasm/char.js new file mode 100644 index 000000000..314044fb4 --- /dev/null +++ b/tests/wasm/char.js @@ -0,0 +1,23 @@ +const wasm = require('wasm-bindgen-test.js'); + +function assertEq(a, b) { + console.log(a, '?=', b); + if (a === b) + return; + throw new Error('not equal'); +} + +exports.char_works = function() { + assertEq(wasm.char_single_char(), 'a'); + assertEq(wasm.char_wide_char(), '💩'); + assertEq(wasm.char_parrot('Ղ'), 'Ղ'); + assertEq(wasm.char_parrot('ҝ'), 'ҝ'); + assertEq(wasm.char_parrot('Δ'), 'Δ'); + assertEq(wasm.char_parrot('䉨'), '䉨'); + assertEq(wasm.char_round('a'), 'a'); + assertEq(wasm.char_round('㊻'), '㊻'); + wasm.char_short_test('a'); + wasm.char_wide_test('💩'); +}; + +exports.js_parrot = function(a) { return a; }; diff --git a/tests/wasm/char.rs b/tests/wasm/char.rs new file mode 100644 index 000000000..57b5e565e --- /dev/null +++ b/tests/wasm/char.rs @@ -0,0 +1,29 @@ +use wasm_bindgen_test::*; +use wasm_bindgen::prelude::*; + +#[wasm_bindgen(module = "tests/wasm/char.js", version = "*")] +extern { + fn char_works(); + fn js_parrot(c: char) -> char; +} + +#[wasm_bindgen_test] +fn works() { + char_works(); +} + +#[wasm_bindgen] +pub fn char_single_char() -> char { 'a' } +#[wasm_bindgen] +pub fn char_wide_char() -> char { '💩' } + +#[wasm_bindgen] +pub fn char_parrot(c: char) -> char { c } + +#[wasm_bindgen] +pub fn char_short_test(a: char) { assert_eq!(a, 'a'); } +#[wasm_bindgen] +pub fn char_wide_test(p: char) { assert_eq!(p, '💩'); } + +#[wasm_bindgen] +pub fn char_round(c: char)-> char { js_parrot(c) } diff --git a/tests/wasm/main.rs b/tests/wasm/main.rs index 268909b25..3c7291ac9 100644 --- a/tests/wasm/main.rs +++ b/tests/wasm/main.rs @@ -5,5 +5,6 @@ extern crate wasm_bindgen_test; extern crate wasm_bindgen; pub mod api; +pub mod char; pub mod option; pub mod optional_primitives;