Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jules-Bertholet committed Jul 14, 2021
1 parent 3dc6439 commit 59d4750
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
12 changes: 12 additions & 0 deletions tests/wasm/js_objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@ exports.js_another_vector_return = () => {
assert.deepStrictEqual(wasm.another_vector_return_get_array(), [1, 2, 3, 4, 5, 6]);
};

exports.returning_vector_string_foo = () => {
return "This is the mostest awesomest string that can possibly exist.";
};

exports.js_returning_vector_string = () => {
assert.strictEqual(wasm.returning_vector_string_bar().length, 10);
};

exports.js_another_vector_string_return = () => {
assert.deepStrictEqual(wasm.another_vector_string_return_get_array(), ["1", "2", "3", "4", "5", "6"]);
};

exports.verify_serde = function(a) {
assert.deepStrictEqual(a, {
a: 0,
Expand Down
38 changes: 37 additions & 1 deletion tests/wasm/js_objects.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use js_sys::JsString;
use wasm_bindgen::prelude::*;
use wasm_bindgen_test::*;

Expand All @@ -24,8 +25,12 @@ extern "C" {

fn returning_vector_foo() -> JsValue;
fn js_returning_vector();

fn js_another_vector_return();

fn returning_vector_string_foo() -> JsString;
fn js_returning_vector_string();
fn js_another_vector_string_return();

fn verify_serde(val: JsValue) -> JsValue;
}

Expand Down Expand Up @@ -107,6 +112,37 @@ fn another_vector_return() {
js_another_vector_return();
}

#[wasm_bindgen]
pub fn returning_vector_string_bar() -> Vec<JsString> {
let mut res = Vec::new();
for _ in 0..10 {
res.push(returning_vector_string_foo())
}
res
}

#[wasm_bindgen_test]
fn returning_vector_string() {
js_returning_vector_string();
}

#[wasm_bindgen]
pub fn another_vector_string_return_get_array() -> Vec<JsString> {
vec![
"1".into(),
"2".into(),
"3".into(),
"4".into(),
"5".into(),
"6".into(),
]
}

#[wasm_bindgen_test]
fn another_vector_string_return() {
js_another_vector_string_return();
}

#[cfg(feature = "serde-serialize")]
#[wasm_bindgen_test]
fn serde() {
Expand Down

0 comments on commit 59d4750

Please sign in to comment.