Use std::any::type_name

This commit is contained in:
timfish
2019-09-30 18:57:21 +01:00
parent 20d30d93c3
commit 53bb0a38f0
3 changed files with 38 additions and 37 deletions

View File

@@ -1,4 +1,4 @@
use rhai::{Engine, EvalAltResult};
use rhai::{Engine, EvalAltResult, RegisterFn};
#[test]
fn test_mismatched_op() {
@@ -7,7 +7,32 @@ fn test_mismatched_op() {
assert_eq!(
engine.eval::<i64>("60 + \"hello\""),
Err(EvalAltResult::ErrorFunctionNotFound(
"+ (integer,string)".into()
"+ (i64,alloc::string::String)".into()
))
);
}
#[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(
"+ (i64,mismatched_op::test_mismatched_op_custom_type::TestStruct)".into()
))
);
}