From 230f923fdb0128002dfae0e543030945df6827f6 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 20 Jul 2018 13:57:18 -0700 Subject: [PATCH] Port `MapIterator` tests to `wasm` --- crates/js-sys/tests/all/MapIterator.rs | 100 ------------------------ crates/js-sys/tests/all/main.rs | 1 - crates/js-sys/tests/wasm/MapIterator.rs | 23 ++++++ crates/js-sys/tests/wasm/main.rs | 1 + 4 files changed, 24 insertions(+), 101 deletions(-) delete mode 100644 crates/js-sys/tests/all/MapIterator.rs create mode 100644 crates/js-sys/tests/wasm/MapIterator.rs diff --git a/crates/js-sys/tests/all/MapIterator.rs b/crates/js-sys/tests/all/MapIterator.rs deleted file mode 100644 index 73d0f7b1..00000000 --- a/crates/js-sys/tests/all/MapIterator.rs +++ /dev/null @@ -1,100 +0,0 @@ -#![allow(non_snake_case)] - -use project; - - -#[test] -fn entries() { - project() - .file("src/lib.rs", r#" - #![feature(use_extern_macros)] - - extern crate wasm_bindgen; - extern crate js_sys; - use wasm_bindgen::prelude::*; - - #[wasm_bindgen] - pub fn get_entries(this: &js_sys::Map) -> js_sys::MapIterator { - this.entries() - } - "#) - .file("test.js", r#" - import * as assert from "assert"; - import * as wasm from "./out"; - - export function test() { - const map = new Map(); - const iterator = map.entries(); - const wasmIterator = wasm.get_entries(map); - map.set('foo', 'bar'); - map.set('bar', 'baz'); - - assert.equal(iterator.toString(), wasmIterator.toString()); - } - "#) - .test() -} - -#[test] -fn keys() { - project() - .file("src/lib.rs", r#" - #![feature(use_extern_macros)] - - extern crate wasm_bindgen; - extern crate js_sys; - use wasm_bindgen::prelude::*; - - #[wasm_bindgen] - pub fn get_keys(this: &js_sys::Map) -> js_sys::MapIterator { - this.keys() - } - "#) - .file("test.js", r#" - import * as assert from "assert"; - import * as wasm from "./out"; - - export function test() { - const map = new Map(); - const iterator = map.keys(); - const wasmIterator = wasm.get_keys(map); - map.set('foo', 'bar'); - map.set('bar', 'baz'); - - assert.equal(iterator.toString(), wasmIterator.toString()); - } - "#) - .test() -} - -#[test] -fn values() { - project() - .file("src/lib.rs", r#" - #![feature(use_extern_macros)] - - extern crate wasm_bindgen; - extern crate js_sys; - use wasm_bindgen::prelude::*; - - #[wasm_bindgen] - pub fn get_values(this: &js_sys::Map) -> js_sys::MapIterator { - this.values() - } - "#) - .file("test.js", r#" - import * as assert from "assert"; - import * as wasm from "./out"; - - export function test() { - const map = new Map(); - const iterator = map.keys(); - const wasmIterator = wasm.get_values(map); - map.set('foo', 'bar'); - map.set('bar', 'baz'); - - assert.equal(iterator.toString(), wasmIterator.toString()); - } - "#) - .test() -} diff --git a/crates/js-sys/tests/all/main.rs b/crates/js-sys/tests/all/main.rs index c3ffcb44..19adfa1d 100644 --- a/crates/js-sys/tests/all/main.rs +++ b/crates/js-sys/tests/all/main.rs @@ -11,7 +11,6 @@ fn project() -> project_builder::Project { // Keep these tests in alphabetical order, just like the imports in `src/js.rs`. mod ArrayIterator; -mod MapIterator; mod Math; mod Number; mod Object; diff --git a/crates/js-sys/tests/wasm/MapIterator.rs b/crates/js-sys/tests/wasm/MapIterator.rs new file mode 100644 index 00000000..486c9891 --- /dev/null +++ b/crates/js-sys/tests/wasm/MapIterator.rs @@ -0,0 +1,23 @@ +use wasm_bindgen::JsValue; +use wasm_bindgen_test::*; +use js_sys::*; + +// TODO: not much you can do with `MapIterator` types yet :( + +#[wasm_bindgen_test] +fn entries() { + let map = Map::new(); + assert!(JsValue::from(map.entries()).is_object()); +} + +#[wasm_bindgen_test] +fn keys() { + let map = Map::new(); + assert!(JsValue::from(map.keys()).is_object()); +} + +#[wasm_bindgen_test] +fn values() { + let map = Map::new(); + assert!(JsValue::from(map.values()).is_object()); +} diff --git a/crates/js-sys/tests/wasm/main.rs b/crates/js-sys/tests/wasm/main.rs index b14ea339..58662568 100644 --- a/crates/js-sys/tests/wasm/main.rs +++ b/crates/js-sys/tests/wasm/main.rs @@ -18,3 +18,4 @@ pub mod Generator; pub mod Intl; pub mod JsString; pub mod Map; +pub mod MapIterator;