mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-12 20:41:24 +00:00
Add OptionalAndUnionArguments test
This commit is contained in:
@ -67,7 +67,7 @@ global.UndefinedMethod = class UndefinedMethod {
|
||||
}
|
||||
};
|
||||
|
||||
global.OptionalMethod = class OptionalMethod {
|
||||
global.NullableMethod = class NullableMethod {
|
||||
constructor() {}
|
||||
opt(a) {
|
||||
if (a == undefined) {
|
||||
@ -107,6 +107,13 @@ global.Indexing = function () {
|
||||
});
|
||||
};
|
||||
|
||||
global.OptionalAndUnionArguments = class OptionalAndUnionArguments {
|
||||
constructor() {}
|
||||
m(a, b = true, c = 123, d = 456) {
|
||||
return [typeof a, a, typeof b, b, typeof c, c, typeof d, d].join(', ');
|
||||
}
|
||||
};
|
||||
|
||||
global.PartialInterface = class PartialInterface {
|
||||
get un() {
|
||||
return 1;
|
||||
|
@ -56,8 +56,8 @@ fn one_method_using_an_undefined_import_doesnt_break_all_other_methods() {
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn optional_method() {
|
||||
let f = OptionalMethod::new().unwrap();
|
||||
fn nullable_method() {
|
||||
let f = NullableMethod::new().unwrap();
|
||||
assert!(f.opt(Some(15)) == Some(16));
|
||||
assert!(f.opt(None) == None);
|
||||
}
|
||||
@ -78,6 +78,19 @@ fn indexing() {
|
||||
assert_eq!(f.get(123), -1);
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn optional_and_union_arguments() {
|
||||
let f = OptionalAndUnionArguments::new().unwrap();
|
||||
assert_eq!(f.m_using_a("abc"), "string, abc, boolean, true, number, 123, number, 456");
|
||||
assert_eq!(f.m_using_a_and_b("abc", false), "string, abc, boolean, false, number, 123, number, 456");
|
||||
assert_eq!(f.m_using_dom_str_and_bool_and_i16("abc", false, 5), "string, abc, boolean, false, number, 5, number, 456");
|
||||
assert_eq!(f.m_using_dom_str_and_bool_and_dom_str("abc", false, "5"), "string, abc, boolean, false, string, 5, number, 456");
|
||||
assert_eq!(f.m_using_dom_str_and_bool_and_i16_and_opt_i64("abc", false, 5, Some(10)), "string, abc, boolean, false, number, 5, bigint, 10");
|
||||
assert_eq!(f.m_using_dom_str_and_bool_and_i16_and_opt_bool("abc", false, 5, Some(true)), "string, abc, boolean, false, number, 5, boolean, true");
|
||||
assert_eq!(f.m_using_dom_str_and_bool_and_dom_str_and_opt_i64("abc", false, "5", Some(10)), "string, abc, boolean, false, string, 5, bigint, 10");
|
||||
assert_eq!(f.m_using_dom_str_and_bool_and_dom_str_and_opt_bool("abc", false, "5", Some(true)), "string, abc, boolean, false, string, 5, boolean, true");
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn unforgeable_is_structural() {
|
||||
let f = Unforgeable::new().unwrap();
|
||||
|
12
crates/webidl-tests/simple.webidl
vendored
12
crates/webidl-tests/simple.webidl
vendored
@ -31,7 +31,7 @@ interface UndefinedMethod {
|
||||
};
|
||||
|
||||
[Constructor()]
|
||||
interface OptionalMethod {
|
||||
interface NullableMethod {
|
||||
octet? opt(short? a);
|
||||
};
|
||||
|
||||
@ -47,6 +47,16 @@ interface Indexing {
|
||||
deleter void (unsigned long index);
|
||||
};
|
||||
|
||||
[Constructor()]
|
||||
interface OptionalAndUnionArguments {
|
||||
DOMString m(
|
||||
DOMString a,
|
||||
optional boolean b = true,
|
||||
optional (short or DOMString) c = 123,
|
||||
optional (long long or boolean)? d = 456
|
||||
);
|
||||
};
|
||||
|
||||
[Constructor()]
|
||||
interface Unforgeable {
|
||||
[Unforgeable] readonly attribute short uno;
|
||||
|
Reference in New Issue
Block a user