2018-07-25 13:34:35 +03:00
|
|
|
#![cfg(target_arch = "wasm32")]
|
2018-06-22 00:00:02 +03:00
|
|
|
|
2018-07-25 13:34:35 +03:00
|
|
|
extern crate wasm_bindgen_test;
|
|
|
|
extern crate wasm_bindgen;
|
|
|
|
extern crate js_sys;
|
2018-07-22 06:09:45 +03:00
|
|
|
|
2018-07-25 13:34:35 +03:00
|
|
|
use wasm_bindgen::prelude::*;
|
|
|
|
use wasm_bindgen_test::*;
|
|
|
|
use js_sys::Array;
|
|
|
|
|
|
|
|
wasm_bindgen_test_configure!(run_in_browser);
|
|
|
|
|
|
|
|
#[wasm_bindgen(module = "./tests/headless.js")]
|
|
|
|
extern {
|
|
|
|
fn is_array_values_supported()-> bool;
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen]
|
|
|
|
extern {
|
|
|
|
type ValuesIterator;
|
|
|
|
#[wasm_bindgen(method, structural)]
|
|
|
|
fn next(this: &ValuesIterator) -> IterNext;
|
|
|
|
|
|
|
|
type IterNext;
|
|
|
|
|
|
|
|
#[wasm_bindgen(method, getter, structural)]
|
|
|
|
fn value(this: &IterNext) -> JsValue;
|
|
|
|
#[wasm_bindgen(method, getter, structural)]
|
|
|
|
fn done(this: &IterNext) -> bool;
|
2018-07-22 06:09:45 +03:00
|
|
|
}
|
|
|
|
|
2018-07-25 13:34:35 +03:00
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn array_iterator_values() {
|
|
|
|
if !is_array_values_supported() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
let array = Array::new();
|
|
|
|
array.push(&8.into());
|
|
|
|
array.push(&3.into());
|
|
|
|
array.push(&2.into());
|
|
|
|
let iter = ValuesIterator::from(JsValue::from(array.values()));
|
|
|
|
|
|
|
|
assert_eq!(iter.next().value(), 8);
|
|
|
|
assert_eq!(iter.next().value(), 3);
|
|
|
|
assert_eq!(iter.next().value(), 2);
|
|
|
|
assert!(iter.next().done());
|
2018-07-09 20:42:30 +03:00
|
|
|
}
|