mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-28 20:21:35 +00:00
Merge branch 'master' into feat/basic-enum-support
This commit is contained in:
@ -3,3 +3,4 @@ use project_builder::project;
|
||||
|
||||
mod simple;
|
||||
mod enums;
|
||||
mod throws;
|
||||
|
@ -41,17 +41,17 @@ fn method() {
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn test() {
|
||||
let pi = Foo::new(3.14159);
|
||||
let e = Foo::new(2.71828);
|
||||
let pi = Foo::new(3.14159).unwrap();
|
||||
let e = Foo::new(2.71828).unwrap();
|
||||
// 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!(!pi.my_cmp(Foo::new(3.14159).unwrap()));
|
||||
let tmp = pi.my_cmp(Foo::new(3.14159).unwrap());
|
||||
assert!(tmp);
|
||||
let tmp =!pi.my_cmp(Foo::new(2.71828));
|
||||
let tmp =!pi.my_cmp(Foo::new(2.71828).unwrap());
|
||||
assert!(tmp);
|
||||
let tmp = !e.my_cmp(Foo::new(3.14159));
|
||||
let tmp = !e.my_cmp(Foo::new(3.14159).unwrap());
|
||||
assert!(tmp);
|
||||
let tmp = e.my_cmp(Foo::new(2.71828));
|
||||
let tmp = e.my_cmp(Foo::new(2.71828).unwrap());
|
||||
assert!(tmp);
|
||||
}
|
||||
"#,
|
||||
@ -105,7 +105,7 @@ fn property() {
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn test() {
|
||||
let x = Foo::new(3.14159);
|
||||
let x = Foo::new(3.14159).unwrap();
|
||||
assert_eq!(x.value(), 3.14159);
|
||||
assert_ne!(x.value(), 2.71828);
|
||||
x.set_value(2.71828);
|
||||
@ -167,7 +167,7 @@ fn named_constructor() {
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn test() {
|
||||
let x = Foo::new(3.14159);
|
||||
let x = Foo::new(3.14159).unwrap();
|
||||
assert_eq!(x.value(), 3.14159);
|
||||
assert_ne!(x.value(), 0.);
|
||||
}
|
||||
@ -317,7 +317,7 @@ fn one_method_using_an_undefined_import_doesnt_break_all_other_methods() {
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn test() {
|
||||
let f = foo::Foo::new();
|
||||
let f = foo::Foo::new().unwrap();
|
||||
assert!(f.ok_method());
|
||||
}
|
||||
"#,
|
||||
@ -362,7 +362,7 @@ fn unforgeable_is_structural() {
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn test() {
|
||||
let f = foo::Foo::new();
|
||||
let f = foo::Foo::new().unwrap();
|
||||
assert_eq!(f.uno(), 1);
|
||||
assert_eq!(f.dos(), 2);
|
||||
}
|
||||
|
100
crates/webidl/tests/all/throws.rs
Normal file
100
crates/webidl/tests/all/throws.rs
Normal file
@ -0,0 +1,100 @@
|
||||
use super::project;
|
||||
|
||||
#[test]
|
||||
fn throws() {
|
||||
project()
|
||||
.file(
|
||||
"thang.webidl",
|
||||
r#"
|
||||
[Constructor(long value)]
|
||||
interface Thang {
|
||||
[Throws]
|
||||
attribute long ok_attr;
|
||||
[Throws]
|
||||
attribute long err_attr;
|
||||
|
||||
[Throws]
|
||||
long ok_method();
|
||||
[Throws]
|
||||
long err_method();
|
||||
|
||||
[Throws]
|
||||
static long ok_static_method();
|
||||
[Throws]
|
||||
static long err_static_method();
|
||||
|
||||
[Throws]
|
||||
static attribute long ok_static_attr;
|
||||
[Throws]
|
||||
static attribute long err_static_attr;
|
||||
};
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"thang.js",
|
||||
r#"
|
||||
export class Thang {
|
||||
constructor(value) {
|
||||
if (value % 2 == 0) {
|
||||
throw new Error("only odd allowed");
|
||||
}
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
get ok_attr() { return this.value; }
|
||||
set ok_attr(x) { }
|
||||
|
||||
get err_attr() { throw new Error("bad"); }
|
||||
set err_attr(x) { throw new Error("bad"); }
|
||||
|
||||
ok_method() { return this.value + 1; }
|
||||
err_method() { throw new Error("bad"); }
|
||||
|
||||
static ok_static_method() { return 1; }
|
||||
static err_static_method() { throw new Error("bad"); }
|
||||
|
||||
static get ok_static_attr() { return 1; }
|
||||
static set ok_static_attr(x) { }
|
||||
|
||||
static get err_static_attr() { throw new Error("bad"); }
|
||||
static set err_static_attr(x) { throw new Error("bad"); }
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
extern crate wasm_bindgen;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
pub mod thang;
|
||||
use thang::Thang;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn test() {
|
||||
assert!(Thang::new(0).is_err());
|
||||
let thang = Thang::new(1).unwrap();
|
||||
|
||||
assert!(thang.ok_attr().is_ok());
|
||||
assert!(thang.set_ok_attr(0).is_ok());
|
||||
|
||||
assert!(thang.err_attr().is_err());
|
||||
assert!(thang.set_err_attr(0).is_err());
|
||||
|
||||
assert!(thang.ok_method().is_ok());
|
||||
assert!(thang.err_method().is_err());
|
||||
|
||||
assert!(Thang::ok_static_method().is_ok());
|
||||
assert!(Thang::err_static_method().is_err());
|
||||
|
||||
assert!(Thang::ok_static_attr().is_ok());
|
||||
assert!(Thang::set_ok_static_attr(0).is_ok());
|
||||
|
||||
assert!(Thang::err_static_attr().is_err());
|
||||
assert!(Thang::set_err_static_attr(0).is_err());
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
Reference in New Issue
Block a user