summaryrefslogtreecommitdiffstats
path: root/vendor/js-sys/tests/wasm/SetIterator.rs
blob: ff853825b14c0410032bba06d0ee8a7c565dc8d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use js_sys::*;
use wasm_bindgen::prelude::*;
use wasm_bindgen_test::*;

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