Unroll switch ranges if possible.

This commit is contained in:
Stephen Chung
2022-07-18 08:54:10 +08:00
parent 107193e35f
commit 4b760d1d0f
5 changed files with 132 additions and 60 deletions

View File

@@ -290,6 +290,49 @@ fn test_switch_ranges() -> Result<(), Box<EvalAltResult>> {
)?,
'x'
);
assert_eq!(
engine.eval_with_scope::<INT>(
&mut scope,
"
switch 5 {
'a' => true,
0..10 => 123,
2..12 => 'z',
_ => 'x'
}
"
)?,
123
);
assert_eq!(
engine.eval_with_scope::<INT>(
&mut scope,
"
switch 5 {
'a' => true,
4 | 5 | 6 => 42,
0..10 => 123,
2..12 => 'z',
_ => 'x'
}
"
)?,
42
);
assert_eq!(
engine.eval_with_scope::<char>(
&mut scope,
"
switch 5 {
'a' => true,
2..12 => 'z',
0..10 if x+2==1+2 => print(40+2),
_ => 'x'
}
"
)?,
'z'
);
assert_eq!(
engine.eval_with_scope::<char>(
&mut scope,