From 5f87ed4cefe0c968e281ffce60a97e6758e46805 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 20 Jul 2018 17:09:50 -0700 Subject: [PATCH] Port `WebAssembly` tests to `wasm` --- crates/js-sys/tests/all/WebAssembly.rs | 70 ------------------------- crates/js-sys/tests/all/main.rs | 1 - crates/js-sys/tests/wasm/WebAssembly.rs | 9 ++++ crates/js-sys/tests/wasm/main.rs | 1 + 4 files changed, 10 insertions(+), 71 deletions(-) delete mode 100644 crates/js-sys/tests/all/WebAssembly.rs create mode 100644 crates/js-sys/tests/wasm/WebAssembly.rs diff --git a/crates/js-sys/tests/all/WebAssembly.rs b/crates/js-sys/tests/all/WebAssembly.rs deleted file mode 100644 index 071d3312..00000000 --- a/crates/js-sys/tests/all/WebAssembly.rs +++ /dev/null @@ -1,70 +0,0 @@ -#![allow(non_snake_case)] - -use super::project; - -#[test] -fn validate() { - project() - .file("src/lib.rs", r#" - #![feature(use_extern_macros)] - - extern crate wasm_bindgen; - extern crate js_sys; - use JsValue; - use wasm_bindgen::prelude::*; - use js_sys::WebAssembly; - - #[wasm_bindgen] - pub fn validate_wasm(wasm: JsValue) -> JsValue { - match WebAssembly::validate(wasm) { - Ok(value) => value.into(), - Err(err) => err - } - } - "#) - .file("test.js", r#" - import * as assert from "assert"; - import * as wasm from "./out"; - - export function test() { - assert.equal(wasm.validate_wasm(new ArrayBuffer(42)), false); - } - "#) - .test() -} - -#[test] -fn validate_with_invalid_input() { - project() - .file("src/lib.rs", r#" - #![feature(use_extern_macros)] - - extern crate wasm_bindgen; - extern crate js_sys; - use JsValue; - use wasm_bindgen::prelude::*; - use js_sys::WebAssembly; - - #[wasm_bindgen] - pub fn validate_wasm(wasm: JsValue) -> JsValue { - match WebAssembly::validate(wasm) { - Ok(value) => value.into(), - Err(err) => err - } - } - "#) - .file("test.js", r#" - import * as assert from "assert"; - import * as wasm from "./out"; - - export function test() { - try { - wasm.validate_wasm(42); - assert.ok(false); - } catch (e) { - assert.ok(true); - } - } - "#) - .test() -} diff --git a/crates/js-sys/tests/all/main.rs b/crates/js-sys/tests/all/main.rs index e7cba1a1..0b0b5ce9 100644 --- a/crates/js-sys/tests/all/main.rs +++ b/crates/js-sys/tests/all/main.rs @@ -12,7 +12,6 @@ fn project() -> project_builder::Project { mod ArrayIterator; mod Reflect; -mod WebAssembly; #[test] fn decode_uri() { diff --git a/crates/js-sys/tests/wasm/WebAssembly.rs b/crates/js-sys/tests/wasm/WebAssembly.rs new file mode 100644 index 00000000..f7d71e79 --- /dev/null +++ b/crates/js-sys/tests/wasm/WebAssembly.rs @@ -0,0 +1,9 @@ +use wasm_bindgen_test::*; +use js_sys::*; + +#[wasm_bindgen_test] +fn validate() { + assert!(!WebAssembly::validate(ArrayBuffer::new(42).into()).unwrap()); + + assert!(WebAssembly::validate(2.into()).is_err()); +} diff --git a/crates/js-sys/tests/wasm/main.rs b/crates/js-sys/tests/wasm/main.rs index a69fc00b..ffac76b0 100644 --- a/crates/js-sys/tests/wasm/main.rs +++ b/crates/js-sys/tests/wasm/main.rs @@ -29,3 +29,4 @@ pub mod Symbol; pub mod TypedArray; pub mod WeakMap; pub mod WeakSet; +pub mod WebAssembly;