Avoid hard-coding variable type for shared.

This commit is contained in:
Stephen Chung
2020-08-01 22:28:13 +08:00
parent af2f8acb5d
commit cc53b21731
4 changed files with 71 additions and 86 deletions

View File

@@ -11,11 +11,23 @@ fn test_shared() -> Result<(), Box<EvalAltResult>> {
assert_eq!(engine.eval::<bool>("shared(true)")?, true);
assert_eq!(
engine.eval::<String>("let x = shared(true); type_of(x)")?,
"bool"
);
assert_eq!(
engine.eval::<String>("let x = shared(true); x = (); type_of(x)")?,
"()"
);
#[cfg(not(feature = "no_float"))]
assert_eq!(engine.eval::<f64>("shared(4.2)")?, 4.2);
assert_eq!(engine.eval::<String>(r#"shared("test")"#)?, "test");
assert_eq!(engine.eval::<String>(r#"shared("test")"#)?, "test");
assert_eq!(engine.eval::<char>("shared('x')")?, 'x');
assert!(engine.eval::<bool>("is_shared(shared(42))")?);