mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-12-26 11:34:22 +03:00
Migrate wasm-bindgen char
test to wasm
This commit is contained in:
parent
5d4c135c31
commit
df7bcc4e03
@ -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();
|
||||
}
|
@ -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;
|
||||
|
23
tests/wasm/char.js
Normal file
23
tests/wasm/char.js
Normal file
@ -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; };
|
29
tests/wasm/char.rs
Normal file
29
tests/wasm/char.rs
Normal file
@ -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) }
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user