mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-03 02:41:06 +00:00
Port MapIterator
tests to wasm
This commit is contained in:
parent
2c9a606c3d
commit
230f923fdb
@ -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()
|
|
||||||
}
|
|
@ -11,7 +11,6 @@ fn project() -> project_builder::Project {
|
|||||||
// Keep these tests in alphabetical order, just like the imports in `src/js.rs`.
|
// Keep these tests in alphabetical order, just like the imports in `src/js.rs`.
|
||||||
|
|
||||||
mod ArrayIterator;
|
mod ArrayIterator;
|
||||||
mod MapIterator;
|
|
||||||
mod Math;
|
mod Math;
|
||||||
mod Number;
|
mod Number;
|
||||||
mod Object;
|
mod Object;
|
||||||
|
23
crates/js-sys/tests/wasm/MapIterator.rs
Normal file
23
crates/js-sys/tests/wasm/MapIterator.rs
Normal 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());
|
||||||
|
}
|
@ -18,3 +18,4 @@ pub mod Generator;
|
|||||||
pub mod Intl;
|
pub mod Intl;
|
||||||
pub mod JsString;
|
pub mod JsString;
|
||||||
pub mod Map;
|
pub mod Map;
|
||||||
|
pub mod MapIterator;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user