mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-24 18:21:33 +00:00
bindings for parseInt/parseFloat (#384)
* parseInt, parseFloat, JsValue::is_nan * Number.parseInt, Number.parseFloat * remove `JsValue::is_nan` * parse_int/float returns f64
This commit is contained in:
committed by
Alex Crichton
parent
d6a0b34480
commit
bfec9e6401
@ -186,3 +186,34 @@ fn is_finite() {
|
||||
)
|
||||
.test();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_int_float() {
|
||||
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 test() {
|
||||
let i = js::parse_int("42", 10);
|
||||
assert_eq!(i as i64, 42);
|
||||
|
||||
let i = js::parse_int("42", 16);
|
||||
assert_eq!(i as i64, 66); // 0x42 == 66
|
||||
|
||||
let i = js::parse_int("invalid int", 10);
|
||||
assert!(i.is_nan());
|
||||
|
||||
let f = js::parse_float("123456.789");
|
||||
assert_eq!(f, 123456.789);
|
||||
|
||||
let f = js::parse_float("invalid float");
|
||||
assert!(f.is_nan());
|
||||
}
|
||||
"#)
|
||||
.test();
|
||||
}
|
||||
|
Reference in New Issue
Block a user