mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-25 14:12:13 +00:00
Move $-renaming tests to wasm
This commit is contained in:
parent
aeca24c7ab
commit
8513858973
@ -36,91 +36,6 @@ fn unused_imports_not_generated() {
|
|||||||
assert!(!contents.contains("foo"), "found `foo` in {}", contents);
|
assert!(!contents.contains("foo"), "found `foo` in {}", contents);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn rename_with_string() {
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn rename_static_with_string() {
|
|
||||||
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 {
|
|
||||||
#[wasm_bindgen(js_name = "$foo")]
|
|
||||||
static FOO: JsValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[wasm_bindgen]
|
|
||||||
pub fn run() {
|
|
||||||
assert_eq!(FOO.as_f64(), Some(1.0));
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
)
|
|
||||||
.file(
|
|
||||||
"test.js",
|
|
||||||
r#"
|
|
||||||
import { run } from "./out";
|
|
||||||
|
|
||||||
export const $foo = 1.0;
|
|
||||||
|
|
||||||
export function test() {
|
|
||||||
run();
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
)
|
|
||||||
.test();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn versions() {
|
fn versions() {
|
||||||
project()
|
project()
|
||||||
|
@ -90,3 +90,6 @@ exports.touch_custom_type = function() {
|
|||||||
exports.interpret_2_as_custom_type = function() {
|
exports.interpret_2_as_custom_type = function() {
|
||||||
assert.throws(wasm.interpret_2_as_custom_type, /expected value of type CustomType/);
|
assert.throws(wasm.interpret_2_as_custom_type, /expected value of type CustomType/);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.baz$ = function() {};
|
||||||
|
exports.$foo = 1.0;
|
||||||
|
@ -42,6 +42,11 @@ extern {
|
|||||||
fn custom_type_return_2() -> CustomType;
|
fn custom_type_return_2() -> CustomType;
|
||||||
#[wasm_bindgen(js_name = interpret_2_as_custom_type)]
|
#[wasm_bindgen(js_name = interpret_2_as_custom_type)]
|
||||||
fn js_interpret_2_as_custom_type();
|
fn js_interpret_2_as_custom_type();
|
||||||
|
|
||||||
|
#[wasm_bindgen(js_name = "baz$")]
|
||||||
|
fn renamed_with_dollar_sign();
|
||||||
|
#[wasm_bindgen(js_name = "$foo")]
|
||||||
|
static RENAMED: JsValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
@ -153,3 +158,13 @@ impl CustomType {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[wasm_bindgen_test]
|
||||||
|
fn rename_with_string() {
|
||||||
|
renamed_with_dollar_sign();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen_test]
|
||||||
|
fn rename_static_with_string() {
|
||||||
|
assert_eq!(RENAMED.as_f64(), Some(1.0));
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user