wasm-bindgen/tests/all/char.rs
Alex Crichton 906cd7adcc Remove usage of wasm_import_module feature
This is now stabilized! Also tweak usage of it to the stable version.
2018-07-21 19:00:40 -07:00

67 lines
1.8 KiB
Rust

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();
}