Skip to content

Commit

Permalink
Add test for cfg attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
seancribbs committed Jan 21, 2024
1 parent 423c2e1 commit 694d929
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/wasm/attributes.js
@@ -0,0 +1,9 @@
const wasm = require("wasm-bindgen-test.js");
const assert = require("assert");

exports.js_works = () => {
assert.strictEqual(wasm.valid_export(), true);
assert.strictEqual(wasm.invalid_export, undefined);
assert.strictEqual(wasm.valid_attr_export(), true);
assert.strictEqual(wasm.invalid_attr_export, undefined);
};
36 changes: 36 additions & 0 deletions tests/wasm/attributes.rs
@@ -0,0 +1,36 @@
use wasm_bindgen::prelude::*;
use wasm_bindgen_test::*;

#[wasm_bindgen(module = "tests/wasm/attributes.js")]
extern "C" {
fn js_works();
}

#[wasm_bindgen_test]
fn works() {
js_works();
}

#[wasm_bindgen]
#[cfg(target_arch = "wasm32")]
pub fn valid_export() -> bool {
true
}

#[wasm_bindgen]
#[cfg(not(target_arch = "wasm32"))]
pub fn invalid_export() -> bool {
false
}

#[wasm_bindgen]
#[cfg_attr(target_arch = "wasm32", no_mangle)]
pub fn valid_attr_export() -> bool {
true
}

#[wasm_bindgen]
#[cfg_attr(not(target_arch = "wasm32"), no_mangle)]
pub fn invalid_attr_export() -> bool {
false
}
1 change: 1 addition & 0 deletions tests/wasm/main.rs
Expand Up @@ -16,6 +16,7 @@ use wasm_bindgen::prelude::*;

pub mod api;
pub mod arg_names;
pub mod attributes;
pub mod bigint;
pub mod char;
pub mod classes;
Expand Down

0 comments on commit 694d929

Please sign in to comment.