2018-07-22 06:09:45 +03:00
|
|
|
#![cfg(not(target_arch = "wasm32"))]
|
2018-06-22 00:00:02 +03:00
|
|
|
#![allow(non_snake_case)]
|
|
|
|
|
2018-07-22 06:09:45 +03:00
|
|
|
extern crate wasm_bindgen_test_project_builder as project_builder;
|
|
|
|
|
|
|
|
fn project() -> project_builder::Project {
|
|
|
|
let mut p = project_builder::project();
|
|
|
|
p.add_local_dependency("js-sys", env!("CARGO_MANIFEST_DIR"));
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
|
|
|
// NB: currently this older test suite is only used for tests which require
|
|
|
|
// headless browser support, otherwise all new tests should go in the `wasm`
|
|
|
|
// test suite next to this one.
|
2018-07-09 20:42:30 +03:00
|
|
|
|
|
|
|
#[test]
|
2018-07-22 06:09:45 +03:00
|
|
|
fn ArrayIterator_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;
|
2018-07-19 22:30:58 +03:00
|
|
|
extern crate js_sys;
|
2018-07-09 20:42:30 +03:00
|
|
|
use wasm_bindgen::prelude::*;
|
|
|
|
|
|
|
|
#[wasm_bindgen]
|
2018-07-19 22:30:58 +03:00
|
|
|
pub fn get_values(this: &js_sys::Array) -> js_sys::ArrayIterator {
|
2018-07-09 20:42:30 +03:00
|
|
|
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
|
|
|
}
|