Add timestamp support.
This commit is contained in:
@@ -24,6 +24,7 @@ fn test_string() -> Result<(), EvalAltResult> {
|
||||
assert_eq!(engine.eval::<String>(r#""foo" + 123"#)?, "foo123");
|
||||
|
||||
#[cfg(not(feature = "no_stdlib"))]
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
assert_eq!(engine.eval::<String>("(42).to_string()")?, "42");
|
||||
|
||||
#[cfg(not(feature = "no_float"))]
|
||||
|
39
tests/time.rs
Normal file
39
tests/time.rs
Normal file
@@ -0,0 +1,39 @@
|
||||
#![cfg(not(feature = "no_stdlib"))]
|
||||
|
||||
use rhai::{Engine, EvalAltResult, INT};
|
||||
|
||||
#[cfg(not(feature = "no_float"))]
|
||||
use rhai::FLOAT;
|
||||
|
||||
#[test]
|
||||
fn test_timestamp() -> Result<(), EvalAltResult> {
|
||||
let engine = Engine::new();
|
||||
|
||||
assert_eq!(engine.eval::<String>("type_of(timestamp())")?, "timestamp");
|
||||
|
||||
#[cfg(not(feature = "no_float"))]
|
||||
assert!(
|
||||
engine.eval::<FLOAT>(
|
||||
r#"
|
||||
let time = timestamp();
|
||||
let x = 10_000;
|
||||
while x > 0 { x -= 1; }
|
||||
elapsed(time)
|
||||
"#
|
||||
)? < 10.0
|
||||
);
|
||||
|
||||
#[cfg(feature = "no_float")]
|
||||
assert!(
|
||||
engine.eval::<INT>(
|
||||
r#"
|
||||
let time = timestamp();
|
||||
let x = 10_000;
|
||||
while x > 0 { x -= 1; }
|
||||
elapsed(time)
|
||||
"#
|
||||
)? < 10
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
Reference in New Issue
Block a user