2020-03-10 16:06:20 +01:00
|
|
|
use rhai::{Engine, EvalAltResult, INT};
|
2020-03-03 11:15:20 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_throw() {
|
|
|
|
let mut engine = Engine::new();
|
|
|
|
|
2020-03-10 16:06:20 +01:00
|
|
|
match engine.eval::<INT>(r#"if true { throw "hello" }"#) {
|
2020-03-03 11:15:20 +01:00
|
|
|
Ok(_) => panic!("not an error"),
|
|
|
|
Err(EvalAltResult::ErrorRuntime(s, _)) if s == "hello" => (),
|
|
|
|
Err(err) => panic!("wrong error: {}", err),
|
|
|
|
}
|
|
|
|
|
2020-03-10 16:06:20 +01:00
|
|
|
match engine.eval::<INT>(r#"throw;"#) {
|
2020-03-03 11:15:20 +01:00
|
|
|
Ok(_) => panic!("not an error"),
|
|
|
|
Err(EvalAltResult::ErrorRuntime(s, _)) if s == "" => (),
|
|
|
|
Err(err) => panic!("wrong error: {}", err),
|
|
|
|
}
|
|
|
|
}
|