mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-12-17 22:51:47 +03:00
62de3bad67
The JS iterator protocol uses duck typing and we don't need separate ArrayIterator and SetIterator etc types, we can have a single iterator type for the whole protocol.
42 lines
990 B
Rust
42 lines
990 B
Rust
use wasm_bindgen::prelude::*;
|
|
use wasm_bindgen_test::*;
|
|
use js_sys::*;
|
|
|
|
#[wasm_bindgen_test]
|
|
fn entries() {
|
|
let s = Set::new(&JsValue::undefined());
|
|
s.add(&1.into());
|
|
let iter = s.entries();
|
|
let obj = iter.next().unwrap();
|
|
assert!(!obj.done());
|
|
let array = Array::from(&obj.value());
|
|
assert_eq!(array.length(), 2);
|
|
array.for_each(&mut |a, _, _| {
|
|
assert_eq!(a, 1);
|
|
});
|
|
|
|
assert!(iter.next().unwrap().done());
|
|
}
|
|
|
|
#[wasm_bindgen_test]
|
|
fn keys() {
|
|
let s = Set::new(&JsValue::undefined());
|
|
s.add(&1.into());
|
|
let iter = s.keys();
|
|
let obj = iter.next().unwrap();
|
|
assert!(!obj.done());
|
|
assert_eq!(obj.value(), 1);
|
|
assert!(iter.next().unwrap().done());
|
|
}
|
|
|
|
#[wasm_bindgen_test]
|
|
fn values() {
|
|
let s = Set::new(&JsValue::undefined());
|
|
s.add(&1.into());
|
|
let iter = s.values();
|
|
let obj = iter.next().unwrap();
|
|
assert!(!obj.done());
|
|
assert_eq!(obj.value(), 1);
|
|
assert!(iter.next().unwrap().done());
|
|
}
|