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_or_equals() -> 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>("let x = 16; x |= 74; x")?, 90);
|
|
|
|
assert_eq!(engine.eval::<bool>("let x = true; x |= false; x")?, true);
|
|
|
|
assert_eq!(engine.eval::<bool>("let x = false; x |= true; x")?, true);
|
|
|
|
|
|
|
|
Ok(())
|
2017-11-03 17:58:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-03-02 15:11:56 +01:00
|
|
|
fn test_and_equals() -> 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>("let x = 16; x &= 31; x")?, 16);
|
|
|
|
assert_eq!(engine.eval::<bool>("let x = true; x &= false; x")?, false);
|
|
|
|
assert_eq!(engine.eval::<bool>("let x = false; x &= true; x")?, false);
|
|
|
|
assert_eq!(engine.eval::<bool>("let x = true; x &= true; x")?, true);
|
|
|
|
|
|
|
|
Ok(())
|
2017-11-03 17:58:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-03-02 15:11:56 +01:00
|
|
|
fn test_xor_equals() -> 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>("let x = 90; x ^= 12; x")?, 86);
|
|
|
|
Ok(())
|
2017-11-03 17:58:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-03-02 15:11:56 +01:00
|
|
|
fn test_multiply_equals() -> 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>("let x = 2; x *= 3; x")?, 6);
|
|
|
|
Ok(())
|
2017-11-03 17:58:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-03-02 15:11:56 +01:00
|
|
|
fn test_divide_equals() -> 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>("let x = 6; x /= 2; x")?, 3);
|
|
|
|
Ok(())
|
2017-11-03 17:58:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-03-02 15:11:56 +01:00
|
|
|
fn test_left_shift_equals() -> 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>("let x = 9; x >>=1; x")?, 4);
|
|
|
|
Ok(())
|
2017-11-03 17:58:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-03-02 15:11:56 +01:00
|
|
|
fn test_right_shift_equals() -> 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>("let x = 4; x<<= 2; x")?, 16);
|
|
|
|
Ok(())
|
2017-11-03 17:58:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-03-02 15:11:56 +01:00
|
|
|
fn test_modulo_equals() -> 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>("let x = 10; x %= 4; x")?, 2);
|
|
|
|
Ok(())
|
2018-06-13 10:56:29 +02:00
|
|
|
}
|