rhai/tests/ops.rs

24 lines
471 B
Rust
Raw Normal View History

2020-03-02 15:11:56 +01:00
use rhai::{Engine, EvalAltResult};
2017-11-03 17:58:51 +01:00
#[test]
2020-03-02 15:11:56 +01:00
fn test_ops() -> Result<(), EvalAltResult> {
2017-11-03 17:58:51 +01:00
let mut engine = Engine::new();
2020-03-02 15:11:56 +01:00
assert_eq!(engine.eval::<i64>("60 + 5")?, 65);
assert_eq!(engine.eval::<i64>("(1 + 2) * (6 - 4) / 2")?, 3);
Ok(())
2017-11-03 17:58:51 +01:00
}
#[test]
2020-03-02 15:11:56 +01:00
fn test_op_prec() -> Result<(), EvalAltResult> {
2017-11-03 17:58:51 +01:00
let mut engine = Engine::new();
assert_eq!(
2020-03-02 15:11:56 +01:00
engine.eval::<i64>("let x = 0; if x == 10 || true { x = 1} x")?,
1
);
2020-03-02 15:11:56 +01:00
Ok(())
}