summaryrefslogtreecommitdiffstats
path: root/vendor/js-sys/tests/wasm/MapIterator.rs
blob: 6a6eec391fb6e6eb2e6958dd3ba9a982d38ad461 (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
42
43
44
45
46
47
48
49
50
51
52
use js_sys::*;
use wasm_bindgen_test::*;

#[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()).unwrap(), "uno");
    assert_eq!(Reflect::get(&next.value(), &1.into()).unwrap(), 1);

    let next = entries.next().unwrap();
    assert!(next.done());
    assert!(next.value().is_undefined());
}

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

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