Debian Codegraph @

.cargo/vendor/wasm-bindgen/tests/headless/snippets.rs

raw
1 use wasm_bindgen::prelude::*;
2 use wasm_bindgen_test::*;
3
4 #[wasm_bindgen(module = "/tests/headless/snippets1.js")]
5 extern "C" {
6 fn get_two() -> u32;
7 #[wasm_bindgen(js_name = get_stateful)]
8 fn get_stateful1() -> u32;
9 }
10
11 #[wasm_bindgen(module = "/tests/headless/snippets1.js")]
12 extern "C" {
13 #[wasm_bindgen(js_name = get_stateful)]
14 fn get_stateful2() -> u32;
15 }
16
17 #[wasm_bindgen_test]
18 fn test_get_two() {
19 assert_eq!(get_two(), 2);
20 }
21
22 #[wasm_bindgen_test]
23 fn stateful_deduplicated() {
24 assert_eq!(get_stateful1(), 1);
25 assert_eq!(get_stateful2(), 2);
26 assert_eq!(get_stateful1(), 3);
27 assert_eq!(get_stateful2(), 4);
28 }
29
30 #[wasm_bindgen(inline_js = "export function get_three() { return 3; }")]
31 extern "C" {
32 fn get_three() -> u32;
33 }
34
35 #[wasm_bindgen_test]
36 fn test_get_three() {
37 assert_eq!(get_three(), 3);
38 }
39
40 #[wasm_bindgen(inline_js = "let a = 0; export function get() { a += 1; return a; }")]
41 extern "C" {
42 #[wasm_bindgen(js_name = get)]
43 fn duplicate1() -> u32;
44 }
45
46 #[wasm_bindgen(inline_js = "let a = 0; export function get() { a += 1; return a; }")]
47 extern "C" {
48 #[wasm_bindgen(js_name = get)]
49 fn duplicate2() -> u32;
50 }
51
52 #[wasm_bindgen_test]
53 fn duplicate_inline_not_unified() {
54 assert_eq!(duplicate1(), 1);
55 assert_eq!(duplicate2(), 1);
56 assert_eq!(duplicate1(), 2);
57 assert_eq!(duplicate2(), 2);
58 }