From 4c4a209609141ac1705201896ce1316214400234 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Mon, 30 Nov 2020 21:16:59 +0800 Subject: [PATCH] Fix tests. --- codegen/src/test/module.rs | 12 ++++++------ src/packages/string_basic.rs | 6 +++--- tests/print.rs | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/codegen/src/test/module.rs b/codegen/src/test/module.rs index c586f0a1..3b3c0d2d 100644 --- a/codegen/src/test/module.rs +++ b/codegen/src/test/module.rs @@ -1672,7 +1672,7 @@ mod generate_tests { } #[allow(unused_mut)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { - m.set_fn("set$squared", FnNamespace::Internal, FnAccess::Public, Some(&["x: &mut u64", "y: u64", "()"]), + m.set_fn("set$squared", FnNamespace::Global, FnAccess::Public, Some(&["x: &mut u64", "y: u64", "()"]), &[core::any::TypeId::of::(), core::any::TypeId::of::()], int_foo_token().into()); if flatten {} else {} @@ -1752,7 +1752,7 @@ mod generate_tests { m.set_fn("set_sq", FnNamespace::Internal, FnAccess::Public, Some(&["x: &mut u64", "y: u64", "()"]), &[core::any::TypeId::of::(), core::any::TypeId::of::()], int_foo_token().into()); - m.set_fn("set$squared", FnNamespace::Internal, FnAccess::Public, Some(&["x: &mut u64", "y: u64", "()"]), + m.set_fn("set$squared", FnNamespace::Global, FnAccess::Public, Some(&["x: &mut u64", "y: u64", "()"]), &[core::any::TypeId::of::(), core::any::TypeId::of::()], int_foo_token().into()); if flatten {} else {} @@ -1829,7 +1829,7 @@ mod generate_tests { } #[allow(unused_mut)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { - m.set_fn("index$get$", FnNamespace::Internal, FnAccess::Public, + m.set_fn("index$get$", FnNamespace::Global, FnAccess::Public, Some(&["x: &mut MyCollection", "i: u64", "FLOAT"]), &[core::any::TypeId::of::(), core::any::TypeId::of::()], @@ -1914,7 +1914,7 @@ mod generate_tests { &[core::any::TypeId::of::(), core::any::TypeId::of::()], get_by_index_token().into()); - m.set_fn("index$get$", FnNamespace::Internal, FnAccess::Public, + m.set_fn("index$get$", FnNamespace::Global, FnAccess::Public, Some(&["x: &mut MyCollection", "i: u64", "FLOAT"]), &[core::any::TypeId::of::(), core::any::TypeId::of::()], @@ -1994,7 +1994,7 @@ mod generate_tests { } #[allow(unused_mut)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { - m.set_fn("index$set$", FnNamespace::Internal, FnAccess::Public, + m.set_fn("index$set$", FnNamespace::Global, FnAccess::Public, Some(&["x: &mut MyCollection", "i: u64", "item: FLOAT", "()"]), &[core::any::TypeId::of::(), core::any::TypeId::of::(), @@ -2083,7 +2083,7 @@ mod generate_tests { core::any::TypeId::of::(), core::any::TypeId::of::()], set_by_index_token().into()); - m.set_fn("index$set$", FnNamespace::Internal, FnAccess::Public, + m.set_fn("index$set$", FnNamespace::Global, FnAccess::Public, Some(&["x: &mut MyCollection", "i: u64", "item: FLOAT", "()"]), &[core::any::TypeId::of::(), core::any::TypeId::of::(), diff --git a/src/packages/string_basic.rs b/src/packages/string_basic.rs index 86db1c53..44ab4e7e 100644 --- a/src/packages/string_basic.rs +++ b/src/packages/string_basic.rs @@ -109,7 +109,7 @@ gen_functions!(debug_float => to_debug(f32, f64)); // Register print and debug -#[cfg(not(feature = "no_index"))] +#[cfg(any(not(feature = "no_index"), not(feature = "no_object")))] #[inline(always)] fn print_with_func(fn_name: &str, ctx: &NativeCallContext, value: &mut Dynamic) -> ImmutableString { match ctx.call_fn_dynamic_raw(fn_name, true, false, &mut [value], None) { @@ -144,7 +144,7 @@ mod print_debug_functions { #[rhai_fn(name = "print", name = "to_string", name = "to_debug", name = "debug")] pub fn format_array(ctx: NativeCallContext, arr: &mut Array) -> ImmutableString { - let mut result = String::with_capacity(16); + let mut result = crate::stdlib::string::String::with_capacity(16); result.push_str("["); let len = arr.len(); @@ -166,7 +166,7 @@ mod print_debug_functions { #[rhai_fn(name = "print", name = "to_string", name = "to_debug", name = "debug")] pub fn format_map(ctx: NativeCallContext, map: &mut Map) -> ImmutableString { - let mut result = String::with_capacity(16); + let mut result = crate::stdlib::string::String::with_capacity(16); result.push_str("#{"); let len = map.len(); diff --git a/tests/print.rs b/tests/print.rs index fb50af3e..7967670a 100644 --- a/tests/print.rs +++ b/tests/print.rs @@ -42,6 +42,7 @@ impl std::fmt::Display for MyStruct { } } +#[cfg(not(feature = "no_object"))] #[test] fn test_print_custom_type() -> Result<(), Box> { let mut engine = Engine::new(); @@ -65,7 +66,6 @@ fn test_print_custom_type() -> Result<(), Box> { r#"[123, true, (), "world", hello: 42]"# ); - #[cfg(not(feature = "no_object"))] assert!(engine .eval::( r#"