Add parse_int and parse_float.

This commit is contained in:
Stephen Chung
2020-09-23 12:00:03 +08:00
parent 035b9cb839
commit ed38b50490
6 changed files with 85 additions and 5 deletions

View File

@@ -20,6 +20,15 @@ fn test_float() -> Result<(), Box<EvalAltResult>> {
Ok(())
}
#[test]
fn test_float_parse() -> Result<(), Box<EvalAltResult>> {
let engine = Engine::new();
assert!((engine.eval::<FLOAT>(r#"parse_float("9.9999")"#)? - 9.9999 as FLOAT).abs() < EPSILON);
Ok(())
}
#[test]
#[cfg(not(feature = "no_object"))]
fn test_struct_with_float() -> Result<(), Box<EvalAltResult>> {

View File

@@ -108,3 +108,14 @@ fn test_math() -> Result<(), Box<EvalAltResult>> {
Ok(())
}
#[test]
fn test_math_parse() -> Result<(), Box<EvalAltResult>> {
let engine = Engine::new();
assert_eq!(engine.eval::<INT>(r#"parse_int("42")"#)?, 42);
assert_eq!(engine.eval::<INT>(r#"parse_int("42", 16)"#)?, 0x42);
assert_eq!(engine.eval::<INT>(r#"parse_int("abcdef", 16)"#)?, 0xabcdef);
Ok(())
}