mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-08-01 04:21:55 +00:00
Migrate most import tests to wasm
This commit is contained in:
@@ -1,443 +1,39 @@
|
||||
use super::project;
|
||||
|
||||
#[test]
|
||||
fn simple() {
|
||||
project()
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(use_extern_macros)]
|
||||
fn unused_imports_not_generated() {
|
||||
let mut project = project();
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
fn foo(s: &str);
|
||||
fn another(a: u32) -> i32;
|
||||
fn take_and_return_bool(a: bool) -> bool;
|
||||
fn return_object() -> JsValue;
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn bar(s: &str) {
|
||||
foo(s);
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn another_thunk(a: u32) -> i32 {
|
||||
another(a)
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn bool_thunk(a: bool) -> bool {
|
||||
take_and_return_bool(a)
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn get_the_object() -> JsValue {
|
||||
return_object()
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.js",
|
||||
r#"
|
||||
import * as wasm from "./out";
|
||||
import * as assert from "assert";
|
||||
|
||||
let ARG = null;
|
||||
let ANOTHER_ARG = null;
|
||||
let SYM = Symbol('a');
|
||||
|
||||
export function foo(s) {
|
||||
assert.strictEqual(ARG, null);
|
||||
assert.strictEqual(s, "foo");
|
||||
ARG = s;
|
||||
}
|
||||
export function another(s) {
|
||||
assert.strictEqual(ANOTHER_ARG, null);
|
||||
assert.strictEqual(s, 21);
|
||||
ANOTHER_ARG = s;
|
||||
return 35;
|
||||
}
|
||||
export function take_and_return_bool(s) {
|
||||
return s;
|
||||
}
|
||||
export function return_object() {
|
||||
return SYM;
|
||||
}
|
||||
|
||||
export function test() {
|
||||
assert.strictEqual(ARG, null);
|
||||
wasm.bar("foo");
|
||||
assert.strictEqual(ARG, "foo");
|
||||
|
||||
assert.strictEqual(ANOTHER_ARG, null);
|
||||
assert.strictEqual(wasm.another_thunk(21), 35);
|
||||
assert.strictEqual(ANOTHER_ARG, 21);
|
||||
|
||||
assert.strictEqual(wasm.bool_thunk(true), true);
|
||||
assert.strictEqual(wasm.bool_thunk(false), false);
|
||||
|
||||
assert.strictEqual(wasm.get_the_object(), SYM);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unused() {
|
||||
project()
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(use_extern_macros)]
|
||||
#![allow(dead_code)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
fn debug_print(s: &str);
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn bar() {}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.js",
|
||||
r#"
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function debug_print() {}
|
||||
|
||||
export function test() {
|
||||
wasm.bar();
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn string_ret() {
|
||||
project()
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(use_extern_macros)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
fn foo() -> String;
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn run() {
|
||||
assert_eq!(foo(), "bar");
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.js",
|
||||
r#"
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function foo() {
|
||||
return 'bar';
|
||||
}
|
||||
|
||||
export function test() {
|
||||
wasm.run();
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn strings() {
|
||||
project()
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(use_extern_macros)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
fn foo(a: String) -> String;
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn bar(a: &str) -> String {
|
||||
foo(a.to_string())
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn bar2(a: String) -> String {
|
||||
foo(a)
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.js",
|
||||
r#"
|
||||
import * as wasm from "./out";
|
||||
import * as assert from "assert";
|
||||
|
||||
export function foo(a) {
|
||||
return a + 'b';
|
||||
}
|
||||
|
||||
export function test() {
|
||||
assert.strictEqual(wasm.bar('a'), 'ab');
|
||||
assert.strictEqual(wasm.bar2('a'), 'ab');
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn exceptions() {
|
||||
project()
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(use_extern_macros)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
fn foo();
|
||||
fn bar();
|
||||
#[wasm_bindgen(catch)]
|
||||
fn baz() -> Result<(), JsValue>;
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn run() {
|
||||
foo();
|
||||
bar();
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn run2() {
|
||||
assert!(baz().is_err());
|
||||
bar();
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.js",
|
||||
r#"
|
||||
import { run, run2 } from "./out";
|
||||
import * as assert from "assert";
|
||||
|
||||
let called = false;
|
||||
|
||||
export function foo() {
|
||||
throw new Error('error!');
|
||||
}
|
||||
|
||||
export function baz() {
|
||||
throw new Error('error2');
|
||||
}
|
||||
|
||||
export function bar() {
|
||||
called = true;
|
||||
}
|
||||
|
||||
export function test() {
|
||||
assert.throws(run, /error!/);
|
||||
assert.strictEqual(called, false);
|
||||
run2();
|
||||
assert.strictEqual(called, true);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn exn_caught() {
|
||||
project()
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(use_extern_macros)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
#[wasm_bindgen(catch)]
|
||||
fn foo() -> Result<(), JsValue>;
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn run() -> JsValue {
|
||||
foo().unwrap_err()
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.js",
|
||||
r#"
|
||||
import { run } from "./out";
|
||||
import * as assert from "assert";
|
||||
|
||||
export function foo() {
|
||||
throw new Error('error!');
|
||||
}
|
||||
|
||||
export function test() {
|
||||
const obj = run();
|
||||
assert.strictEqual(obj instanceof Error, true);
|
||||
assert.strictEqual(obj.message, 'error!');
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn free_imports() {
|
||||
project()
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(use_extern_macros)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen]
|
||||
extern {
|
||||
fn parseInt(a: &str) -> u32;
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn run() {
|
||||
assert_eq!(parseInt("3"), 3);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.js",
|
||||
r#"
|
||||
import { run } from "./out";
|
||||
|
||||
export function test() {
|
||||
run();
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn import_a_field() {
|
||||
project()
|
||||
project
|
||||
.debug(false)
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(use_extern_macros)]
|
||||
.file("src/lib.rs", r#"
|
||||
#![feature(use_extern_macros)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
static IMPORT: JsValue;
|
||||
}
|
||||
#[wasm_bindgen]
|
||||
extern {
|
||||
pub fn foo();
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn run() {
|
||||
assert_eq!(IMPORT.as_f64(), Some(1.0));
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.js",
|
||||
r#"
|
||||
import { run } from "./out";
|
||||
#[wasm_bindgen]
|
||||
pub fn run() {
|
||||
}
|
||||
"#)
|
||||
.file("test.js", r#"
|
||||
import { run } from "./out";
|
||||
|
||||
export const IMPORT = 1.0;
|
||||
|
||||
export function test() {
|
||||
run();
|
||||
}
|
||||
"#,
|
||||
)
|
||||
export function test() {
|
||||
run();
|
||||
}
|
||||
"#)
|
||||
.test();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rename() {
|
||||
project()
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(use_extern_macros)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
#[wasm_bindgen(js_name = baz)]
|
||||
fn foo();
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn run() {
|
||||
foo();
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.js",
|
||||
r#"
|
||||
import * as wasm from "./out";
|
||||
import * as assert from "assert";
|
||||
|
||||
let called = false;
|
||||
|
||||
export function baz() {
|
||||
called = true;
|
||||
}
|
||||
|
||||
export function test() {
|
||||
wasm.run();
|
||||
assert.strictEqual(called, true);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
let contents = project.read_js();
|
||||
assert!(contents.contains("run"), "didn't find `run` in {}", contents);
|
||||
assert!(!contents.contains("foo"), "found `foo` in {}", contents);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -490,218 +86,3 @@ fn versions() {
|
||||
)
|
||||
.test();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn underscore_pattern() {
|
||||
project()
|
||||
.debug(false)
|
||||
.file("src/lib.rs", r#"
|
||||
#![feature(use_extern_macros)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
fn foo(_: u8);
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn run() {
|
||||
foo(1);
|
||||
}
|
||||
"#)
|
||||
.file("test.js", r#"
|
||||
import { run } from "./out";
|
||||
|
||||
export function foo(_a) {
|
||||
}
|
||||
|
||||
export function test() {
|
||||
run();
|
||||
}
|
||||
"#)
|
||||
.test();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rust_keyword() {
|
||||
project()
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(use_extern_macros)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
#[wasm_bindgen(js_name = self)]
|
||||
fn foo() -> u32;
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn run() {
|
||||
assert_eq!(foo(), 2);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.js",
|
||||
r#"
|
||||
import { run } from "./out";
|
||||
|
||||
export function self() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
export function test() {
|
||||
run();
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rust_keyword2() {
|
||||
project()
|
||||
.debug(false)
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(use_extern_macros)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
pub type bar;
|
||||
#[wasm_bindgen(js_namespace = bar, js_name = foo)]
|
||||
static FOO: JsValue;
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn run() {
|
||||
assert_eq!(FOO.as_f64(), Some(3.0));
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.js",
|
||||
r#"
|
||||
import { run } from "./out";
|
||||
|
||||
export const bar = {
|
||||
foo: 3,
|
||||
};
|
||||
|
||||
export function test() {
|
||||
run();
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn custom_type() {
|
||||
project()
|
||||
.debug(false)
|
||||
.file("src/lib.rs", r#"
|
||||
#![feature(use_extern_macros)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
fn foo(f: Foo) -> Foo;
|
||||
fn bad2() -> Foo;
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub struct Foo(());
|
||||
|
||||
#[wasm_bindgen]
|
||||
impl Foo {
|
||||
pub fn touch(&self) {
|
||||
panic!()
|
||||
}
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn run() {
|
||||
foo(Foo(()));
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn bad() {
|
||||
bad2();
|
||||
}
|
||||
"#)
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import { run, Foo, bad } from "./out";
|
||||
|
||||
let VAL = null;
|
||||
|
||||
export function foo(f) {
|
||||
VAL = f;
|
||||
return f;
|
||||
}
|
||||
|
||||
export function bad2() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
export function test() {
|
||||
run();
|
||||
assert.throws(() => VAL.touch(), /Attempt to use a moved value/);
|
||||
assert.throws(bad, /expected value of type Foo/);
|
||||
}
|
||||
"#)
|
||||
.test();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unused_imports_not_generated() {
|
||||
let mut project = project();
|
||||
|
||||
project
|
||||
.debug(false)
|
||||
.file("src/lib.rs", r#"
|
||||
#![feature(use_extern_macros)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen]
|
||||
extern {
|
||||
pub fn foo();
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn run() {
|
||||
}
|
||||
"#)
|
||||
.file("test.js", r#"
|
||||
import { run } from "./out";
|
||||
|
||||
export function test() {
|
||||
run();
|
||||
}
|
||||
"#)
|
||||
.test();
|
||||
|
||||
let contents = project.read_js();
|
||||
assert!(contents.contains("run"), "didn't find `run` in {}", contents);
|
||||
assert!(!contents.contains("foo"), "found `foo` in {}", contents);
|
||||
}
|
||||
|
@@ -6,8 +6,8 @@ use project_builder::{project, run};
|
||||
|
||||
mod comments;
|
||||
mod dependencies;
|
||||
mod imports;
|
||||
mod js_objects;
|
||||
mod imports;
|
||||
mod node;
|
||||
mod non_debug;
|
||||
mod non_wasm;
|
||||
|
92
tests/wasm/imports.js
Normal file
92
tests/wasm/imports.js
Normal file
@@ -0,0 +1,92 @@
|
||||
const assert = require('assert');
|
||||
const wasm = require('wasm-bindgen-test');
|
||||
|
||||
let ARG = null;
|
||||
let ANOTHER_ARG = null;
|
||||
let SYM = Symbol('a');
|
||||
|
||||
exports.simple_foo = function(s) {
|
||||
assert.strictEqual(ARG, null);
|
||||
assert.strictEqual(s, "foo");
|
||||
ARG = s;
|
||||
};
|
||||
|
||||
exports.simple_another = function(s) {
|
||||
assert.strictEqual(ANOTHER_ARG, null);
|
||||
assert.strictEqual(s, 21);
|
||||
ANOTHER_ARG = s;
|
||||
return 35;
|
||||
};
|
||||
|
||||
exports.simple_take_and_return_bool = function(s) {
|
||||
return s;
|
||||
};
|
||||
exports.simple_return_object = function() {
|
||||
return SYM;
|
||||
};
|
||||
exports.test_simple = function() {
|
||||
assert.strictEqual(ARG, null);
|
||||
wasm.simple_take_str("foo");
|
||||
assert.strictEqual(ARG, "foo");
|
||||
|
||||
assert.strictEqual(ANOTHER_ARG, null);
|
||||
assert.strictEqual(wasm.simple_another_thunk(21), 35);
|
||||
assert.strictEqual(ANOTHER_ARG, 21);
|
||||
|
||||
assert.strictEqual(wasm.simple_bool_thunk(true), true);
|
||||
assert.strictEqual(wasm.simple_bool_thunk(false), false);
|
||||
|
||||
assert.strictEqual(wasm.simple_get_the_object(), SYM);
|
||||
};
|
||||
|
||||
exports.return_string = function() {
|
||||
return 'bar';
|
||||
};
|
||||
|
||||
exports.take_and_ret_string = function(a) {
|
||||
return a + 'b';
|
||||
};
|
||||
|
||||
exports.exceptions_throw = function() {
|
||||
throw new Error('error!');
|
||||
};
|
||||
exports.exceptions_throw2 = function() {
|
||||
throw new Error('error2');
|
||||
};
|
||||
exports.test_exception_propagates = function() {
|
||||
assert.throws(wasm.exceptions_propagate, /error!/);
|
||||
};
|
||||
|
||||
exports.assert_valid_error = function(obj) {
|
||||
assert.strictEqual(obj instanceof Error, true);
|
||||
assert.strictEqual(obj.message, 'error2');
|
||||
};
|
||||
|
||||
exports.IMPORT = 1.0;
|
||||
|
||||
exports.return_three = function() { return 3; };
|
||||
|
||||
exports.underscore = function(x) {};
|
||||
|
||||
exports.self = function() { return 2; };
|
||||
|
||||
exports.bar = { foo: 3 };
|
||||
|
||||
let CUSTOM_TYPE = null;
|
||||
|
||||
exports.take_custom_type = function(f) {
|
||||
CUSTOM_TYPE = f;
|
||||
return f;
|
||||
};
|
||||
|
||||
exports.custom_type_return_2 = function() {
|
||||
return 2;
|
||||
};
|
||||
|
||||
exports.touch_custom_type = function() {
|
||||
assert.throws(() => CUSTOM_TYPE.touch(), /Attempt to use a moved value/);
|
||||
};
|
||||
|
||||
exports.interpret_2_as_custom_type = function() {
|
||||
assert.throws(wasm.interpret_2_as_custom_type, /expected value of type CustomType/);
|
||||
};
|
155
tests/wasm/imports.rs
Normal file
155
tests/wasm/imports.rs
Normal file
@@ -0,0 +1,155 @@
|
||||
use wasm_bindgen_test::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen(module = "tests/wasm/imports.js", version = "*")]
|
||||
extern {
|
||||
fn test_simple();
|
||||
|
||||
fn simple_foo(s: &str);
|
||||
fn simple_another(a: u32) -> i32;
|
||||
fn simple_take_and_return_bool(a: bool) -> bool;
|
||||
fn simple_return_object() -> JsValue;
|
||||
#[allow(dead_code)]
|
||||
fn missing_symbol(s: &str);
|
||||
fn return_string() -> String;
|
||||
fn take_and_ret_string(s: String) -> String;
|
||||
#[wasm_bindgen(js_name = take_and_ret_string)]
|
||||
fn take_and_ret_string2(s: &str) -> String;
|
||||
|
||||
fn exceptions_throw();
|
||||
#[wasm_bindgen(catch)]
|
||||
fn exceptions_throw2() -> Result<(), JsValue>;
|
||||
fn test_exception_propagates();
|
||||
|
||||
fn assert_valid_error(val: JsValue);
|
||||
|
||||
static IMPORT: JsValue;
|
||||
|
||||
#[wasm_bindgen(js_name = return_three)]
|
||||
fn rust_name_for_return_three() -> u32;
|
||||
|
||||
fn underscore(_: u8);
|
||||
|
||||
#[wasm_bindgen(js_name = self)]
|
||||
fn js_function_named_rust_keyword() -> u32;
|
||||
|
||||
type bar;
|
||||
#[wasm_bindgen(js_namespace = bar, js_name = foo)]
|
||||
static FOO: JsValue;
|
||||
|
||||
fn take_custom_type(f: CustomType) -> CustomType;
|
||||
fn touch_custom_type();
|
||||
fn custom_type_return_2() -> CustomType;
|
||||
#[wasm_bindgen(js_name = interpret_2_as_custom_type)]
|
||||
fn js_interpret_2_as_custom_type();
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
extern {
|
||||
fn parseInt(a: &str) -> u32;
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn simple() {
|
||||
test_simple();
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn simple_take_str(s: &str) {
|
||||
simple_foo(s);
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn simple_another_thunk(a: u32) -> i32 {
|
||||
simple_another(a)
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn simple_bool_thunk(a: bool) -> bool {
|
||||
simple_take_and_return_bool(a)
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn simple_get_the_object() -> JsValue {
|
||||
simple_return_object()
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn string_ret() {
|
||||
assert_eq!(return_string(), "bar");
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn strings() {
|
||||
assert_eq!(take_and_ret_string(String::from("a")), "ab");
|
||||
assert_eq!(take_and_ret_string2("b"), "bb");
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn exceptions() {
|
||||
test_exception_propagates();
|
||||
assert!(exceptions_throw2().is_err());
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn exceptions_propagate() {
|
||||
exceptions_throw();
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn exn_caught() {
|
||||
assert_valid_error(exceptions_throw2().unwrap_err());
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn free_imports() {
|
||||
assert_eq!(parseInt("3"), 3);
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn import_a_field() {
|
||||
assert_eq!(IMPORT.as_f64(), Some(1.0));
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn rename() {
|
||||
assert_eq!(rust_name_for_return_three(), 3);
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn underscore_pattern() {
|
||||
underscore(2);
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn rust_keyword() {
|
||||
assert_eq!(js_function_named_rust_keyword(), 2);
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn rust_keyword2() {
|
||||
assert_eq!(FOO.as_f64(), Some(3.0));
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn custom_type() {
|
||||
take_custom_type(CustomType(()));
|
||||
touch_custom_type();
|
||||
js_interpret_2_as_custom_type();
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn interpret_2_as_custom_type() {
|
||||
custom_type_return_2();
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub struct CustomType(());
|
||||
|
||||
#[wasm_bindgen]
|
||||
impl CustomType {
|
||||
pub fn touch(&self) {
|
||||
panic!()
|
||||
}
|
||||
}
|
||||
|
@@ -10,6 +10,7 @@ pub mod classes;
|
||||
pub mod closures;
|
||||
pub mod duplicates;
|
||||
pub mod enums;
|
||||
pub mod imports;
|
||||
pub mod import_class;
|
||||
pub mod js_objects;
|
||||
pub mod math;
|
||||
|
Reference in New Issue
Block a user