mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-12-18 15:31:48 +03:00
efa4a2b8fa
* Reorganize Travis configuration * Add a `JOB` env var descriptor to all matrix entries. Not used anywhere but is useful when viewing the whole build on Travis's web interface. * Reorganize where builds are located, moving slow builds first and fast ones last. * Change checking the CLI builds from `cargo build` to `cargo check` * Use YAML references to reduce some duplication * Print some more timing statistics for each test * Extract `Project` helper in tests to a module This'll help make it a bit more extensible over time. At the same time the methods are also slightly reorganized to read more clearly from top to bottom. * Migrate all tests away from Webpack Wepback can take a significant amount of time to execute and when it's multiplied by hundreds of tests that adds up really quickly! After investigating Node's `--experimental-modules` option it looks like it's suitable for our use so this switches all tests to using JS files (moving away from TypeScript as well) with `--experimental-modules` with Node. Tests will be selectively re-enabled with webpack and node.js specific output (that doesn't require `--experimental-modules`), coming in later commits. * Restore the node test for node.js output Ensures it's workable as-is * Only generate typescript with webpack * Only read wasm files for webpack * Skip package.json/node_modules for now * Only generate webpack config if needed * Start a dedicated test module for typescript Will hopefully verify the generated Typescript compiles OK. * Remove unneeded `node` method * Fixup some rebase conflicts * Don't run asmjs example on travis * Fixup generator tests * Attempt to fix windows * Comment windows fix * More test fixes * More exclusions * More test fixes * Relax eslint regex Catch mjs modules as well * Fix eslint * Speed up travis on examples slightly
284 lines
7.1 KiB
Rust
284 lines
7.1 KiB
Rust
use super::project;
|
|
|
|
#[test]
|
|
fn method() {
|
|
project()
|
|
.file(
|
|
"foo.webidl",
|
|
r#"
|
|
[Constructor(double value)]
|
|
interface Foo {
|
|
[Pure]
|
|
boolean myCmp(Foo bar);
|
|
};
|
|
"#,
|
|
)
|
|
.file(
|
|
"foo.js",
|
|
r#"
|
|
export class Foo {
|
|
constructor(value) {
|
|
this.value = value;
|
|
}
|
|
myCmp(other) {
|
|
return this.value === other.value;
|
|
}
|
|
}
|
|
"#,
|
|
)
|
|
.file(
|
|
"src/lib.rs",
|
|
r#"
|
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
|
|
|
extern crate wasm_bindgen;
|
|
|
|
use wasm_bindgen::prelude::*;
|
|
|
|
pub mod foo;
|
|
|
|
use foo::Foo;
|
|
|
|
#[wasm_bindgen]
|
|
pub fn test() {
|
|
let pi = Foo::new(3.14159);
|
|
let e = Foo::new(2.71828);
|
|
// TODO: figure out why the following doesn't fail
|
|
// assert!(!pi.my_cmp(Foo::new(3.14159)));
|
|
let tmp = pi.my_cmp(Foo::new(3.14159));
|
|
assert!(tmp);
|
|
let tmp =!pi.my_cmp(Foo::new(2.71828));
|
|
assert!(tmp);
|
|
let tmp = !e.my_cmp(Foo::new(3.14159));
|
|
assert!(tmp);
|
|
let tmp = e.my_cmp(Foo::new(2.71828));
|
|
assert!(tmp);
|
|
}
|
|
"#,
|
|
)
|
|
.test();
|
|
}
|
|
|
|
#[test]
|
|
fn property() {
|
|
project()
|
|
.file(
|
|
"foo.webidl",
|
|
r#"
|
|
[Constructor(double value)]
|
|
interface Foo {
|
|
[Pure]
|
|
attribute double value;
|
|
};
|
|
"#,
|
|
)
|
|
.file(
|
|
"foo.js",
|
|
r#"
|
|
export class Foo {
|
|
constructor(value) {
|
|
this._value = value;
|
|
}
|
|
|
|
get value() {
|
|
return this._value;
|
|
}
|
|
|
|
set value(value) {
|
|
this._value = value;
|
|
}
|
|
}
|
|
"#,
|
|
)
|
|
.file(
|
|
"src/lib.rs",
|
|
r#"
|
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
|
|
|
extern crate wasm_bindgen;
|
|
|
|
use wasm_bindgen::prelude::*;
|
|
|
|
pub mod foo;
|
|
|
|
use foo::Foo;
|
|
|
|
#[wasm_bindgen]
|
|
pub fn test() {
|
|
let x = Foo::new(3.14159);
|
|
assert_eq!(x.value(), 3.14159);
|
|
assert_ne!(x.value(), 2.71828);
|
|
x.set_value(2.71828);
|
|
assert_ne!(x.value(), 3.14159);
|
|
assert_eq!(x.value(), 2.71828);
|
|
}
|
|
"#,
|
|
)
|
|
.test();
|
|
}
|
|
|
|
#[test]
|
|
fn named_constructor() {
|
|
project()
|
|
.file(
|
|
"foo.webidl",
|
|
r#"
|
|
[NamedConstructor=Bar(double value)]
|
|
interface Foo {
|
|
[Pure]
|
|
readonly attribute double value;
|
|
};
|
|
"#,
|
|
)
|
|
.file(
|
|
// Not a perfect test, but it gets the job done.
|
|
"foo.js",
|
|
r#"
|
|
export class Foo {
|
|
constructor() {
|
|
this._value = 0;
|
|
}
|
|
|
|
get value(){
|
|
return this._value;
|
|
}
|
|
}
|
|
|
|
export class Bar extends Foo {
|
|
constructor(_value) {
|
|
super();
|
|
this._value = _value;
|
|
}
|
|
}
|
|
"#,
|
|
)
|
|
.file(
|
|
"src/lib.rs",
|
|
r#"
|
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
|
|
|
extern crate wasm_bindgen;
|
|
|
|
use wasm_bindgen::prelude::*;
|
|
|
|
pub mod foo;
|
|
|
|
use foo::Foo;
|
|
|
|
#[wasm_bindgen]
|
|
pub fn test() {
|
|
let x = Foo::new(3.14159);
|
|
assert_eq!(x.value(), 3.14159);
|
|
assert_ne!(x.value(), 0.);
|
|
}
|
|
"#,
|
|
)
|
|
.test();
|
|
}
|
|
|
|
#[test]
|
|
fn static_method() {
|
|
project()
|
|
.file(
|
|
"foo.webidl",
|
|
r#"
|
|
interface Foo {
|
|
static double swap(double value);
|
|
};
|
|
"#,
|
|
)
|
|
.file(
|
|
"foo.js",
|
|
r#"
|
|
export class Foo {
|
|
static swap(value) {
|
|
const res = Foo.value;
|
|
Foo.value = value;
|
|
return res;
|
|
}
|
|
}
|
|
|
|
Foo.value = 0;
|
|
"#,
|
|
)
|
|
.file(
|
|
"src/lib.rs",
|
|
r#"
|
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
|
|
|
extern crate wasm_bindgen;
|
|
|
|
use wasm_bindgen::prelude::*;
|
|
|
|
pub mod foo;
|
|
|
|
use foo::Foo;
|
|
|
|
#[wasm_bindgen]
|
|
pub fn test() {
|
|
assert_eq!(Foo::swap(3.14159), 0.);
|
|
assert_eq!(Foo::swap(2.71828), 3.14159);
|
|
assert_ne!(Foo::swap(2.71828), 3.14159);
|
|
assert_eq!(Foo::swap(3.14159), 2.71828);
|
|
assert_ne!(Foo::swap(3.14159), 2.71828);
|
|
}
|
|
"#,
|
|
)
|
|
.test();
|
|
}
|
|
|
|
#[test]
|
|
fn static_property() {
|
|
project()
|
|
.file(
|
|
"foo.webidl",
|
|
r#"
|
|
interface Foo {
|
|
static attribute double value;
|
|
};
|
|
"#,
|
|
)
|
|
.file(
|
|
"foo.js",
|
|
r#"
|
|
export class Foo {
|
|
static get value(){
|
|
return Foo._value;
|
|
}
|
|
|
|
static set value(value) {
|
|
Foo._value = value;
|
|
}
|
|
}
|
|
|
|
Foo._value = 0;
|
|
"#,
|
|
)
|
|
.file(
|
|
"src/lib.rs",
|
|
r#"
|
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
|
|
|
extern crate wasm_bindgen;
|
|
|
|
use wasm_bindgen::prelude::*;
|
|
|
|
pub mod foo;
|
|
|
|
use foo::Foo;
|
|
|
|
#[wasm_bindgen]
|
|
pub fn test() {
|
|
assert_eq!(Foo::value(), 0.);
|
|
Foo::set_value(3.14159);
|
|
assert_eq!(Foo::value(), 3.14159);
|
|
assert_ne!(Foo::value(), 2.71828);
|
|
Foo::set_value(2.71828);
|
|
assert_eq!(Foo::value(), 2.71828);
|
|
assert_ne!(Foo::value(), 3.14159);
|
|
}
|
|
"#,
|
|
)
|
|
.test();
|
|
}
|