3 #![deny(missing_docs)] // test that documenting public bindings is enough
5 use wasm_bindgen
::prelude
::*;
6 use wasm_bindgen_test
::*;
8 #[wasm_bindgen(module = "tests/wasm/import_class.js")]
10 fn math_log(f
: f64) -> f64;
12 #[wasm_bindgen(js_namespace = StaticFunction)]
17 #[wasm_bindgen(js_namespace = Construct)]
18 fn create() -> Construct
;
19 #[wasm_bindgen(method)]
20 fn get_internal_string(this
: &Construct
) -> String
;
21 #[wasm_bindgen(method)]
22 fn append_to_internal_string(this
: &Construct
, s
: &str);
23 #[wasm_bindgen(method)]
24 fn assert_internal_string(this
: &Construct
, s
: &str);
27 #[wasm_bindgen(constructor)]
28 fn new(arg
: i32) -> NewConstructors
;
29 #[wasm_bindgen(method)]
30 fn get(this
: &NewConstructors
) -> i32;
32 #[wasm_bindgen(js_name = default)]
34 #[wasm_bindgen(constructor, js_class = default)]
35 fn new(arg
: i32) -> RenamedTypes
;
36 #[wasm_bindgen(method, js_class = default)]
37 fn get(this
: &RenamedTypes
) -> i32;
39 fn switch_methods_a();
40 fn switch_methods_b();
42 #[wasm_bindgen(constructor)]
43 #[wasm_bindgen(final)]
44 fn new() -> SwitchMethods
;
45 #[wasm_bindgen(js_namespace = SwitchMethods, final)]
47 fn switch_methods_called() -> bool
;
48 #[wasm_bindgen(method, final)]
49 fn b(this
: &SwitchMethods
);
52 #[wasm_bindgen(constructor)]
53 fn new() -> Properties
;
54 #[wasm_bindgen(getter, method)]
55 fn a(this
: &Properties
) -> i32;
56 #[wasm_bindgen(setter, method)]
57 fn set_a(this
: &Properties
, a
: i32);
59 type RenameProperties
;
60 #[wasm_bindgen(constructor)]
61 fn new() -> RenameProperties
;
62 #[wasm_bindgen(getter = a, method)]
63 fn test(this
: &RenameProperties
) -> i32;
64 #[wasm_bindgen(getter, method, js_name = a)]
65 fn test2(this
: &RenameProperties
) -> i32;
66 #[wasm_bindgen(setter = a, method)]
67 fn another(this
: &RenameProperties
, a
: i32);
68 #[wasm_bindgen(setter, method, js_name = a)]
69 fn another2(this
: &RenameProperties
, a
: i32);
72 pub type AssertImportDenyDocsWorks
;
74 #[wasm_bindgen(constructor)]
75 pub fn new() -> AssertImportDenyDocsWorks
;
77 #[wasm_bindgen(getter = a, method)]
78 pub fn test(this
: &AssertImportDenyDocsWorks
) -> i32;
83 #[wasm_bindgen(constructor)]
85 fn take_none(val
: Option
<Options
>);
86 fn take_some(val
: Option
<Options
>);
87 fn return_null() -> Option
<Options
>;
88 fn return_undefined() -> Option
<Options
>;
89 fn return_some() -> Option
<Options
>;
90 fn run_rust_option_tests();
92 type CatchConstructors
;
93 #[wasm_bindgen(constructor, catch)]
94 fn new(x
: u32) -> Result
<CatchConstructors
, JsValue
>;
96 type StaticStructural
;
97 #[wasm_bindgen(static_method_of = StaticStructural, structural)]
98 fn static_structural(a
: u32) -> u32;
102 #[wasm_bindgen(js_namespace = ["nestedNamespace", "InnerClass"])]
103 fn inner_static_function(a
: u32) -> u32;
104 #[wasm_bindgen(js_namespace = ["nestedNamespace", "InnerClass"])]
105 fn create_inner_instance() -> InnerClass
;
106 #[wasm_bindgen(method)]
107 fn get_internal_int(this
: &InnerClass
) -> u32;
108 #[wasm_bindgen(method)]
109 fn append_to_internal_int(this
: &InnerClass
, i
: u32);
110 #[wasm_bindgen(method)]
111 fn assert_internal_int(this
: &InnerClass
, i
: u32);
116 #[wasm_bindgen(js_namespace = Math)]
118 #[wasm_bindgen(js_namespace = Math)]
119 fn log(a
: f64) -> f64;
125 assert_eq
!(log(1.0), math_log(1.0));
130 assert_eq
!(bar(), 2);
135 let f
= Construct
::create();
136 assert_eq
!(f
.get_internal_string(), "this");
137 assert_eq
!(f
.clone().get_internal_string(), "this");
138 f
.append_to_internal_string(" foo");
139 f
.assert_internal_string("this foo");
143 fn new_constructors() {
144 let f
= NewConstructors
::new(1);
145 assert_eq
!(f
.get(), 2);
150 let f
= RenamedTypes
::new(1);
151 assert_eq
!(f
.get(), 2);
155 #[cfg(ignored)] // TODO: fix this before landing
156 fn switch_methods() {
157 assert
!(!switch_methods_called());
159 assert
!(switch_methods_called());
163 assert
!(!switch_methods_called());
165 assert
!(switch_methods_called());
167 assert
!(!switch_methods_called());
168 SwitchMethods
::new().b();
169 assert
!(switch_methods_called());
173 assert
!(!switch_methods_called());
174 SwitchMethods
::new().b();
175 assert
!(!switch_methods_called());
180 let a
= Properties
::new();
181 assert_eq
!(a
.a(), 1);
183 assert_eq
!(a
.a(), 2);
187 fn rename_setter_getter() {
188 let x
: fn() -> RenameProperties
= RenameProperties
::new
;
190 assert_eq
!(a
.test(), 1);
192 assert_eq
!(a
.test(), 2);
194 assert_eq
!(a
.test2(), 3);
199 pub struct AssertDenyDocsWorks
{
207 pub fn assert_deny_docs_works() {}
212 take_some(Some(Options
::new()));
213 assert
!(return_null().is_none());
214 assert
!(return_undefined().is_none());
215 assert
!(return_some().is_some());
216 run_rust_option_tests();
221 pub fn rust_take_none(a
: Option
<Options
>) {
222 assert
!(a
.is_none());
227 pub fn rust_take_some(a
: Option
<Options
>) {
228 assert
!(a
.is_some());
233 pub fn rust_return_none() -> Option
<Options
> {
239 pub fn rust_return_some() -> Option
<Options
> {
244 fn catch_constructors() {
245 assert
!(CatchConstructors
::new(0).is_err());
246 assert
!(CatchConstructors
::new(1).is_ok());
250 fn static_structural() {
251 assert_eq
!(StaticStructural
::static_structural(30), 33);
255 fn nested_namespace() {
256 assert_eq
!(InnerClass
::inner_static_function(15), 20);
258 let f
= InnerClass
::create_inner_instance();
259 assert_eq
!(f
.get_internal_int(), 3);
260 assert_eq
!(f
.clone().get_internal_int(), 3);
261 f
.append_to_internal_int(5);
262 f
.assert_internal_int(8);