Add Dynamic::from(&str)

This commit is contained in:
Stephen Chung
2020-10-06 21:25:05 +08:00
parent 1de44c7ecd
commit 8809d25d3c
3 changed files with 23 additions and 1 deletions

View File

@@ -1,4 +1,4 @@
use rhai::{Engine, EvalAltResult, ImmutableString, RegisterFn, INT};
use rhai::{Dynamic, Engine, EvalAltResult, ImmutableString, RegisterFn, Scope, INT};
#[test]
fn test_string() -> Result<(), Box<EvalAltResult>> {
@@ -49,6 +49,21 @@ fn test_string() -> Result<(), Box<EvalAltResult>> {
Ok(())
}
#[test]
fn test_string_dynamic() -> Result<(), Box<EvalAltResult>> {
let engine = Engine::new();
let mut scope = Scope::new();
scope.push("x", Dynamic::from("foo"));
scope.push("y", String::from("foo"));
scope.push("z", "foo");
assert!(engine.eval_with_scope::<bool>(&mut scope, r#"x == "foo""#)?);
assert!(engine.eval_with_scope::<bool>(&mut scope, r#"y == "foo""#)?);
assert!(engine.eval_with_scope::<bool>(&mut scope, r#"z == "foo""#)?);
Ok(())
}
#[cfg(not(feature = "no_object"))]
#[test]
fn test_string_substring() -> Result<(), Box<EvalAltResult>> {