test: Move Object-related js_globals tests to submodule file

This commit is contained in:
Nick Fitzgerald 2018-06-19 10:15:09 -07:00
parent d9cac3bd90
commit a201cafdea
2 changed files with 58 additions and 58 deletions

56
tests/all/js_globals/Object.rs Executable file
View File

@ -0,0 +1,56 @@
#![allow(non_snake_case)]
use project;
#[test]
fn new() {
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 new_object() -> js::Object {
js::Object::new()
}
"#)
.file("test.ts", r#"
import * as assert from "assert";
import * as wasm from "./out";
export function test() {
assert.equal(typeof wasm.new_object(), "object");
}
"#)
.test()
}
#[test]
fn has_own_property() {
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 has_own_foo_property(obj: &js::Object) -> bool {
obj.has_own_property("foo")
}
"#)
.file("test.ts", r#"
import * as assert from "assert";
import * as wasm from "./out";
export function test() {
assert.ok(wasm.has_own_foo_property({ foo: 42 }));
assert.ok(!wasm.has_own_foo_property({}));
}
"#)
.test()
}

View File

@ -2,6 +2,8 @@
use super::project;
mod Object;
#[test]
#[cfg(feature = "std")]
fn decode_uri() {
@ -90,61 +92,3 @@ fn eval() {
"#)
.test();
}
#[allow(non_snake_case)]
mod Object {
use project;
#[test]
fn new() {
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 new_object() -> js::Object {
js::Object::new()
}
"#)
.file("test.ts", r#"
import * as assert from "assert";
import * as wasm from "./out";
export function test() {
assert.equal(typeof wasm.new_object(), "object");
}
"#)
.test()
}
#[test]
fn has_own_property() {
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 has_own_foo_property(obj: &js::Object) -> bool {
obj.has_own_property("foo")
}
"#)
.file("test.ts", r#"
import * as assert from "assert";
import * as wasm from "./out";
export function test() {
assert.ok(wasm.has_own_foo_property({ foo: 42 }));
assert.ok(!wasm.has_own_foo_property({}));
}
"#)
.test()
}
}