2020-04-15 16:21:23 +02:00
|
|
|
#![cfg(not(feature = "no_std"))]
|
2020-04-11 10:06:57 +02:00
|
|
|
|
|
|
|
use rhai::{Engine, EvalAltResult, INT};
|
|
|
|
|
|
|
|
#[cfg(not(feature = "no_float"))]
|
|
|
|
use rhai::FLOAT;
|
|
|
|
|
|
|
|
#[test]
|
2020-04-21 17:25:12 +02:00
|
|
|
fn test_timestamp() -> Result<(), Box<EvalAltResult>> {
|
2020-04-11 10:06:57 +02:00
|
|
|
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(())
|
|
|
|
}
|