Skip to content

Commit 1a28c50

Browse files
committed
Add test for cfg attributes
1 parent 423c2e1 commit 1a28c50

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

tests/wasm/attributes.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const wasm = require("wasm-bindgen-test.js");
2+
const assert = require("assert");
3+
4+
exports.js_works = () => {
5+
assert.strictEqual(wasm.valid_export(), true);
6+
assert.strictEqual(wasm.invalid_export, undefined);
7+
assert.strictEqual(wasm.valid_attr_export(), true);
8+
assert.strictEqual(wasm.invalid_attr_export, undefined);
9+
};

tests/wasm/attributes.rs

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
use wasm_bindgen::prelude::*;
2+
use wasm_bindgen_test::*;
3+
4+
#[wasm_bindgen(module = "tests/wasm/attributes.js")]
5+
extern "C" {
6+
fn js_works();
7+
}
8+
9+
#[wasm_bindgen_test]
10+
fn works() {
11+
js_works();
12+
}
13+
14+
#[wasm_bindgen]
15+
#[cfg(target_arch = "wasm32")]
16+
pub fn valid_export() -> bool {
17+
true
18+
}
19+
20+
#[wasm_bindgen]
21+
#[cfg(not(target_arch = "wasm32"))]
22+
pub fn invalid_export() -> bool {
23+
false
24+
}
25+
26+
#[wasm_bindgen]
27+
#[cfg_attr(not(target_arch = "wasm32"), cfg(feature = "missing-feature"))]
28+
pub fn valid_attr_export() -> bool {
29+
true
30+
}
31+
32+
#[wasm_bindgen]
33+
#[cfg_attr(target_arch = "wasm32", cfg(feature = "missing-feature"))]
34+
pub fn invalid_attr_export() -> bool {
35+
false
36+
}

tests/wasm/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use wasm_bindgen::prelude::*;
1616

1717
pub mod api;
1818
pub mod arg_names;
19+
pub mod attributes;
1920
pub mod bigint;
2021
pub mod char;
2122
pub mod classes;

0 commit comments

Comments
 (0)