2018-07-30 21:06:29 +03:00
|
|
|
use wasm_bindgen_test::*;
|
|
|
|
|
|
|
|
include!(concat!(env!("OUT_DIR"), "/simple.rs"));
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn method() {
|
|
|
|
let pi = Method::new(3.14159).unwrap();
|
|
|
|
let e = Method::new(2.71828).unwrap();
|
|
|
|
assert!(pi.my_cmp(&pi));
|
|
|
|
assert!(!pi.my_cmp(&e));
|
|
|
|
assert!(!e.my_cmp(&pi));
|
|
|
|
assert!(e.my_cmp(&e));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn property() {
|
|
|
|
let x = Property::new(3.14159).unwrap();
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn named_constructor() {
|
|
|
|
let x = NamedConstructor::new(3.14159).unwrap();
|
|
|
|
assert_eq!(x.value(), 3.14159);
|
|
|
|
assert_ne!(x.value(), 0.);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn static_method() {
|
|
|
|
assert_eq!(StaticMethod::swap(3.14159), 0.);
|
|
|
|
assert_eq!(StaticMethod::swap(2.71828), 3.14159);
|
|
|
|
assert_ne!(StaticMethod::swap(2.71828), 3.14159);
|
|
|
|
assert_eq!(StaticMethod::swap(3.14159), 2.71828);
|
|
|
|
assert_ne!(StaticMethod::swap(3.14159), 2.71828);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn static_property() {
|
|
|
|
assert_eq!(StaticProperty::value(), 0.);
|
|
|
|
StaticProperty::set_value(3.14159);
|
|
|
|
assert_eq!(StaticProperty::value(), 3.14159);
|
|
|
|
assert_ne!(StaticProperty::value(), 2.71828);
|
|
|
|
StaticProperty::set_value(2.71828);
|
|
|
|
assert_eq!(StaticProperty::value(), 2.71828);
|
|
|
|
assert_ne!(StaticProperty::value(), 3.14159);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
2018-08-17 09:13:34 +03:00
|
|
|
fn one_method_with_an_undefined_import_doesnt_break_all_other_methods() {
|
2018-07-30 21:06:29 +03:00
|
|
|
let f = UndefinedMethod::new().unwrap();
|
|
|
|
assert!(f.ok_method());
|
|
|
|
}
|
|
|
|
|
2018-08-03 16:28:35 +03:00
|
|
|
#[wasm_bindgen_test]
|
2018-08-13 23:18:16 +03:00
|
|
|
fn nullable_method() {
|
|
|
|
let f = NullableMethod::new().unwrap();
|
2018-08-03 16:28:35 +03:00
|
|
|
assert!(f.opt(Some(15)) == Some(16));
|
|
|
|
assert!(f.opt(None) == None);
|
|
|
|
}
|
|
|
|
|
2018-08-05 18:05:20 +03:00
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn global_method() {
|
2018-08-29 01:19:31 +03:00
|
|
|
assert_eq!(GlobalMethod::m(), 123);
|
2018-08-07 00:42:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn indexing() {
|
|
|
|
let f = Indexing::new().unwrap();
|
|
|
|
assert_eq!(f.get(123), -1);
|
|
|
|
f.set(123, 456);
|
|
|
|
assert_eq!(f.get(123), 456);
|
|
|
|
f.delete(123);
|
|
|
|
assert_eq!(f.get(123), -1);
|
2018-08-05 18:05:20 +03:00
|
|
|
}
|
|
|
|
|
2018-08-13 23:18:16 +03:00
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn optional_and_union_arguments() {
|
|
|
|
let f = OptionalAndUnionArguments::new().unwrap();
|
2018-08-17 09:13:34 +03:00
|
|
|
assert_eq!(f.m("abc"), "string, abc, boolean, true, number, 123, number, 456");
|
|
|
|
assert_eq!(f.m_with_b("abc", false), "string, abc, boolean, false, number, 123, number, 456");
|
|
|
|
assert_eq!(f.m_with_bool_and_i16("abc", false, 5), "string, abc, boolean, false, number, 5, number, 456");
|
2018-08-19 20:24:23 +03:00
|
|
|
assert_eq!(f.m_with_bool_and_str("abc", false, "5"), "string, abc, boolean, false, string, 5, number, 456");
|
2018-08-17 09:13:34 +03:00
|
|
|
assert_eq!(f.m_with_bool_and_i16_and_opt_i64("abc", false, 5, Some(10)), "string, abc, boolean, false, number, 5, bigint, 10");
|
|
|
|
assert_eq!(f.m_with_bool_and_i16_and_opt_bool("abc", false, 5, Some(true)), "string, abc, boolean, false, number, 5, boolean, true");
|
2018-08-19 20:24:23 +03:00
|
|
|
assert_eq!(f.m_with_bool_and_str_and_opt_i64("abc", false, "5", Some(10)), "string, abc, boolean, false, string, 5, bigint, 10");
|
|
|
|
assert_eq!(f.m_with_bool_and_str_and_opt_bool("abc", false, "5", Some(true)), "string, abc, boolean, false, string, 5, boolean, true");
|
2018-08-13 23:18:16 +03:00
|
|
|
}
|
|
|
|
|
2018-07-30 21:06:29 +03:00
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn unforgeable_is_structural() {
|
|
|
|
let f = Unforgeable::new().unwrap();
|
|
|
|
assert_eq!(f.uno(), 1);
|
|
|
|
assert_eq!(f.dos(), 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn partial_interface() {
|
|
|
|
let f = PartialInterface::new().unwrap();
|
|
|
|
assert_eq!(f.un(), 1);
|
|
|
|
assert_eq!(f.deux(), 2);
|
|
|
|
assert_eq!(f.trois(), 3);
|
|
|
|
assert_eq!(f.quatre(), 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn mixin() {
|
|
|
|
let f = MixinFoo::new(1).unwrap();
|
|
|
|
assert_eq!(f.bar(), 1);
|
|
|
|
MixinFoo::set_default_bar(7);
|
|
|
|
f.add_to_bar(MixinFoo::default_bar());
|
|
|
|
assert_eq!(f.bar(), 8);
|
|
|
|
}
|
2018-08-29 02:32:31 +03:00
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn overload_naming() {
|
|
|
|
let o = Overloads::new().unwrap();
|
2018-08-29 20:28:04 +03:00
|
|
|
// o.foo();
|
|
|
|
// o.foo_with_arg("x");
|
|
|
|
// o.foo_with_arg_and_a("x", 3);
|
2018-08-29 02:32:31 +03:00
|
|
|
}
|