wasm-bindgen/tests/all/js_globals/ArrayIterator.rs

70 lines
1.9 KiB
Rust
Raw Normal View History

2018-06-22 00:00:02 +03:00
#![allow(non_snake_case)]
use project;
#[test]
fn keys() {
project()
.file("src/lib.rs", r#"
#![feature(proc_macro, wasm_custom_section)]
extern crate wasm_bindgen;
use wasm_bindgen::prelude::*;
use wasm_bindgen::js;
#[wasm_bindgen]
pub fn get_keys(this: &js::Array) -> js::ArrayIterator {
this.keys()
}
"#)
.file("test.ts", r#"
import * as assert from "assert";
import * as wasm from "./out";
export function test() {
let characters = [8, 5, 4, 3, 1, 2]
let iterator = characters.keys();
let wasmIterator = wasm.get_keys(characters);
assert.equal(iterator.toString(), wasmIterator.toString());
2018-06-22 00:11:08 +03:00
assert.equal(Array.from(iterator)[0], Array.from(wasmIterator)[0]);
}
"#)
.test()
}
#[test]
fn entries() {
project()
.file("src/lib.rs", r#"
#![feature(proc_macro, wasm_custom_section)]
extern crate wasm_bindgen;
use wasm_bindgen::prelude::*;
use wasm_bindgen::js;
#[wasm_bindgen]
pub fn get_entries(this: &js::Array) -> js::ArrayIterator {
this.entries()
}
"#)
.file("test.ts", r#"
import * as assert from "assert";
import * as wasm from "./out";
export function test() {
let characters = [8, 5, 4, 3, 1, 2]
let iterator = characters.entries();
let wasmIterator = wasm.get_entries(characters);
let jsItem = iterator.next();
let wasmItem = wasmIterator.next();
assert.equal(iterator.toString(), wasmIterator.toString());
assert.equal(jsItem.value[1], wasmItem.value[1]);
2018-06-22 00:00:02 +03:00
}
"#)
.test()
}