Debian Codegraph @

.cargo/vendor/wasm-bindgen/tests/wasm/option.rs

raw
1 use wasm_bindgen::prelude::*;
2 use wasm_bindgen_test::*;
3
4 #[wasm_bindgen(module = "tests/wasm/option.js")]
5 extern "C" {
6 pub type MyType;
7 #[wasm_bindgen(constructor)]
8 fn new() -> MyType;
9
10 fn take_none_byval(t: Option<MyType>);
11 fn take_some_byval(t: Option<MyType>);
12 fn return_undef_byval() -> Option<MyType>;
13 fn return_null_byval() -> Option<MyType>;
14 fn return_some_byval() -> Option<MyType>;
15 fn test_option_values();
16
17 #[wasm_bindgen(js_name = take_none_byval)]
18 fn take_none_byref(t: Option<&MyType>);
19 #[wasm_bindgen(js_name = take_some_byval)]
20 fn take_some_byref(t: Option<&MyType>);
21 }
22
23 #[wasm_bindgen_test]
24 fn import_by_value() {
25 take_none_byval(None);
26 take_some_byval(Some(MyType::new()));
27 assert!(return_null_byval().is_none());
28 assert!(return_undef_byval().is_none());
29 assert!(return_some_byval().is_some());
30 }
31
32 #[wasm_bindgen_test]
33 fn export_by_value() {
34 test_option_values();
35 }
36
37 #[wasm_bindgen]
38 pub fn rust_take_none_byval(t: Option<MyType>) {
39 assert!(t.is_none());
40 }
41
42 #[wasm_bindgen]
43 pub fn rust_take_some_byval(t: Option<MyType>) {
44 assert!(t.is_some());
45 }
46
47 #[wasm_bindgen]
48 pub fn rust_return_none_byval() -> Option<MyType> {
49 None
50 }
51
52 #[wasm_bindgen]
53 pub fn rust_return_some_byval() -> Option<MyType> {
54 Some(MyType::new())
55 }
56
57 #[wasm_bindgen_test]
58 fn import_by_ref() {
59 take_none_byref(None);
60 take_some_byref(Some(&MyType::new()));
61 }