Use matches! in examples.

This commit is contained in:
Stephen Chung
2020-03-14 23:40:30 +08:00
parent b9e4040635
commit 6e076c409d
6 changed files with 98 additions and 84 deletions

View File

@@ -1,18 +1,14 @@
use rhai::{Engine, EvalAltResult, INT};
use rhai::{Engine, EvalAltResult};
#[test]
fn test_throw() {
let mut engine = Engine::new();
match engine.eval::<INT>(r#"if true { throw "hello" }"#) {
Ok(_) => panic!("not an error"),
Err(EvalAltResult::ErrorRuntime(s, _)) if s == "hello" => (),
Err(err) => panic!("wrong error: {}", err),
}
assert!(matches!(
engine.eval::<()>(r#"if true { throw "hello" }"#).expect_err("expects error"),
EvalAltResult::ErrorRuntime(s, _) if s == "hello"));
match engine.eval::<INT>(r#"throw;"#) {
Ok(_) => panic!("not an error"),
Err(EvalAltResult::ErrorRuntime(s, _)) if s == "" => (),
Err(err) => panic!("wrong error: {}", err),
}
assert!(matches!(
engine.eval::<()>(r#"throw;"#).expect_err("expects error"),
EvalAltResult::ErrorRuntime(s, _) if s == ""));
}