2019-09-30 19:57:21 +02:00
|
|
|
use rhai::{Engine, EvalAltResult, RegisterFn};
|
2017-11-03 17:58:51 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_mismatched_op() {
|
|
|
|
let mut engine = Engine::new();
|
|
|
|
|
2017-12-20 21:09:53 +01:00
|
|
|
assert_eq!(
|
|
|
|
engine.eval::<i64>("60 + \"hello\""),
|
2020-02-23 16:41:14 +01:00
|
|
|
Err(EvalAltResult::ErrorMismatchOutputType(
|
|
|
|
"alloc::string::String".into()
|
2019-09-30 19:57:21 +02:00
|
|
|
))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_mismatched_op_custom_type() {
|
|
|
|
#[derive(Clone)]
|
|
|
|
struct TestStruct {
|
|
|
|
x: i64,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TestStruct {
|
|
|
|
fn new() -> TestStruct {
|
|
|
|
TestStruct { x: 1 }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut engine = Engine::new();
|
|
|
|
engine.register_type::<TestStruct>();
|
|
|
|
engine.register_fn("new_ts", TestStruct::new);
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
engine.eval::<i64>("60 + new_ts()"),
|
|
|
|
Err(EvalAltResult::ErrorFunctionNotFound(
|
2020-02-24 16:25:52 +01:00
|
|
|
"+ (i64, mismatched_op::test_mismatched_op_custom_type::TestStruct)".into()
|
2019-09-18 12:21:07 +02:00
|
|
|
))
|
2017-12-20 21:09:53 +01:00
|
|
|
);
|
2017-11-03 17:58:51 +01:00
|
|
|
}
|