2018-04-10 01:32:06 +03:00
|
|
|
use super::project;
|
2018-03-07 22:57:51 +03:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn dependencies_work() {
|
2018-04-10 01:32:06 +03:00
|
|
|
project()
|
2018-03-07 22:57:51 +03:00
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2018-07-17 17:11:30 +03:00
|
|
|
#![feature(use_extern_macros, wasm_custom_section, wasm_import_module)]
|
2018-07-05 06:37:09 +03:00
|
|
|
extern crate wasm_bindgen;
|
|
|
|
extern crate dependency;
|
|
|
|
use wasm_bindgen::prelude::*;
|
2018-03-07 22:57:51 +03:00
|
|
|
|
2018-07-05 06:37:09 +03:00
|
|
|
#[wasm_bindgen]
|
|
|
|
pub fn return_dep_ty(x: f64) -> dependency::Foo {
|
|
|
|
dependency::Foo(x)
|
|
|
|
}
|
2018-03-07 22:57:51 +03:00
|
|
|
|
2018-07-05 06:37:09 +03:00
|
|
|
#[wasm_bindgen]
|
|
|
|
pub fn takes_own_dep_ty(foo: dependency::Foo) -> f64 {
|
|
|
|
foo.0
|
|
|
|
}
|
2018-03-07 22:57:51 +03:00
|
|
|
|
2018-07-05 06:37:09 +03:00
|
|
|
#[wasm_bindgen]
|
|
|
|
pub fn takes_ref_dep_ty(foo: &dependency::Foo) -> f64 {
|
|
|
|
foo.0
|
|
|
|
}
|
2018-03-07 22:57:51 +03:00
|
|
|
|
2018-07-05 06:37:09 +03:00
|
|
|
#[wasm_bindgen]
|
|
|
|
pub fn takes_mut_dep_ty(foo: &mut dependency::Foo, x: f64) {
|
|
|
|
foo.0 = x;
|
|
|
|
}
|
|
|
|
"#,
|
2018-03-07 22:57:51 +03:00
|
|
|
)
|
|
|
|
.add_local_dependency("dependency", "vendor/dependency")
|
|
|
|
.file(
|
|
|
|
"vendor/dependency/Cargo.toml",
|
|
|
|
&format!(
|
|
|
|
r#"
|
2018-07-05 06:37:09 +03:00
|
|
|
[package]
|
|
|
|
name = "dependency"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-07 22:57:51 +03:00
|
|
|
|
2018-07-05 06:37:09 +03:00
|
|
|
[dependencies]
|
|
|
|
wasm-bindgen = {{ path = '{}' }}
|
|
|
|
"#,
|
2018-03-07 22:57:51 +03:00
|
|
|
env!("CARGO_MANIFEST_DIR")
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"vendor/dependency/src/lib.rs",
|
|
|
|
r#"
|
2018-07-17 17:11:30 +03:00
|
|
|
#![feature(use_extern_macros, wasm_custom_section, wasm_import_module)]
|
2018-07-05 06:37:09 +03:00
|
|
|
extern crate wasm_bindgen;
|
|
|
|
use wasm_bindgen::prelude::*;
|
2018-03-07 22:57:51 +03:00
|
|
|
|
2018-07-05 06:37:09 +03:00
|
|
|
#[wasm_bindgen]
|
|
|
|
pub struct Foo(pub f64);
|
2018-03-07 22:57:51 +03:00
|
|
|
|
2018-07-05 06:37:09 +03:00
|
|
|
#[wasm_bindgen]
|
|
|
|
impl Foo {
|
|
|
|
pub fn new(x: f64) -> Foo { Foo(x) }
|
|
|
|
pub fn get(&self) -> f64 { self.0 }
|
|
|
|
}
|
|
|
|
"#,
|
2018-03-07 22:57:51 +03:00
|
|
|
)
|
|
|
|
.file(
|
2018-07-05 06:37:09 +03:00
|
|
|
"test.js",
|
2018-03-07 22:57:51 +03:00
|
|
|
r#"
|
2018-07-05 06:37:09 +03:00
|
|
|
import * as assert from "assert";
|
|
|
|
import * as wasm from "./out";
|
2018-03-07 22:57:51 +03:00
|
|
|
|
2018-07-05 06:37:09 +03:00
|
|
|
export function test() {
|
|
|
|
const foo = wasm.return_dep_ty(42);
|
|
|
|
assert.strictEqual(foo.get(), 42);
|
2018-03-07 22:57:51 +03:00
|
|
|
|
2018-07-05 06:37:09 +03:00
|
|
|
const x = wasm.takes_ref_dep_ty(foo);
|
|
|
|
assert.strictEqual(x, 42);
|
2018-03-07 22:57:51 +03:00
|
|
|
|
2018-07-05 06:37:09 +03:00
|
|
|
const y = 1337;
|
|
|
|
wasm.takes_mut_dep_ty(foo, y);
|
|
|
|
assert.strictEqual(foo.get(), y);
|
2018-03-07 22:57:51 +03:00
|
|
|
|
2018-07-05 06:37:09 +03:00
|
|
|
const z = wasm.takes_own_dep_ty(foo);
|
|
|
|
assert.strictEqual(z, y);
|
|
|
|
assert.strictEqual(foo.ptr, 0);
|
|
|
|
}
|
|
|
|
"#,
|
2018-03-07 22:57:51 +03:00
|
|
|
)
|
|
|
|
.test();
|
|
|
|
}
|
2018-07-18 02:24:48 +03:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn same_api_two_crates() {
|
|
|
|
project()
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
|
|
|
#![feature(use_extern_macros, wasm_custom_section, wasm_import_module)]
|
|
|
|
extern crate wasm_bindgen;
|
|
|
|
extern crate a;
|
|
|
|
extern crate b;
|
|
|
|
|
|
|
|
use wasm_bindgen::prelude::*;
|
|
|
|
|
|
|
|
#[wasm_bindgen(module = "./foo")]
|
|
|
|
extern {
|
|
|
|
fn assert_next_undefined();
|
|
|
|
fn assert_next_ten();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen]
|
|
|
|
pub fn test() {
|
|
|
|
assert_next_undefined();
|
|
|
|
a::test();
|
|
|
|
assert_next_ten();
|
|
|
|
b::test();
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"foo.js",
|
|
|
|
r#"
|
|
|
|
import { strictEqual } from "assert";
|
|
|
|
|
|
|
|
let next = null;
|
|
|
|
|
|
|
|
export function assert_next_undefined() {
|
|
|
|
next = undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function assert_next_ten() {
|
|
|
|
next = 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function foo(a) {
|
|
|
|
console.log(a, next);
|
|
|
|
strictEqual(a, next);
|
|
|
|
next = null;
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.add_local_dependency("a", "a")
|
|
|
|
.file(
|
|
|
|
"a/Cargo.toml",
|
|
|
|
&format!(r#"
|
|
|
|
[package]
|
|
|
|
name = 'a'
|
|
|
|
version = '0.0.0'
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
wasm-bindgen = {{ path = '{}' }}
|
|
|
|
"#,
|
|
|
|
env!("CARGO_MANIFEST_DIR")
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"a/src/lib.rs",
|
|
|
|
"
|
|
|
|
#![feature(use_extern_macros, wasm_custom_section, wasm_import_module)]
|
|
|
|
extern crate wasm_bindgen;
|
|
|
|
|
|
|
|
use wasm_bindgen::prelude::*;
|
|
|
|
|
|
|
|
#[wasm_bindgen(module = \"./foo\")]
|
|
|
|
extern {
|
|
|
|
fn foo();
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn test() {
|
|
|
|
foo();
|
|
|
|
}
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.add_local_dependency("b", "b")
|
|
|
|
.file(
|
|
|
|
"b/Cargo.toml",
|
|
|
|
&format!(r#"
|
|
|
|
[package]
|
|
|
|
name = 'b'
|
|
|
|
version = '0.0.0'
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
wasm-bindgen = {{ path = '{}' }}
|
|
|
|
"#,
|
|
|
|
env!("CARGO_MANIFEST_DIR")
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"b/src/lib.rs",
|
|
|
|
"
|
|
|
|
#![feature(use_extern_macros, wasm_custom_section, wasm_import_module)]
|
|
|
|
extern crate wasm_bindgen;
|
|
|
|
|
|
|
|
use wasm_bindgen::prelude::*;
|
|
|
|
|
|
|
|
#[wasm_bindgen(module = \"./foo\")]
|
|
|
|
extern {
|
|
|
|
fn foo(x: u32);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn test() {
|
|
|
|
foo(10);
|
|
|
|
}
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.test();
|
|
|
|
}
|