Refactor tests.

This commit is contained in:
Stephen Chung
2020-03-02 22:11:56 +08:00
parent ed8d2ac20f
commit 0707fad1ca
27 changed files with 338 additions and 317 deletions

View File

@@ -4,12 +4,12 @@ use rhai::{Engine, EvalAltResult, RegisterFn};
fn test_mismatched_op() {
let mut engine = Engine::new();
assert_eq!(
engine.eval::<i64>("60 + \"hello\""),
Err(EvalAltResult::ErrorMismatchOutputType(
"alloc::string::String".into()
))
);
let r = engine.eval::<i64>("60 + \"hello\"");
match r {
Err(EvalAltResult::ErrorMismatchOutputType(err, _)) if err == "alloc::string::String" => (),
_ => panic!(),
}
}
#[test]
@@ -29,10 +29,14 @@ fn test_mismatched_op_custom_type() {
engine.register_type::<TestStruct>();
engine.register_fn("new_ts", TestStruct::new);
assert_eq!(
engine.eval::<i64>("60 + new_ts()"),
Err(EvalAltResult::ErrorFunctionNotFound(
"+ (i64, mismatched_op::test_mismatched_op_custom_type::TestStruct)".into()
))
);
let r = engine.eval::<i64>("60 + new_ts()");
match r {
Err(EvalAltResult::ErrorFunctionNotFound(err, _))
if err == "+ (i64, mismatched_op::test_mismatched_op_custom_type::TestStruct)" =>
{
()
}
_ => panic!(),
}
}