mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-11-28 14:27:36 +03:00
test: Move Object
-related js_globals tests to submodule file
This commit is contained in:
parent
d9cac3bd90
commit
a201cafdea
56
tests/all/js_globals/Object.rs
Executable file
56
tests/all/js_globals/Object.rs
Executable 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()
|
||||||
|
}
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
use super::project;
|
use super::project;
|
||||||
|
|
||||||
|
mod Object;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
fn decode_uri() {
|
fn decode_uri() {
|
||||||
@ -90,61 +92,3 @@ fn eval() {
|
|||||||
"#)
|
"#)
|
||||||
.test();
|
.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()
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user