rhai/tests/if_block.rs

30 lines
762 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_if() -> 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>("if true { 55 }")?, 55);
assert_eq!(engine.eval::<i64>("if false { 55 } else { 44 }")?, 44);
assert_eq!(engine.eval::<i64>("if true { 55 } else { 44 }")?, 55);
2020-03-02 10:04:56 +01:00
assert_eq!(
2020-03-02 15:11:56 +01:00
engine.eval::<i64>("if false { 55 } else if true { 33 } else { 44 }")?,
33
2020-03-02 10:04:56 +01:00
);
assert_eq!(
engine.eval::<i64>(
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
}