Add case alternatives for switch.

This commit is contained in:
Stephen Chung
2022-07-04 17:42:24 +08:00
parent 54db9a2819
commit dee66a409f
9 changed files with 334 additions and 170 deletions

View File

@@ -45,6 +45,13 @@ fn test_switch() -> Result<(), Box<EvalAltResult>> {
engine.eval_with_scope::<()>(&mut scope, "switch x { 1 => 123, 2 => 'a' }")?,
()
);
assert_eq!(
engine.eval_with_scope::<INT>(
&mut scope,
"switch x { 1 | 2 | 3 | 5..50 | 'x' | true => 123, 'z' => 'a' }"
)?,
123
);
assert_eq!(
engine.eval::<INT>("let x = timestamp(); switch x { 1 => 123, _ => 42 }")?,
42