mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-13 04:51:23 +00:00
Merge pull request #392 from brisad/add-more-bindings
Add bindings in Date and Number
This commit is contained in:
@ -2,6 +2,40 @@
|
||||
|
||||
use super::project;
|
||||
|
||||
#[test]
|
||||
fn get_date() {
|
||||
project()
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::js::{Date, Number};
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn get_date(this: &Date) -> Number {
|
||||
this.get_date()
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function test() {
|
||||
let date = new Date(1993, 6, 28, 14, 39, 7);
|
||||
|
||||
assert.equal(wasm.get_date(date), 28);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn get_day() {
|
||||
project()
|
||||
|
@ -2,6 +2,33 @@
|
||||
|
||||
use super::project;
|
||||
|
||||
#[test]
|
||||
fn is_integer() {
|
||||
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 is_integer(obj: &js::Object) -> bool {
|
||||
js::Number::is_integer(&obj)
|
||||
}
|
||||
"#)
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function test() {
|
||||
assert.ok(wasm.is_integer(123));
|
||||
assert.ok(!wasm.is_integer(123.45));
|
||||
}
|
||||
"#)
|
||||
.test()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn new() {
|
||||
project()
|
||||
|
Reference in New Issue
Block a user