mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-16 18:20:51 +00:00
Port WebAssembly
tests to wasm
This commit is contained in:
parent
9f7eea1e75
commit
5f87ed4cef
@ -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()
|
||||
}
|
@ -12,7 +12,6 @@ fn project() -> project_builder::Project {
|
||||
|
||||
mod ArrayIterator;
|
||||
mod Reflect;
|
||||
mod WebAssembly;
|
||||
|
||||
#[test]
|
||||
fn decode_uri() {
|
||||
|
9
crates/js-sys/tests/wasm/WebAssembly.rs
Normal file
9
crates/js-sys/tests/wasm/WebAssembly.rs
Normal file
@ -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());
|
||||
}
|
@ -29,3 +29,4 @@ pub mod Symbol;
|
||||
pub mod TypedArray;
|
||||
pub mod WeakMap;
|
||||
pub mod WeakSet;
|
||||
pub mod WebAssembly;
|
||||
|
Loading…
x
Reference in New Issue
Block a user