wasm-bindgen/crates/js-sys/tests/wasm/MapIterator.rs

53 lines
1.2 KiB
Rust
Raw Normal View History

2018-07-20 23:57:18 +03:00
use wasm_bindgen_test::*;
use js_sys::*;
#[wasm_bindgen_test]
fn entries() {
let map = Map::new();
map.set(&"uno".into(), &1.into());
let entries = map.entries();
let next = entries.next().unwrap();
assert_eq!(next.done(), false);
assert!(next.value().is_object());
assert_eq!(Reflect::get(&next.value(), &0.into()), "uno");
assert_eq!(Reflect::get(&next.value(), &1.into()), 1);
let next = entries.next().unwrap();
assert!(next.done());
assert!(next.value().is_undefined());
2018-07-20 23:57:18 +03:00
}
#[wasm_bindgen_test]
fn keys() {
let map = Map::new();
map.set(&"uno".into(), &1.into());
let keys = map.keys();
let next = keys.next().unwrap();
assert_eq!(next.done(), false);
assert_eq!(next.value(), "uno");
let next = keys.next().unwrap();
assert!(next.done());
assert!(next.value().is_undefined());
2018-07-20 23:57:18 +03:00
}
#[wasm_bindgen_test]
fn values() {
let map = Map::new();
map.set(&"uno".into(), &1.into());
let values = map.values();
let next = values.next().unwrap();
assert_eq!(next.done(), false);
assert_eq!(next.value(), 1);
let next = values.next().unwrap();
assert!(next.done());
assert!(next.value().is_undefined());
2018-07-20 23:57:18 +03:00
}