summaryrefslogtreecommitdiffstats
path: root/vendor/wasm-bindgen/tests/wasm
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/wasm-bindgen/tests/wasm')
-rw-r--r--vendor/wasm-bindgen/tests/wasm/enum_vecs.js23
-rw-r--r--vendor/wasm-bindgen/tests/wasm/enum_vecs.rs36
-rw-r--r--vendor/wasm-bindgen/tests/wasm/enums.js4
-rw-r--r--vendor/wasm-bindgen/tests/wasm/enums.rs14
-rw-r--r--vendor/wasm-bindgen/tests/wasm/getters_and_setters.rs19
-rw-r--r--vendor/wasm-bindgen/tests/wasm/ignore.rs11
-rw-r--r--vendor/wasm-bindgen/tests/wasm/macro_rules.rs12
-rw-r--r--vendor/wasm-bindgen/tests/wasm/main.rs4
-rw-r--r--vendor/wasm-bindgen/tests/wasm/node.js16
-rw-r--r--vendor/wasm-bindgen/tests/wasm/node.rs11
-rw-r--r--vendor/wasm-bindgen/tests/wasm/slice.js21
-rw-r--r--vendor/wasm-bindgen/tests/wasm/slice.rs32
-rw-r--r--vendor/wasm-bindgen/tests/wasm/string_vecs.js23
-rw-r--r--vendor/wasm-bindgen/tests/wasm/string_vecs.rs29
-rw-r--r--vendor/wasm-bindgen/tests/wasm/struct_vecs.js23
-rw-r--r--vendor/wasm-bindgen/tests/wasm/struct_vecs.rs40
16 files changed, 294 insertions, 24 deletions
diff --git a/vendor/wasm-bindgen/tests/wasm/enum_vecs.js b/vendor/wasm-bindgen/tests/wasm/enum_vecs.js
new file mode 100644
index 000000000..bef43b3e4
--- /dev/null
+++ b/vendor/wasm-bindgen/tests/wasm/enum_vecs.js
@@ -0,0 +1,23 @@
+const wasm = require('wasm-bindgen-test.js');
+const assert = require('assert');
+
+exports.pass_enum_vec = () => {
+ const el1 = wasm.EnumArrayElement.Unit;
+ const el2 = wasm.EnumArrayElement.Unit;
+ const ret = wasm.consume_enum_vec([el1, el2]);
+ assert.strictEqual(ret.length, 3);
+
+ const ret2 = wasm.consume_optional_enum_vec(ret);
+ assert.strictEqual(ret2.length, 4);
+
+ assert.strictEqual(wasm.consume_optional_enum_vec(undefined), undefined);
+};
+
+exports.pass_invalid_enum_vec = () => {
+ try {
+ wasm.consume_enum_vec(['not an enum value']);
+ } catch (e) {
+ assert.match(e.message, /invalid enum value passed/)
+ assert.match(e.stack, /consume_enum_vec/)
+ }
+};
diff --git a/vendor/wasm-bindgen/tests/wasm/enum_vecs.rs b/vendor/wasm-bindgen/tests/wasm/enum_vecs.rs
new file mode 100644
index 000000000..7b6e6bcaf
--- /dev/null
+++ b/vendor/wasm-bindgen/tests/wasm/enum_vecs.rs
@@ -0,0 +1,36 @@
+use wasm_bindgen::prelude::*;
+use wasm_bindgen_test::*;
+
+#[wasm_bindgen(module = "tests/wasm/enum_vecs.js")]
+extern "C" {
+ fn pass_enum_vec();
+ fn pass_invalid_enum_vec();
+}
+
+#[wasm_bindgen]
+pub enum EnumArrayElement {
+ Unit,
+}
+
+#[wasm_bindgen]
+pub fn consume_enum_vec(mut vec: Vec<EnumArrayElement>) -> Vec<EnumArrayElement> {
+ vec.push(EnumArrayElement::Unit);
+ vec
+}
+
+#[wasm_bindgen]
+pub fn consume_optional_enum_vec(
+ vec: Option<Vec<EnumArrayElement>>,
+) -> Option<Vec<EnumArrayElement>> {
+ vec.map(consume_enum_vec)
+}
+
+#[wasm_bindgen_test]
+fn test_valid() {
+ pass_enum_vec();
+}
+
+#[wasm_bindgen_test]
+fn test_invalid() {
+ pass_invalid_enum_vec();
+}
diff --git a/vendor/wasm-bindgen/tests/wasm/enums.js b/vendor/wasm-bindgen/tests/wasm/enums.js
index 640597dac..466f9f85b 100644
--- a/vendor/wasm-bindgen/tests/wasm/enums.js
+++ b/vendor/wasm-bindgen/tests/wasm/enums.js
@@ -38,3 +38,7 @@ exports.js_expect_enum_none = a => {
exports.js_renamed_enum = b => {
assert.strictEqual(wasm.JsRenamedEnum.B, b);
};
+
+exports.js_enum_with_error_variant = () => {
+ assert.strictEqual(wasm.EnumWithErrorVariant.Error, 2);
+};
diff --git a/vendor/wasm-bindgen/tests/wasm/enums.rs b/vendor/wasm-bindgen/tests/wasm/enums.rs
index 959a3e271..7c652273b 100644
--- a/vendor/wasm-bindgen/tests/wasm/enums.rs
+++ b/vendor/wasm-bindgen/tests/wasm/enums.rs
@@ -10,6 +10,7 @@ extern "C" {
fn js_expect_enum(x: Color, y: Option<Color>);
fn js_expect_enum_none(x: Option<Color>);
fn js_renamed_enum(b: RenamedEnum);
+ fn js_enum_with_error_variant();
}
#[wasm_bindgen]
@@ -71,6 +72,14 @@ pub fn handle_optional_enums(x: Option<Color>) -> Option<Color> {
x
}
+#[wasm_bindgen]
+#[derive(Copy, Clone)]
+pub enum EnumWithErrorVariant {
+ OK,
+ Warning,
+ Error,
+}
+
#[wasm_bindgen_test]
fn test_optional_enums() {
use self::Color::*;
@@ -95,3 +104,8 @@ fn test_optional_enum_values() {
fn test_renamed_enum() {
js_renamed_enum(RenamedEnum::B);
}
+
+#[wasm_bindgen_test]
+fn test_enum_with_error_variant() {
+ js_enum_with_error_variant();
+}
diff --git a/vendor/wasm-bindgen/tests/wasm/getters_and_setters.rs b/vendor/wasm-bindgen/tests/wasm/getters_and_setters.rs
index 7425fc23e..8c8411983 100644
--- a/vendor/wasm-bindgen/tests/wasm/getters_and_setters.rs
+++ b/vendor/wasm-bindgen/tests/wasm/getters_and_setters.rs
@@ -20,6 +20,8 @@ extern "C" {
fn _12_js(rules: Rules) -> Rules;
fn _13_js(rules: Rules) -> Rules;
+ fn raw_identifer(rules: RulesWithRawField) -> RulesWithRawField;
+
fn test_getter_compute(x: GetterCompute);
fn test_setter_compute(x: SetterCompute);
fn test_statics(x: Statics);
@@ -33,6 +35,23 @@ pub struct Rules {
}
#[wasm_bindgen]
+pub struct RulesWithRawField {
+ pub r#mod: i32,
+}
+
+#[wasm_bindgen]
+impl RulesWithRawField {
+ #[wasm_bindgen]
+ pub fn get_field_value(&self) -> i32 {
+ self.r#mod
+ }
+ #[wasm_bindgen]
+ pub fn set_field_value(&mut self, value: i32) {
+ self.r#mod = value;
+ }
+}
+
+#[wasm_bindgen]
#[allow(non_snake_case)]
impl Rules {
#[wasm_bindgen]
diff --git a/vendor/wasm-bindgen/tests/wasm/ignore.rs b/vendor/wasm-bindgen/tests/wasm/ignore.rs
new file mode 100644
index 000000000..39897e31b
--- /dev/null
+++ b/vendor/wasm-bindgen/tests/wasm/ignore.rs
@@ -0,0 +1,11 @@
+#[wasm_bindgen_test]
+#[ignore]
+fn should_panic() {
+ panic!()
+}
+
+#[wasm_bindgen_test]
+#[ignore = "reason"]
+fn should_panic_string() {
+ panic!()
+}
diff --git a/vendor/wasm-bindgen/tests/wasm/macro_rules.rs b/vendor/wasm-bindgen/tests/wasm/macro_rules.rs
new file mode 100644
index 000000000..42c4b2a1d
--- /dev/null
+++ b/vendor/wasm-bindgen/tests/wasm/macro_rules.rs
@@ -0,0 +1,12 @@
+//! This tests that the `wasm_bindgen` macro produces code that compiles for this use case.
+//! `cargo test --target wasm32-unknown-unknown` will not run if this test breaks.
+use wasm_bindgen::prelude::*;
+
+macro_rules! my_export {
+ ($i: ident, $s: ty) => {
+ #[wasm_bindgen]
+ pub fn $i(_: $s) {}
+ };
+}
+
+my_export!(should_compile, &[i32]);
diff --git a/vendor/wasm-bindgen/tests/wasm/main.rs b/vendor/wasm-bindgen/tests/wasm/main.rs
index 508a9ea1f..72bb5c414 100644
--- a/vendor/wasm-bindgen/tests/wasm/main.rs
+++ b/vendor/wasm-bindgen/tests/wasm/main.rs
@@ -23,6 +23,7 @@ pub mod closures;
pub mod comments;
pub mod duplicate_deps;
pub mod duplicates;
+pub mod enum_vecs;
pub mod enums;
#[path = "final.rs"]
pub mod final_;
@@ -35,6 +36,7 @@ pub mod js_keywords;
pub mod js_objects;
pub mod jscast;
pub mod link_to;
+pub mod macro_rules;
pub mod math;
pub mod no_shims;
pub mod node;
@@ -46,6 +48,8 @@ pub mod result_jserror;
pub mod rethrow;
pub mod simple;
pub mod slice;
+pub mod string_vecs;
+pub mod struct_vecs;
pub mod structural;
pub mod truthy_falsy;
pub mod usize;
diff --git a/vendor/wasm-bindgen/tests/wasm/node.js b/vendor/wasm-bindgen/tests/wasm/node.js
index 41baa8b24..b38656731 100644
--- a/vendor/wasm-bindgen/tests/wasm/node.js
+++ b/vendor/wasm-bindgen/tests/wasm/node.js
@@ -24,14 +24,14 @@ exports.test_works = function() {
assert.strictEqual(r2.add(2), 13);
r2.free();
- assert.strictEqual(wasm.Color.Green, 0);
- assert.strictEqual(wasm.Color.Yellow, 1);
- assert.strictEqual(wasm.Color.Red, 2);
- assert.strictEqual(wasm.Color[0], 'Green');
- assert.strictEqual(wasm.Color[1], 'Yellow');
- assert.strictEqual(wasm.Color[2], 'Red');
- assert.strictEqual(Object.keys(wasm.Color).length, 6);
- assert.strictEqual(wasm.cycle(wasm.Color.Green), wasm.Color.Yellow);
+ assert.strictEqual(wasm.NodeColor.Green, 0);
+ assert.strictEqual(wasm.NodeColor.Yellow, 1);
+ assert.strictEqual(wasm.NodeColor.Red, 2);
+ assert.strictEqual(wasm.NodeColor[0], 'Green');
+ assert.strictEqual(wasm.NodeColor[1], 'Yellow');
+ assert.strictEqual(wasm.NodeColor[2], 'Red');
+ assert.strictEqual(Object.keys(wasm.NodeColor).length, 6);
+ assert.strictEqual(wasm.cycle(wasm.NodeColor.Green), wasm.NodeColor.Yellow);
wasm.node_math(1.0, 2.0);
};
diff --git a/vendor/wasm-bindgen/tests/wasm/node.rs b/vendor/wasm-bindgen/tests/wasm/node.rs
index 742dbcfb5..8f57e1731 100644
--- a/vendor/wasm-bindgen/tests/wasm/node.rs
+++ b/vendor/wasm-bindgen/tests/wasm/node.rs
@@ -34,18 +34,19 @@ impl Foo {
}
}
+// Use a different name to avoid a collision with the `Color` enum in enums.rs when --no-modules is used.
#[wasm_bindgen]
-pub enum Color {
+pub enum NodeColor {
Green,
Yellow,
Red,
}
#[wasm_bindgen]
-pub fn cycle(color: Color) -> Color {
+pub fn cycle(color: NodeColor) -> NodeColor {
match color {
- Color::Green => Color::Yellow,
- Color::Yellow => Color::Red,
- Color::Red => Color::Green,
+ NodeColor::Green => NodeColor::Yellow,
+ NodeColor::Yellow => NodeColor::Red,
+ NodeColor::Red => NodeColor::Green,
}
}
diff --git a/vendor/wasm-bindgen/tests/wasm/slice.js b/vendor/wasm-bindgen/tests/wasm/slice.js
index c23535e9b..3e65dfc52 100644
--- a/vendor/wasm-bindgen/tests/wasm/slice.js
+++ b/vendor/wasm-bindgen/tests/wasm/slice.js
@@ -6,39 +6,60 @@ exports.js_export = () => {
i8[0] = 1;
i8[1] = 2;
assert.deepStrictEqual(wasm.export_i8(i8), i8);
+ assert.deepStrictEqual(wasm.export_optional_i8(i8), i8);
const u8 = new Uint8Array(2);
u8[0] = 1;
u8[1] = 2;
assert.deepStrictEqual(wasm.export_u8(u8), u8);
+ assert.deepStrictEqual(wasm.export_optional_u8(u8), u8);
const i16 = new Int16Array(2);
i16[0] = 1;
i16[1] = 2;
assert.deepStrictEqual(wasm.export_i16(i16), i16);
+ assert.deepStrictEqual(wasm.export_optional_i16(i16), i16);
const u16 = new Uint16Array(2);
u16[0] = 1;
u16[1] = 2;
assert.deepStrictEqual(wasm.export_u16(u16), u16);
+ assert.deepStrictEqual(wasm.export_optional_u16(u16), u16);
const i32 = new Int32Array(2);
i32[0] = 1;
i32[1] = 2;
assert.deepStrictEqual(wasm.export_i32(i32), i32);
+ assert.deepStrictEqual(wasm.export_optional_i32(i32), i32);
assert.deepStrictEqual(wasm.export_isize(i32), i32);
+ assert.deepStrictEqual(wasm.export_optional_isize(i32), i32);
const u32 = new Uint32Array(2);
u32[0] = 1;
u32[1] = 2;
assert.deepStrictEqual(wasm.export_u32(u32), u32);
+ assert.deepStrictEqual(wasm.export_optional_u32(u32), u32);
assert.deepStrictEqual(wasm.export_usize(u32), u32);
+ assert.deepStrictEqual(wasm.export_optional_usize(u32), u32);
const f32 = new Float32Array(2);
f32[0] = 1;
f32[1] = 2;
assert.deepStrictEqual(wasm.export_f32(f32), f32);
+ assert.deepStrictEqual(wasm.export_optional_f32(f32), f32);
const f64 = new Float64Array(2);
f64[0] = 1;
f64[1] = 2;
assert.deepStrictEqual(wasm.export_f64(f64), f64);
+ assert.deepStrictEqual(wasm.export_optional_f64(f64), f64);
+
+ assert.strictEqual(wasm.export_optional_i8(undefined), undefined);
+ assert.strictEqual(wasm.export_optional_u8(undefined), undefined);
+ assert.strictEqual(wasm.export_optional_i16(undefined), undefined);
+ assert.strictEqual(wasm.export_optional_u16(undefined), undefined);
+ assert.strictEqual(wasm.export_optional_i32(undefined), undefined);
+ assert.strictEqual(wasm.export_optional_isize(undefined), undefined);
+ assert.strictEqual(wasm.export_optional_u32(undefined), undefined);
+ assert.strictEqual(wasm.export_optional_usize(undefined), undefined);
+ assert.strictEqual(wasm.export_optional_f32(undefined), undefined);
+ assert.strictEqual(wasm.export_optional_f64(undefined), undefined);
};
const test_import = (a, b, c) => {
diff --git a/vendor/wasm-bindgen/tests/wasm/slice.rs b/vendor/wasm-bindgen/tests/wasm/slice.rs
index 6e659ce6f..9f9066fe7 100644
--- a/vendor/wasm-bindgen/tests/wasm/slice.rs
+++ b/vendor/wasm-bindgen/tests/wasm/slice.rs
@@ -22,7 +22,7 @@ extern "C" {
}
macro_rules! export_macro {
- ($(($i:ident, $n:ident))*) => ($(
+ ($(($i:ident, $n:ident, $optional_n:ident))*) => ($(
#[wasm_bindgen]
pub fn $n(a: &[$i]) -> Vec<$i> {
assert_eq!(a.len(), 2);
@@ -30,20 +30,30 @@ macro_rules! export_macro {
assert_eq!(a[1], 2 as $i);
a.to_vec()
}
+
+ #[wasm_bindgen]
+ pub fn $optional_n(a: Option<Vec<$i>>) -> Option<Vec<$i>> {
+ a.map(|a| {
+ assert_eq!(a.len(), 2);
+ assert_eq!(a[0], 1 as $i);
+ assert_eq!(a[1], 2 as $i);
+ a.to_vec()
+ })
+ }
)*)
}
export_macro! {
- (i8, export_i8)
- (u8, export_u8)
- (i16, export_i16)
- (u16, export_u16)
- (i32, export_i32)
- (u32, export_u32)
- (isize, export_isize)
- (usize, export_usize)
- (f32, export_f32)
- (f64, export_f64)
+ (i8, export_i8, export_optional_i8)
+ (u8, export_u8, export_optional_u8)
+ (i16, export_i16, export_optional_i16)
+ (u16, export_u16, export_optional_u16)
+ (i32, export_i32, export_optional_i32)
+ (u32, export_u32, export_optional_u32)
+ (isize, export_isize, export_optional_isize)
+ (usize, export_usize, export_optional_usize)
+ (f32, export_f32, export_optional_f32)
+ (f64, export_f64, export_optional_f64)
}
#[wasm_bindgen_test]
diff --git a/vendor/wasm-bindgen/tests/wasm/string_vecs.js b/vendor/wasm-bindgen/tests/wasm/string_vecs.js
new file mode 100644
index 000000000..de9b0ef58
--- /dev/null
+++ b/vendor/wasm-bindgen/tests/wasm/string_vecs.js
@@ -0,0 +1,23 @@
+const wasm = require('wasm-bindgen-test.js');
+const assert = require('assert');
+
+exports.pass_string_vec = () => {
+ assert.deepStrictEqual(
+ wasm.consume_string_vec(["hello", "world"]),
+ ["hello", "world", "Hello from Rust!"],
+ );
+ assert.deepStrictEqual(
+ wasm.consume_optional_string_vec(["hello", "world"]),
+ ["hello", "world", "Hello from Rust!"],
+ );
+ assert.strictEqual(wasm.consume_optional_string_vec(undefined), undefined);
+};
+
+exports.pass_invalid_string_vec = () => {
+ try {
+ wasm.consume_string_vec([42]);
+ } catch (e) {
+ assert.match(e.message, /array contains a value of the wrong type/)
+ assert.match(e.stack, /consume_string_vec/)
+ }
+};
diff --git a/vendor/wasm-bindgen/tests/wasm/string_vecs.rs b/vendor/wasm-bindgen/tests/wasm/string_vecs.rs
new file mode 100644
index 000000000..1234d03d9
--- /dev/null
+++ b/vendor/wasm-bindgen/tests/wasm/string_vecs.rs
@@ -0,0 +1,29 @@
+use wasm_bindgen::prelude::*;
+use wasm_bindgen_test::*;
+
+#[wasm_bindgen(module = "tests/wasm/string_vecs.js")]
+extern "C" {
+ fn pass_string_vec();
+ fn pass_invalid_string_vec();
+}
+
+#[wasm_bindgen]
+pub fn consume_string_vec(mut vec: Vec<String>) -> Vec<String> {
+ vec.push("Hello from Rust!".to_owned());
+ vec
+}
+
+#[wasm_bindgen]
+pub fn consume_optional_string_vec(vec: Option<Vec<String>>) -> Option<Vec<String>> {
+ vec.map(consume_string_vec)
+}
+
+#[wasm_bindgen_test]
+fn test_valid() {
+ pass_string_vec();
+}
+
+#[wasm_bindgen_test]
+fn test_invalid() {
+ pass_invalid_string_vec();
+}
diff --git a/vendor/wasm-bindgen/tests/wasm/struct_vecs.js b/vendor/wasm-bindgen/tests/wasm/struct_vecs.js
new file mode 100644
index 000000000..23eb154fd
--- /dev/null
+++ b/vendor/wasm-bindgen/tests/wasm/struct_vecs.js
@@ -0,0 +1,23 @@
+const wasm = require('wasm-bindgen-test.js');
+const assert = require('assert');
+
+exports.pass_struct_vec = () => {
+ const el1 = new wasm.ArrayElement();
+ const el2 = new wasm.ArrayElement();
+ const ret = wasm.consume_struct_vec([el1, el2]);
+ assert.strictEqual(ret.length, 3);
+
+ const ret2 = wasm.consume_optional_struct_vec(ret);
+ assert.strictEqual(ret2.length, 4);
+
+ assert.strictEqual(wasm.consume_optional_struct_vec(undefined), undefined);
+};
+
+exports.pass_invalid_struct_vec = () => {
+ try {
+ wasm.consume_struct_vec(['not a struct']);
+ } catch (e) {
+ assert.match(e.message, /array contains a value of the wrong type/)
+ assert.match(e.stack, /consume_struct_vec/)
+ }
+};
diff --git a/vendor/wasm-bindgen/tests/wasm/struct_vecs.rs b/vendor/wasm-bindgen/tests/wasm/struct_vecs.rs
new file mode 100644
index 000000000..2440abc20
--- /dev/null
+++ b/vendor/wasm-bindgen/tests/wasm/struct_vecs.rs
@@ -0,0 +1,40 @@
+use wasm_bindgen::prelude::*;
+use wasm_bindgen_test::*;
+
+#[wasm_bindgen(module = "tests/wasm/struct_vecs.js")]
+extern "C" {
+ fn pass_struct_vec();
+ fn pass_invalid_struct_vec();
+}
+
+#[wasm_bindgen]
+pub struct ArrayElement;
+
+#[wasm_bindgen]
+impl ArrayElement {
+ #[wasm_bindgen(constructor)]
+ pub fn new() -> ArrayElement {
+ ArrayElement
+ }
+}
+
+#[wasm_bindgen]
+pub fn consume_struct_vec(mut vec: Vec<ArrayElement>) -> Vec<ArrayElement> {
+ vec.push(ArrayElement);
+ vec
+}
+
+#[wasm_bindgen]
+pub fn consume_optional_struct_vec(vec: Option<Vec<ArrayElement>>) -> Option<Vec<ArrayElement>> {
+ vec.map(consume_struct_vec)
+}
+
+#[wasm_bindgen_test]
+fn test_valid() {
+ pass_struct_vec();
+}
+
+#[wasm_bindgen_test]
+fn test_invalid() {
+ pass_invalid_struct_vec();
+}