Add switch case conditions.

This commit is contained in:
Stephen Chung
2021-04-16 12:04:33 +08:00
parent c5128e15d5
commit 980a13ca42
7 changed files with 233 additions and 173 deletions

View File

@@ -67,6 +67,45 @@ fn test_switch() -> Result<(), Box<EvalAltResult>> {
Ok(())
}
#[test]
fn test_switch_condition() -> Result<(), Box<EvalAltResult>> {
let engine = Engine::new();
let mut scope = Scope::new();
scope.push("x", 42 as INT);
assert_eq!(
engine.eval_with_scope::<INT>(
&mut scope,
r"
switch x / 2 {
21 if x > 40 => 1,
0 if x < 100 => 2,
1 => 3,
_ => 9
}
"
)?,
1
);
assert_eq!(
engine.eval_with_scope::<INT>(
&mut scope,
r"
switch x / 2 {
21 if x < 40 => 1,
0 if x < 100 => 2,
1 => 3,
_ => 9
}
"
)?,
9
);
Ok(())
}
#[cfg(not(feature = "no_index"))]
#[cfg(not(feature = "no_object"))]
mod test_switch_enum {