Add only_i32
and only_i64
features.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use rhai::{Engine, EvalAltResult, Scope};
|
||||
use rhai::{Engine, EvalAltResult, Scope, INT};
|
||||
|
||||
#[test]
|
||||
fn test_var_scope() -> Result<(), EvalAltResult> {
|
||||
@@ -6,14 +6,14 @@ fn test_var_scope() -> Result<(), EvalAltResult> {
|
||||
let mut scope = Scope::new();
|
||||
|
||||
engine.eval_with_scope::<()>(&mut scope, false, "let x = 4 + 5")?;
|
||||
assert_eq!(engine.eval_with_scope::<i64>(&mut scope, false, "x")?, 9);
|
||||
assert_eq!(engine.eval_with_scope::<INT>(&mut scope, false, "x")?, 9);
|
||||
engine.eval_with_scope::<()>(&mut scope, false, "x = x + 1; x = x + 2;")?;
|
||||
assert_eq!(engine.eval_with_scope::<i64>(&mut scope, false, "x")?, 12);
|
||||
assert_eq!(engine.eval_with_scope::<INT>(&mut scope, false, "x")?, 12);
|
||||
assert_eq!(
|
||||
engine.eval_with_scope::<()>(&mut scope, false, "{let x = 3}")?,
|
||||
()
|
||||
);
|
||||
assert_eq!(engine.eval_with_scope::<i64>(&mut scope, false, "x")?, 12);
|
||||
assert_eq!(engine.eval_with_scope::<INT>(&mut scope, false, "x")?, 12);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -26,10 +26,10 @@ fn test_scope_eval() -> Result<(), EvalAltResult> {
|
||||
let mut scope = Scope::new();
|
||||
|
||||
// Then push some initialized variables into the state
|
||||
// NOTE: Remember the default numbers used by Rhai are i64 and f64.
|
||||
// NOTE: Remember the default numbers used by Rhai are INT and f64.
|
||||
// Better stick to them or it gets hard to work with other variables in the script.
|
||||
scope.push("y", 42_i64);
|
||||
scope.push("z", 999_i64);
|
||||
scope.push("y", 42 as INT);
|
||||
scope.push("z", 999 as INT);
|
||||
|
||||
// First invocation
|
||||
engine
|
||||
@@ -37,12 +37,12 @@ fn test_scope_eval() -> Result<(), EvalAltResult> {
|
||||
.expect("y and z not found?");
|
||||
|
||||
// Second invocation using the same state
|
||||
let result = engine.eval_with_scope::<i64>(&mut scope, false, "x")?;
|
||||
let result = engine.eval_with_scope::<INT>(&mut scope, false, "x")?;
|
||||
|
||||
println!("result: {}", result); // should print 966
|
||||
|
||||
// Variable y is changed in the script
|
||||
assert_eq!(scope.get_value::<i64>("y").unwrap(), 1);
|
||||
assert_eq!(scope.get_value::<INT>("y").unwrap(), 1);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Reference in New Issue
Block a user