Merge branch 'master' into plugins_dev

This commit is contained in:
Stephen Chung
2020-08-20 16:54:00 +08:00
7 changed files with 105 additions and 20 deletions

View File

@@ -1,6 +1,6 @@
#![cfg(not(feature = "no_object"))]
use rhai::{Engine, EvalAltResult, Map, Scope, INT};
use rhai::{Engine, EvalAltResult, Map, ParseErrorType, Scope, INT};
#[test]
fn test_map_indexing() -> Result<(), Box<EvalAltResult>> {
@@ -182,6 +182,14 @@ fn test_map_json() -> Result<(), Box<EvalAltResult>> {
);
}
engine.parse_json(&format!("#{}", json), true)?;
assert!(matches!(
*engine.parse_json(" 123", true).expect_err("should error"),
EvalAltResult::ErrorParsing(ParseErrorType::MissingToken(token, _), pos)
if token == "{" && pos.position() == Some(4)
));
Ok(())
}

View File

@@ -94,6 +94,31 @@ fn test_module_resolver() -> Result<(), Box<EvalAltResult>> {
42
);
assert_eq!(
engine.eval::<INT>(
r#"
import "hello" as h1;
import "hello" as h2;
let x = 42;
h1::sum(x, -10, 3, 7)
"#
)?,
42
);
assert_eq!(
engine.eval::<INT>(
r#"
import "hello" as h1;
import "hello" as h2;
let x = 42;
h1::sum(x, 0, 0, 0);
x
"#
)?,
42
);
assert_eq!(
engine.eval::<INT>(
r#"