Code cleanup
This commit is contained in:
parent
ca64668e58
commit
4f771d904a
@ -5,7 +5,7 @@ use crate::calc_fn_hash;
|
||||
use crate::engine::{
|
||||
search_imports, search_namespace, search_scope_only, Engine, Imports, State, KEYWORD_DEBUG,
|
||||
KEYWORD_EVAL, KEYWORD_FN_PTR, KEYWORD_FN_PTR_CALL, KEYWORD_FN_PTR_CURRY, KEYWORD_PRINT,
|
||||
KEYWORD_TYPE_OF, KEYWORD_SHARED, KEYWORD_TAKE
|
||||
KEYWORD_TYPE_OF, KEYWORD_SHARED,
|
||||
};
|
||||
use crate::error::ParseErrorType;
|
||||
use crate::fn_native::{FnCallArgs, FnPtr};
|
||||
@ -31,7 +31,7 @@ use crate::parser::FLOAT;
|
||||
use crate::engine::{FN_IDX_GET, FN_IDX_SET};
|
||||
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
use crate::engine::{Map, Target, FN_GET, FN_SET};
|
||||
use crate::engine::{Map, Target, FN_GET, FN_SET, KEYWORD_TAKE};
|
||||
|
||||
use crate::stdlib::{
|
||||
any::{type_name, TypeId},
|
||||
|
@ -1,6 +1,6 @@
|
||||
//! Module defining interfaces to native-Rust functions.
|
||||
|
||||
use crate::any::{Dynamic, Variant};
|
||||
use crate::any::Dynamic;
|
||||
use crate::calc_fn_hash;
|
||||
use crate::engine::Engine;
|
||||
use crate::module::Module;
|
||||
|
@ -15,7 +15,7 @@ use crate::stdlib::{
|
||||
any::TypeId,
|
||||
boxed::Box,
|
||||
mem,
|
||||
string::{String, ToString},
|
||||
string::String,
|
||||
};
|
||||
|
||||
/// Trait to register custom functions with the `Engine`.
|
||||
|
@ -1,6 +1,12 @@
|
||||
#![cfg(not(feature = "no_function"))]
|
||||
use rhai::{Dynamic, Engine, EvalAltResult, RegisterFn, FnPtr, Module, INT, Array};
|
||||
use std::any::{TypeId, Any};
|
||||
use rhai::{Dynamic, Engine, EvalAltResult, FnPtr, Module, INT};
|
||||
use std::any::TypeId;
|
||||
|
||||
#[cfg(not(feature = "no_shared"))]
|
||||
use rhai::RegisterFn;
|
||||
|
||||
#[cfg(not(feature = "no_index"))]
|
||||
use rhai::Array;
|
||||
|
||||
#[test]
|
||||
fn test_fn_ptr_curry_call() -> Result<(), Box<EvalAltResult>> {
|
||||
@ -35,7 +41,7 @@ fn test_fn_ptr_curry_call() -> Result<(), Box<EvalAltResult>> {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(not(feature = "no_capture"))]
|
||||
#[cfg(all(not(feature = "no_capture"), not(feature = "no_object")))]
|
||||
fn test_closures() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
@ -110,6 +116,8 @@ fn test_shared() -> Result<(), Box<EvalAltResult>> {
|
||||
'x'
|
||||
);
|
||||
|
||||
#[cfg(not(feature = "no_index"))]
|
||||
{
|
||||
assert_eq!(
|
||||
engine.eval::<String>(
|
||||
r#"
|
||||
@ -124,8 +132,6 @@ fn test_shared() -> Result<(), Box<EvalAltResult>> {
|
||||
"teSt"
|
||||
);
|
||||
|
||||
#[cfg(not(feature = "no_index"))]
|
||||
{
|
||||
assert_eq!(
|
||||
engine.eval::<Array>(
|
||||
r#"
|
||||
@ -137,6 +143,7 @@ fn test_shared() -> Result<(), Box<EvalAltResult>> {
|
||||
5
|
||||
);
|
||||
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
assert_eq!(
|
||||
engine.eval::<INT>(
|
||||
r"
|
||||
@ -170,6 +177,7 @@ fn test_shared() -> Result<(), Box<EvalAltResult>> {
|
||||
true
|
||||
);
|
||||
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
assert_eq!(
|
||||
engine.eval::<INT>(
|
||||
r#"
|
||||
@ -250,6 +258,8 @@ fn test_shared() -> Result<(), Box<EvalAltResult>> {
|
||||
42
|
||||
);
|
||||
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
{
|
||||
#[derive(Clone)]
|
||||
struct TestStruct {
|
||||
x: INT,
|
||||
@ -277,14 +287,13 @@ fn test_shared() -> Result<(), Box<EvalAltResult>> {
|
||||
}
|
||||
}
|
||||
|
||||
engine.register_type::<TestStruct>();
|
||||
|
||||
engine.register_get_set("x", TestStruct::get_x, TestStruct::set_x);
|
||||
engine.register_fn("update", TestStruct::update);
|
||||
engine.register_fn("merge", TestStruct::merge);
|
||||
engine.register_fn("new_ts", TestStruct::new);
|
||||
engine.
|
||||
register_raw_fn(
|
||||
engine
|
||||
.register_type::<TestStruct>()
|
||||
.register_get_set("x", TestStruct::get_x, TestStruct::set_x)
|
||||
.register_fn("update", TestStruct::update)
|
||||
.register_fn("merge", TestStruct::merge)
|
||||
.register_fn("new_ts", TestStruct::new)
|
||||
.register_raw_fn(
|
||||
"mutate_with_cb",
|
||||
&[
|
||||
TypeId::of::<TestStruct>(),
|
||||
@ -339,6 +348,7 @@ fn test_shared() -> Result<(), Box<EvalAltResult>> {
|
||||
)?,
|
||||
2151
|
||||
);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user