2020-03-10 16:06:20 +01:00
|
|
|
use rhai::{Engine, EvalAltResult, INT};
|
2017-11-03 17:58:51 +01:00
|
|
|
|
|
|
|
#[test]
|
2020-03-02 15:11:56 +01:00
|
|
|
fn test_if() -> Result<(), EvalAltResult> {
|
2017-11-03 17:58:51 +01:00
|
|
|
let mut engine = Engine::new();
|
|
|
|
|
2020-03-10 16:06:20 +01:00
|
|
|
assert_eq!(engine.eval::<INT>("if true { 55 }")?, 55);
|
|
|
|
assert_eq!(engine.eval::<INT>("if false { 55 } else { 44 }")?, 44);
|
|
|
|
assert_eq!(engine.eval::<INT>("if true { 55 } else { 44 }")?, 55);
|
2020-03-02 10:04:56 +01:00
|
|
|
assert_eq!(
|
2020-03-10 16:06:20 +01:00
|
|
|
engine.eval::<INT>("if false { 55 } else if true { 33 } else { 44 }")?,
|
2020-03-02 15:11:56 +01:00
|
|
|
33
|
2020-03-02 10:04:56 +01:00
|
|
|
);
|
|
|
|
assert_eq!(
|
2020-03-10 16:06:20 +01:00
|
|
|
engine.eval::<INT>(
|
2020-03-02 10:04:56 +01:00
|
|
|
r"
|
|
|
|
if false { 55 }
|
|
|
|
else if false { 33 }
|
|
|
|
else if false { 66 }
|
|
|
|
else if false { 77 }
|
|
|
|
else if false { 88 }
|
|
|
|
else { 44 }
|
|
|
|
"
|
2020-03-02 15:11:56 +01:00
|
|
|
)?,
|
|
|
|
44
|
2020-03-02 10:04:56 +01:00
|
|
|
);
|
2020-03-02 15:11:56 +01:00
|
|
|
|
|
|
|
Ok(())
|
2017-11-03 17:58:51 +01:00
|
|
|
}
|