2018-06-22 00:00:02 +03:00
|
|
|
#![allow(non_snake_case)]
|
|
|
|
|
|
|
|
use project;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn keys() {
|
|
|
|
project()
|
2018-06-28 08:42:34 +03:00
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2018-07-19 16:57:18 +03:00
|
|
|
#![feature(use_extern_macros)]
|
2018-06-22 00:00:02 +03:00
|
|
|
|
|
|
|
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()
|
|
|
|
}
|
|
|
|
|
2018-06-28 08:42:34 +03:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
2018-07-05 06:37:09 +03:00
|
|
|
"test.js",
|
2018-06-28 08:42:34 +03:00
|
|
|
r#"
|
2018-06-22 00:00:02 +03:00
|
|
|
import * as assert from "assert";
|
|
|
|
import * as wasm from "./out";
|
|
|
|
|
|
|
|
export function test() {
|
2018-07-09 20:42:30 +03:00
|
|
|
let numbers = [8, 5, 4, 3, 1, 2];
|
|
|
|
let iterator = numbers.keys();
|
|
|
|
let wasmIterator = wasm.get_keys(numbers);
|
2018-06-22 00:00:02 +03:00
|
|
|
|
|
|
|
assert.equal(iterator.toString(), wasmIterator.toString());
|
2018-06-22 00:11:08 +03:00
|
|
|
assert.equal(Array.from(iterator)[0], Array.from(wasmIterator)[0]);
|
|
|
|
}
|
2018-06-28 08:42:34 +03:00
|
|
|
"#,
|
|
|
|
)
|
2018-06-22 00:11:08 +03:00
|
|
|
.test()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn entries() {
|
|
|
|
project()
|
2018-06-28 08:42:34 +03:00
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2018-07-19 16:57:18 +03:00
|
|
|
#![feature(use_extern_macros)]
|
2018-06-22 00:11:08 +03:00
|
|
|
|
|
|
|
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()
|
|
|
|
}
|
|
|
|
|
2018-06-28 08:42:34 +03:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
2018-07-05 06:37:09 +03:00
|
|
|
"test.js",
|
2018-06-28 08:42:34 +03:00
|
|
|
r#"
|
2018-06-22 00:11:08 +03:00
|
|
|
import * as assert from "assert";
|
|
|
|
import * as wasm from "./out";
|
|
|
|
|
|
|
|
export function test() {
|
2018-07-09 20:42:30 +03:00
|
|
|
let numbers = [8, 5, 4, 3, 1, 2];
|
|
|
|
let iterator = numbers.entries();
|
|
|
|
let wasmIterator = wasm.get_entries(numbers);
|
2018-06-22 00:11:08 +03:00
|
|
|
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
|
|
|
}
|
2018-06-28 08:42:34 +03:00
|
|
|
"#,
|
|
|
|
)
|
2018-06-22 00:00:02 +03:00
|
|
|
.test()
|
|
|
|
}
|
2018-07-09 20:42:30 +03:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn values() {
|
2018-07-10 02:35:25 +03:00
|
|
|
let mut project = project();
|
|
|
|
project.file(
|
2018-07-09 20:42:30 +03:00
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2018-07-19 16:57:18 +03:00
|
|
|
#![feature(use_extern_macros)]
|
2018-07-09 20:42:30 +03:00
|
|
|
|
|
|
|
extern crate wasm_bindgen;
|
|
|
|
use wasm_bindgen::prelude::*;
|
|
|
|
use wasm_bindgen::js;
|
|
|
|
|
|
|
|
#[wasm_bindgen]
|
|
|
|
pub fn get_values(this: &js::Array) -> js::ArrayIterator {
|
|
|
|
this.values()
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"test.js",
|
|
|
|
r#"
|
|
|
|
import * as assert from "assert";
|
|
|
|
import * as wasm from "./out";
|
|
|
|
|
|
|
|
export function test() {
|
2018-07-10 02:35:25 +03:00
|
|
|
if (typeof Array.prototype.values !== "function") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-09 20:42:30 +03:00
|
|
|
let numbers = [8, 3, 2];
|
|
|
|
let wasmIterator = wasm.get_values(numbers);
|
|
|
|
|
|
|
|
assert.equal(wasmIterator.next().value, 8);
|
|
|
|
assert.equal(wasmIterator.next().value, 3);
|
|
|
|
assert.equal(wasmIterator.next().value, 2);
|
|
|
|
assert.ok(wasmIterator.next().done);
|
|
|
|
}
|
|
|
|
"#,
|
2018-07-10 02:35:25 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
let mut headless = project.clone();
|
|
|
|
headless.headless(true);
|
|
|
|
|
|
|
|
project.test();
|
|
|
|
headless.test();
|
2018-07-09 20:42:30 +03:00
|
|
|
}
|