Port MapIterator tests to wasm

This commit is contained in:
Alex Crichton 2018-07-20 13:57:18 -07:00
parent 2c9a606c3d
commit 230f923fdb
4 changed files with 24 additions and 101 deletions

View File

@ -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()
}

View File

@ -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;

View File

@ -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());
}

View File

@ -18,3 +18,4 @@ pub mod Generator;
pub mod Intl;
pub mod JsString;
pub mod Map;
pub mod MapIterator;