2018-04-09 15:32:06 -07:00
|
|
|
use super::project;
|
2017-12-19 09:25:41 -08:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn simple() {
|
2018-04-09 15:32:06 -07:00
|
|
|
project()
|
2017-12-19 09:25:41 -08:00
|
|
|
.file("src/lib.rs", r#"
|
2018-03-14 14:33:53 -07:00
|
|
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
2017-12-19 09:25:41 -08:00
|
|
|
|
|
|
|
extern crate wasm_bindgen;
|
|
|
|
|
|
|
|
use wasm_bindgen::prelude::*;
|
|
|
|
|
2018-02-07 16:41:33 -08:00
|
|
|
#[wasm_bindgen(module = "./test")]
|
|
|
|
extern {
|
|
|
|
fn foo(s: &JsValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen]
|
2018-03-05 23:25:15 +01:00
|
|
|
pub fn bar(s: &JsValue) {
|
2018-02-07 16:41:33 -08:00
|
|
|
foo(s);
|
2017-12-19 09:25:41 -08:00
|
|
|
}
|
|
|
|
"#)
|
2017-12-19 19:06:48 -08:00
|
|
|
.file("test.ts", r#"
|
2018-01-29 21:20:38 -08:00
|
|
|
import * as wasm from "./out";
|
2017-12-19 09:25:41 -08:00
|
|
|
import * as assert from "assert";
|
|
|
|
|
2017-12-19 19:06:48 -08:00
|
|
|
let ARG: string | null = null;
|
2017-12-19 09:25:41 -08:00
|
|
|
|
2018-01-29 21:20:38 -08:00
|
|
|
export function foo(s: any): void {
|
|
|
|
assert.strictEqual(ARG, null);
|
|
|
|
ARG = s;
|
|
|
|
}
|
2017-12-19 09:25:41 -08:00
|
|
|
|
2018-01-29 21:20:38 -08:00
|
|
|
export function test() {
|
2017-12-19 09:25:41 -08:00
|
|
|
assert.strictEqual(ARG, null);
|
2018-01-29 21:20:38 -08:00
|
|
|
let sym = (Symbol as any)('test');
|
2017-12-19 09:25:41 -08:00
|
|
|
wasm.bar(sym);
|
|
|
|
assert.strictEqual(ARG, sym);
|
|
|
|
}
|
|
|
|
"#)
|
|
|
|
.test();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn owned() {
|
2018-04-09 15:32:06 -07:00
|
|
|
project()
|
2017-12-19 09:25:41 -08:00
|
|
|
.file("src/lib.rs", r#"
|
2018-03-14 14:33:53 -07:00
|
|
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
2017-12-19 09:25:41 -08:00
|
|
|
|
|
|
|
extern crate wasm_bindgen;
|
|
|
|
|
|
|
|
use wasm_bindgen::prelude::*;
|
|
|
|
|
2018-02-07 16:41:33 -08:00
|
|
|
#[wasm_bindgen(module = "./test")]
|
|
|
|
extern {
|
|
|
|
fn foo(s: JsValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen]
|
2018-03-05 23:25:15 +01:00
|
|
|
pub fn bar(s: JsValue) {
|
2018-02-07 16:41:33 -08:00
|
|
|
foo(s);
|
2017-12-19 09:25:41 -08:00
|
|
|
}
|
|
|
|
"#)
|
2017-12-19 19:06:48 -08:00
|
|
|
.file("test.ts", r#"
|
2018-01-29 21:20:38 -08:00
|
|
|
import * as wasm from "./out";
|
2017-12-19 09:25:41 -08:00
|
|
|
import * as assert from "assert";
|
|
|
|
|
2018-01-29 21:20:38 -08:00
|
|
|
let ARG: any = null;
|
2017-12-19 09:25:41 -08:00
|
|
|
|
2018-01-29 21:20:38 -08:00
|
|
|
export function foo(s: any): void {
|
|
|
|
assert.strictEqual(ARG, null);
|
|
|
|
ARG = s;
|
|
|
|
}
|
2017-12-19 09:25:41 -08:00
|
|
|
|
2018-01-29 21:20:38 -08:00
|
|
|
export function test() {
|
2017-12-19 09:25:41 -08:00
|
|
|
assert.strictEqual(ARG, null);
|
2018-01-29 21:20:38 -08:00
|
|
|
let sym = (Symbol as any)('test');
|
2017-12-19 09:25:41 -08:00
|
|
|
wasm.bar(sym);
|
|
|
|
assert.strictEqual(ARG, sym);
|
|
|
|
}
|
|
|
|
"#)
|
|
|
|
.test();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn clone() {
|
2018-04-09 15:32:06 -07:00
|
|
|
project()
|
2017-12-19 09:25:41 -08:00
|
|
|
.file("src/lib.rs", r#"
|
2018-03-14 14:33:53 -07:00
|
|
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
2017-12-19 09:25:41 -08:00
|
|
|
|
|
|
|
extern crate wasm_bindgen;
|
|
|
|
|
|
|
|
use wasm_bindgen::prelude::*;
|
|
|
|
|
2018-02-07 16:41:33 -08:00
|
|
|
#[wasm_bindgen(module = "./test")]
|
|
|
|
extern {
|
|
|
|
fn foo1(s: JsValue);
|
|
|
|
fn foo2(s: &JsValue);
|
|
|
|
fn foo3(s: JsValue);
|
|
|
|
fn foo4(s: &JsValue);
|
|
|
|
fn foo5(s: JsValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen]
|
2018-03-05 23:25:15 +01:00
|
|
|
pub fn bar(s: JsValue) {
|
2018-02-07 16:41:33 -08:00
|
|
|
foo1(s.clone());
|
|
|
|
foo2(&s);
|
|
|
|
foo3(s.clone());
|
|
|
|
foo4(&s);
|
|
|
|
foo5(s);
|
2017-12-19 09:25:41 -08:00
|
|
|
}
|
|
|
|
"#)
|
2017-12-19 19:06:48 -08:00
|
|
|
.file("test.ts", r#"
|
2018-01-29 21:20:38 -08:00
|
|
|
import * as wasm from "./out";
|
2017-12-19 09:25:41 -08:00
|
|
|
import * as assert from "assert";
|
|
|
|
|
2018-01-29 21:20:38 -08:00
|
|
|
let ARG = (Symbol as any)('test');
|
2017-12-19 09:25:41 -08:00
|
|
|
|
2018-01-29 21:20:38 -08:00
|
|
|
export function foo1(s: any): void { assert.strictEqual(s, ARG); }
|
|
|
|
export function foo2(s: any): void { assert.strictEqual(s, ARG); }
|
|
|
|
export function foo3(s: any): void { assert.strictEqual(s, ARG); }
|
|
|
|
export function foo4(s: any): void { assert.strictEqual(s, ARG); }
|
|
|
|
export function foo5(s: any): void { assert.strictEqual(s, ARG); }
|
2017-12-19 09:25:41 -08:00
|
|
|
|
2018-01-29 21:20:38 -08:00
|
|
|
export function test() {
|
2017-12-19 09:25:41 -08:00
|
|
|
wasm.bar(ARG);
|
|
|
|
}
|
|
|
|
"#)
|
|
|
|
.test();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn promote() {
|
2018-04-09 15:32:06 -07:00
|
|
|
project()
|
2017-12-19 09:25:41 -08:00
|
|
|
.file("src/lib.rs", r#"
|
2018-03-14 14:33:53 -07:00
|
|
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
2017-12-19 09:25:41 -08:00
|
|
|
|
|
|
|
extern crate wasm_bindgen;
|
|
|
|
|
|
|
|
use wasm_bindgen::prelude::*;
|
|
|
|
|
2018-02-07 16:41:33 -08:00
|
|
|
#[wasm_bindgen(module = "./test")]
|
|
|
|
extern {
|
|
|
|
fn foo1(s: &JsValue);
|
|
|
|
fn foo2(s: JsValue);
|
|
|
|
fn foo3(s: &JsValue);
|
|
|
|
fn foo4(s: JsValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen]
|
2018-03-05 23:25:15 +01:00
|
|
|
pub fn bar(s: &JsValue) {
|
2018-02-07 16:41:33 -08:00
|
|
|
foo1(s);
|
|
|
|
foo2(s.clone());
|
|
|
|
foo3(s);
|
|
|
|
foo4(s.clone());
|
2017-12-19 09:25:41 -08:00
|
|
|
}
|
|
|
|
"#)
|
2017-12-19 19:06:48 -08:00
|
|
|
.file("test.ts", r#"
|
2018-01-29 21:20:38 -08:00
|
|
|
import * as wasm from "./out";
|
2017-12-19 09:25:41 -08:00
|
|
|
import * as assert from "assert";
|
|
|
|
|
2018-01-29 21:20:38 -08:00
|
|
|
let ARG = (Symbol as any)('test');
|
2017-12-19 09:25:41 -08:00
|
|
|
|
2018-01-29 21:20:38 -08:00
|
|
|
export function foo1(s: any): void { assert.strictEqual(s, ARG); }
|
|
|
|
export function foo2(s: any): void { assert.strictEqual(s, ARG); }
|
|
|
|
export function foo3(s: any): void { assert.strictEqual(s, ARG); }
|
|
|
|
export function foo4(s: any): void { assert.strictEqual(s, ARG); }
|
2017-12-19 09:25:41 -08:00
|
|
|
|
2018-01-29 21:20:38 -08:00
|
|
|
export function test() {
|
2017-12-19 09:25:41 -08:00
|
|
|
wasm.bar(ARG);
|
|
|
|
}
|
|
|
|
"#)
|
|
|
|
.test();
|
|
|
|
}
|
2018-02-28 10:56:56 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn returning_vector() {
|
2018-04-09 15:32:06 -07:00
|
|
|
project()
|
2018-02-28 10:56:56 +01:00
|
|
|
.file("src/lib.rs", r#"
|
2018-03-14 14:33:53 -07:00
|
|
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
2018-02-28 10:56:56 +01:00
|
|
|
|
|
|
|
extern crate wasm_bindgen;
|
|
|
|
|
|
|
|
use wasm_bindgen::prelude::*;
|
|
|
|
|
|
|
|
#[wasm_bindgen(module = "./test")]
|
|
|
|
extern {
|
|
|
|
fn foo() -> JsValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen]
|
2018-03-05 23:25:15 +01:00
|
|
|
pub fn bar() -> Vec<JsValue> {
|
2018-02-28 10:56:56 +01:00
|
|
|
let mut res = Vec::new();
|
|
|
|
for _ in 0..10 {
|
|
|
|
res.push(foo())
|
|
|
|
}
|
|
|
|
res
|
|
|
|
}
|
|
|
|
"#)
|
|
|
|
.file("test.ts", r#"
|
|
|
|
import * as wasm from "./out";
|
|
|
|
import * as assert from "assert";
|
|
|
|
|
2018-02-28 17:29:40 +01:00
|
|
|
export function foo(): any { return { "foo": "bar" }; }
|
2018-02-28 10:56:56 +01:00
|
|
|
|
|
|
|
export function test() {
|
|
|
|
const result = wasm.bar();
|
|
|
|
assert.strictEqual(result.length, 10);
|
|
|
|
}
|
|
|
|
"#)
|
|
|
|
.test();
|
|
|
|
}
|