Make all public API's return Box<EvalAltResult> to reduce footprint.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
use rhai::{Array, Engine, EvalAltResult, RegisterFn, INT};
|
||||
|
||||
#[test]
|
||||
fn test_arrays() -> Result<(), EvalAltResult> {
|
||||
fn test_arrays() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
assert_eq!(engine.eval::<INT>("let x = [1, 2, 3]; x[1]")?, 2);
|
||||
@@ -58,7 +58,7 @@ fn test_arrays() -> Result<(), EvalAltResult> {
|
||||
|
||||
#[test]
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
fn test_array_with_structs() -> Result<(), EvalAltResult> {
|
||||
fn test_array_with_structs() -> Result<(), Box<EvalAltResult>> {
|
||||
#[derive(Clone)]
|
||||
struct TestStruct {
|
||||
x: INT,
|
||||
|
@@ -1,7 +1,7 @@
|
||||
use rhai::{Engine, EvalAltResult, INT};
|
||||
|
||||
#[test]
|
||||
fn test_binary_ops() -> Result<(), EvalAltResult> {
|
||||
fn test_binary_ops() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
assert_eq!(engine.eval::<INT>("10 % 4")?, 2);
|
||||
|
@@ -1,14 +1,14 @@
|
||||
use rhai::{Engine, EvalAltResult, INT};
|
||||
|
||||
#[test]
|
||||
fn test_left_shift() -> Result<(), EvalAltResult> {
|
||||
fn test_left_shift() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
assert_eq!(engine.eval::<INT>("4 << 2")?, 16);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_right_shift() -> Result<(), EvalAltResult> {
|
||||
fn test_right_shift() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
assert_eq!(engine.eval::<INT>("9 >> 1")?, 4);
|
||||
Ok(())
|
||||
|
@@ -1,7 +1,7 @@
|
||||
use rhai::{Engine, EvalAltResult};
|
||||
|
||||
#[test]
|
||||
fn test_bool_op1() -> Result<(), EvalAltResult> {
|
||||
fn test_bool_op1() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
assert_eq!(engine.eval::<bool>("true && (false || true)")?, true);
|
||||
@@ -11,7 +11,7 @@ fn test_bool_op1() -> Result<(), EvalAltResult> {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_bool_op2() -> Result<(), EvalAltResult> {
|
||||
fn test_bool_op2() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
assert_eq!(engine.eval::<bool>("false && (false || true)")?, false);
|
||||
@@ -21,7 +21,7 @@ fn test_bool_op2() -> Result<(), EvalAltResult> {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_bool_op3() -> Result<(), EvalAltResult> {
|
||||
fn test_bool_op3() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
assert!(engine.eval::<bool>("true && (false || 123)").is_err());
|
||||
@@ -33,7 +33,7 @@ fn test_bool_op3() -> Result<(), EvalAltResult> {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_bool_op_short_circuit() -> Result<(), EvalAltResult> {
|
||||
fn test_bool_op_short_circuit() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
assert_eq!(
|
||||
|
@@ -2,7 +2,7 @@
|
||||
use rhai::{Engine, EvalAltResult, Func, ParseErrorType, Scope, INT};
|
||||
|
||||
#[test]
|
||||
fn test_fn() -> Result<(), EvalAltResult> {
|
||||
fn test_fn() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
// Expect duplicated parameters error
|
||||
@@ -19,7 +19,7 @@ fn test_fn() -> Result<(), EvalAltResult> {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_call_fn() -> Result<(), EvalAltResult> {
|
||||
fn test_call_fn() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
let mut scope = Scope::new();
|
||||
|
||||
@@ -61,7 +61,7 @@ fn test_call_fn() -> Result<(), EvalAltResult> {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_anonymous_fn() -> Result<(), EvalAltResult> {
|
||||
fn test_anonymous_fn() -> Result<(), Box<EvalAltResult>> {
|
||||
let calc_func = Func::<(INT, INT, INT), INT>::create_from_script(
|
||||
Engine::new(),
|
||||
"fn calc(x, y, z) { (x + y) * z }",
|
||||
|
@@ -1,7 +1,7 @@
|
||||
use rhai::{Engine, EvalAltResult};
|
||||
|
||||
#[test]
|
||||
fn test_chars() -> Result<(), EvalAltResult> {
|
||||
fn test_chars() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
assert_eq!(engine.eval::<char>("'y'")?, 'y');
|
||||
|
@@ -1,7 +1,7 @@
|
||||
use rhai::{Engine, EvalAltResult, INT};
|
||||
|
||||
#[test]
|
||||
fn test_or_equals() -> Result<(), EvalAltResult> {
|
||||
fn test_or_equals() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
assert_eq!(engine.eval::<INT>("let x = 16; x |= 74; x")?, 90);
|
||||
@@ -12,7 +12,7 @@ fn test_or_equals() -> Result<(), EvalAltResult> {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_and_equals() -> Result<(), EvalAltResult> {
|
||||
fn test_and_equals() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
assert_eq!(engine.eval::<INT>("let x = 16; x &= 31; x")?, 16);
|
||||
@@ -24,42 +24,42 @@ fn test_and_equals() -> Result<(), EvalAltResult> {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_xor_equals() -> Result<(), EvalAltResult> {
|
||||
fn test_xor_equals() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
assert_eq!(engine.eval::<INT>("let x = 90; x ^= 12; x")?, 86);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_multiply_equals() -> Result<(), EvalAltResult> {
|
||||
fn test_multiply_equals() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
assert_eq!(engine.eval::<INT>("let x = 2; x *= 3; x")?, 6);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_divide_equals() -> Result<(), EvalAltResult> {
|
||||
fn test_divide_equals() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
assert_eq!(engine.eval::<INT>("let x = 6; x /= 2; x")?, 3);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_left_shift_equals() -> Result<(), EvalAltResult> {
|
||||
fn test_left_shift_equals() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
assert_eq!(engine.eval::<INT>("let x = 9; x >>=1; x")?, 4);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_right_shift_equals() -> Result<(), EvalAltResult> {
|
||||
fn test_right_shift_equals() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
assert_eq!(engine.eval::<INT>("let x = 4; x<<= 2; x")?, 16);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_modulo_equals() -> Result<(), EvalAltResult> {
|
||||
fn test_modulo_equals() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
assert_eq!(engine.eval::<INT>("let x = 10; x %= 4; x")?, 2);
|
||||
Ok(())
|
||||
|
@@ -1,21 +1,21 @@
|
||||
use rhai::{Engine, EvalAltResult, INT};
|
||||
|
||||
#[test]
|
||||
fn test_constant() -> Result<(), EvalAltResult> {
|
||||
fn test_constant() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
assert_eq!(engine.eval::<INT>("const x = 123; x")?, 123);
|
||||
|
||||
assert!(
|
||||
matches!(engine.eval::<INT>("const x = 123; x = 42;").expect_err("expects error"),
|
||||
EvalAltResult::ErrorAssignmentToConstant(var, _) if var == "x")
|
||||
);
|
||||
assert!(matches!(
|
||||
*engine.eval::<INT>("const x = 123; x = 42;").expect_err("expects error"),
|
||||
EvalAltResult::ErrorAssignmentToConstant(var, _) if var == "x"
|
||||
));
|
||||
|
||||
#[cfg(not(feature = "no_index"))]
|
||||
assert!(
|
||||
matches!(engine.eval::<INT>("const x = [1, 2, 3, 4, 5]; x[2] = 42;").expect_err("expects error"),
|
||||
EvalAltResult::ErrorAssignmentToConstant(var, _) if var == "x")
|
||||
);
|
||||
assert!(matches!(
|
||||
*engine.eval::<INT>("const x = [1, 2, 3, 4, 5]; x[2] = 42;").expect_err("expects error"),
|
||||
EvalAltResult::ErrorAssignmentToConstant(var, _) if var == "x"
|
||||
));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@@ -1,14 +1,15 @@
|
||||
use rhai::{Engine, EvalAltResult, INT};
|
||||
|
||||
#[test]
|
||||
fn test_decrement() -> Result<(), EvalAltResult> {
|
||||
fn test_decrement() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
assert_eq!(engine.eval::<INT>("let x = 10; x -= 7; x")?, 3);
|
||||
|
||||
assert!(matches!(engine
|
||||
.eval::<String>(r#"let s = "test"; s -= "ing"; s"#)
|
||||
.expect_err("expects error"), EvalAltResult::ErrorFunctionNotFound(err, _) if err == "- (string, string)"));
|
||||
assert!(matches!(
|
||||
*engine.eval::<String>(r#"let s = "test"; s -= "ing"; s"#).expect_err("expects error"),
|
||||
EvalAltResult::ErrorFunctionNotFound(err, _) if err == "- (string, string)"
|
||||
));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
use rhai::{Engine, EvalAltResult, Scope, INT};
|
||||
|
||||
#[test]
|
||||
fn test_eval() -> Result<(), EvalAltResult> {
|
||||
fn test_eval() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
assert_eq!(
|
||||
@@ -18,7 +18,7 @@ fn test_eval() -> Result<(), EvalAltResult> {
|
||||
|
||||
#[test]
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
fn test_eval_function() -> Result<(), EvalAltResult> {
|
||||
fn test_eval_function() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
let mut scope = Scope::new();
|
||||
|
||||
@@ -61,7 +61,7 @@ fn test_eval_function() -> Result<(), EvalAltResult> {
|
||||
|
||||
#[test]
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
fn test_eval_override() -> Result<(), EvalAltResult> {
|
||||
fn test_eval_override() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
assert_eq!(
|
||||
|
@@ -1,7 +1,7 @@
|
||||
use rhai::{Engine, EvalAltResult, Scope, INT};
|
||||
|
||||
#[test]
|
||||
fn test_expressions() -> Result<(), EvalAltResult> {
|
||||
fn test_expressions() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
let mut scope = Scope::new();
|
||||
|
||||
@@ -28,7 +28,7 @@ fn test_expressions() -> Result<(), EvalAltResult> {
|
||||
/// This example taken from https://github.com/jonathandturner/rhai/issues/115
|
||||
#[test]
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
fn test_expressions_eval() -> Result<(), EvalAltResult> {
|
||||
fn test_expressions_eval() -> Result<(), Box<EvalAltResult>> {
|
||||
#[derive(Debug, Clone)]
|
||||
struct AGENT {
|
||||
pub gender: String,
|
||||
|
@@ -4,7 +4,7 @@ use rhai::{Engine, EvalAltResult, RegisterFn, FLOAT};
|
||||
const EPSILON: FLOAT = 0.000_000_000_1;
|
||||
|
||||
#[test]
|
||||
fn test_float() -> Result<(), EvalAltResult> {
|
||||
fn test_float() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
assert_eq!(
|
||||
@@ -22,7 +22,7 @@ fn test_float() -> Result<(), EvalAltResult> {
|
||||
|
||||
#[test]
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
fn struct_with_float() -> Result<(), EvalAltResult> {
|
||||
fn struct_with_float() -> Result<(), Box<EvalAltResult>> {
|
||||
#[derive(Clone)]
|
||||
struct TestStruct {
|
||||
x: f64,
|
||||
|
@@ -2,7 +2,7 @@ use rhai::{Engine, EvalAltResult, INT};
|
||||
|
||||
#[cfg(not(feature = "no_index"))]
|
||||
#[test]
|
||||
fn test_for_array() -> Result<(), EvalAltResult> {
|
||||
fn test_for_array() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
let script = r"
|
||||
@@ -32,7 +32,7 @@ fn test_for_array() -> Result<(), EvalAltResult> {
|
||||
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
#[test]
|
||||
fn test_for_object() -> Result<(), EvalAltResult> {
|
||||
fn test_for_object() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
let script = r#"
|
||||
|
@@ -3,7 +3,7 @@
|
||||
use rhai::{Engine, EvalAltResult, RegisterFn, INT};
|
||||
|
||||
#[test]
|
||||
fn test_get_set() -> Result<(), EvalAltResult> {
|
||||
fn test_get_set() -> Result<(), Box<EvalAltResult>> {
|
||||
#[derive(Clone)]
|
||||
struct TestStruct {
|
||||
x: INT,
|
||||
@@ -36,7 +36,7 @@ fn test_get_set() -> Result<(), EvalAltResult> {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_big_get_set() -> Result<(), EvalAltResult> {
|
||||
fn test_big_get_set() -> Result<(), Box<EvalAltResult>> {
|
||||
#[derive(Clone)]
|
||||
struct TestChild {
|
||||
x: INT,
|
||||
|
@@ -1,7 +1,7 @@
|
||||
use rhai::{Engine, EvalAltResult, INT};
|
||||
|
||||
#[test]
|
||||
fn test_if() -> Result<(), EvalAltResult> {
|
||||
fn test_if() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
assert_eq!(engine.eval::<INT>("if true { 55 }")?, 55);
|
||||
@@ -29,7 +29,7 @@ fn test_if() -> Result<(), EvalAltResult> {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_if_expr() -> Result<(), EvalAltResult> {
|
||||
fn test_if_expr() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
assert_eq!(
|
||||
|
@@ -1,7 +1,7 @@
|
||||
use rhai::{Engine, EvalAltResult, INT};
|
||||
|
||||
#[test]
|
||||
fn test_increment() -> Result<(), EvalAltResult> {
|
||||
fn test_increment() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
assert_eq!(engine.eval::<INT>("let x = 1; x += 2; x")?, 3);
|
||||
|
@@ -3,7 +3,7 @@
|
||||
use rhai::{Engine, EvalAltResult, INT};
|
||||
|
||||
#[test]
|
||||
fn test_internal_fn() -> Result<(), EvalAltResult> {
|
||||
fn test_internal_fn() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
assert_eq!(
|
||||
@@ -16,7 +16,7 @@ fn test_internal_fn() -> Result<(), EvalAltResult> {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_big_internal_fn() -> Result<(), EvalAltResult> {
|
||||
fn test_big_internal_fn() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
assert_eq!(
|
||||
@@ -35,7 +35,7 @@ fn test_big_internal_fn() -> Result<(), EvalAltResult> {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_internal_fn_overloading() -> Result<(), EvalAltResult> {
|
||||
fn test_internal_fn_overloading() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
assert_eq!(
|
||||
|
@@ -1,7 +1,7 @@
|
||||
use rhai::{Engine, EvalAltResult, INT};
|
||||
|
||||
#[test]
|
||||
fn test_loop() -> Result<(), EvalAltResult> {
|
||||
fn test_loop() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
assert_eq!(
|
||||
|
@@ -3,7 +3,7 @@
|
||||
use rhai::{Engine, EvalAltResult, Map, Scope, INT};
|
||||
|
||||
#[test]
|
||||
fn test_map_indexing() -> Result<(), EvalAltResult> {
|
||||
fn test_map_indexing() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
#[cfg(not(feature = "no_index"))]
|
||||
@@ -81,7 +81,7 @@ fn test_map_indexing() -> Result<(), EvalAltResult> {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_map_assign() -> Result<(), EvalAltResult> {
|
||||
fn test_map_assign() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
let x = engine.eval::<Map>(r#"let x = #{a: 1, b: true, "c$": "hello"}; x"#)?;
|
||||
@@ -112,7 +112,7 @@ fn test_map_assign() -> Result<(), EvalAltResult> {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_map_return() -> Result<(), EvalAltResult> {
|
||||
fn test_map_return() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
let x = engine.eval::<Map>(r#"#{a: 1, b: true, "c$": "hello"}"#)?;
|
||||
@@ -143,7 +143,7 @@ fn test_map_return() -> Result<(), EvalAltResult> {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_map_for() -> Result<(), EvalAltResult> {
|
||||
fn test_map_for() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
assert_eq!(
|
||||
@@ -170,7 +170,7 @@ fn test_map_for() -> Result<(), EvalAltResult> {
|
||||
#[test]
|
||||
/// Because a Rhai object map literal is almost the same as JSON,
|
||||
/// it is possible to convert from JSON into a Rhai object map.
|
||||
fn test_map_json() -> Result<(), EvalAltResult> {
|
||||
fn test_map_json() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
let json = r#"{"a":1, "b":true, "c":42, "$d e f!":"hello", "z":null}"#;
|
||||
|
@@ -1,7 +1,7 @@
|
||||
use rhai::{Engine, EvalAltResult, INT};
|
||||
|
||||
#[test]
|
||||
fn test_math() -> Result<(), EvalAltResult> {
|
||||
fn test_math() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
assert_eq!(engine.eval::<INT>("1 + 2")?, 3);
|
||||
@@ -25,37 +25,37 @@ fn test_math() -> Result<(), EvalAltResult> {
|
||||
#[cfg(not(feature = "only_i32"))]
|
||||
{
|
||||
assert!(matches!(
|
||||
engine
|
||||
*engine
|
||||
.eval::<INT>("abs(-9223372036854775808)")
|
||||
.expect_err("expects negation overflow"),
|
||||
EvalAltResult::ErrorArithmetic(_, _)
|
||||
));
|
||||
assert!(matches!(
|
||||
engine
|
||||
*engine
|
||||
.eval::<INT>("9223372036854775807 + 1")
|
||||
.expect_err("expects overflow"),
|
||||
EvalAltResult::ErrorArithmetic(_, _)
|
||||
));
|
||||
assert!(matches!(
|
||||
engine
|
||||
*engine
|
||||
.eval::<INT>("-9223372036854775808 - 1")
|
||||
.expect_err("expects underflow"),
|
||||
EvalAltResult::ErrorArithmetic(_, _)
|
||||
));
|
||||
assert!(matches!(
|
||||
engine
|
||||
*engine
|
||||
.eval::<INT>("9223372036854775807 * 9223372036854775807")
|
||||
.expect_err("expects overflow"),
|
||||
EvalAltResult::ErrorArithmetic(_, _)
|
||||
));
|
||||
assert!(matches!(
|
||||
engine
|
||||
*engine
|
||||
.eval::<INT>("9223372036854775807 / 0")
|
||||
.expect_err("expects division by zero"),
|
||||
EvalAltResult::ErrorArithmetic(_, _)
|
||||
));
|
||||
assert!(matches!(
|
||||
engine
|
||||
*engine
|
||||
.eval::<INT>("9223372036854775807 % 0")
|
||||
.expect_err("expects division by zero"),
|
||||
EvalAltResult::ErrorArithmetic(_, _)
|
||||
@@ -65,31 +65,31 @@ fn test_math() -> Result<(), EvalAltResult> {
|
||||
#[cfg(feature = "only_i32")]
|
||||
{
|
||||
assert!(matches!(
|
||||
engine
|
||||
*engine
|
||||
.eval::<INT>("2147483647 + 1")
|
||||
.expect_err("expects overflow"),
|
||||
EvalAltResult::ErrorArithmetic(_, _)
|
||||
));
|
||||
assert!(matches!(
|
||||
engine
|
||||
*engine
|
||||
.eval::<INT>("-2147483648 - 1")
|
||||
.expect_err("expects underflow"),
|
||||
EvalAltResult::ErrorArithmetic(_, _)
|
||||
));
|
||||
assert!(matches!(
|
||||
engine
|
||||
*engine
|
||||
.eval::<INT>("2147483647 * 2147483647")
|
||||
.expect_err("expects overflow"),
|
||||
EvalAltResult::ErrorArithmetic(_, _)
|
||||
));
|
||||
assert!(matches!(
|
||||
engine
|
||||
*engine
|
||||
.eval::<INT>("2147483647 / 0")
|
||||
.expect_err("expects division by zero"),
|
||||
EvalAltResult::ErrorArithmetic(_, _)
|
||||
));
|
||||
assert!(matches!(
|
||||
engine
|
||||
*engine
|
||||
.eval::<INT>("2147483647 % 0")
|
||||
.expect_err("expects division by zero"),
|
||||
EvalAltResult::ErrorArithmetic(_, _)
|
||||
|
@@ -3,7 +3,7 @@
|
||||
use rhai::{Engine, EvalAltResult, RegisterFn, INT};
|
||||
|
||||
#[test]
|
||||
fn test_method_call() -> Result<(), EvalAltResult> {
|
||||
fn test_method_call() -> Result<(), Box<EvalAltResult>> {
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
struct TestStruct {
|
||||
x: INT,
|
||||
|
@@ -4,10 +4,10 @@ use rhai::{Engine, EvalAltResult, RegisterFn, INT};
|
||||
fn test_mismatched_op() {
|
||||
let engine = Engine::new();
|
||||
|
||||
assert!(
|
||||
matches!(engine.eval::<INT>(r#""hello, " + "world!""#).expect_err("expects error"),
|
||||
EvalAltResult::ErrorMismatchOutputType(err, _) if err == "string")
|
||||
);
|
||||
assert!(matches!(
|
||||
*engine.eval::<INT>(r#""hello, " + "world!""#).expect_err("expects error"),
|
||||
EvalAltResult::ErrorMismatchOutputType(err, _) if err == "string"
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -33,12 +33,14 @@ fn test_mismatched_op_custom_type() {
|
||||
.expect_err("expects error");
|
||||
|
||||
#[cfg(feature = "only_i32")]
|
||||
assert!(
|
||||
matches!(r, EvalAltResult::ErrorFunctionNotFound(err, _) if err == "+ (i32, TestStruct)")
|
||||
);
|
||||
assert!(matches!(
|
||||
*r,
|
||||
EvalAltResult::ErrorFunctionNotFound(err, _) if err == "+ (i32, TestStruct)"
|
||||
));
|
||||
|
||||
#[cfg(not(feature = "only_i32"))]
|
||||
assert!(
|
||||
matches!(r, EvalAltResult::ErrorFunctionNotFound(err, _) if err == "+ (i64, TestStruct)")
|
||||
);
|
||||
assert!(matches!(
|
||||
*r,
|
||||
EvalAltResult::ErrorFunctionNotFound(err, _) if err == "+ (i64, TestStruct)"
|
||||
));
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
use rhai::{Engine, EvalAltResult};
|
||||
|
||||
#[test]
|
||||
fn test_not() -> Result<(), EvalAltResult> {
|
||||
fn test_not() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
assert_eq!(
|
||||
|
@@ -1,7 +1,7 @@
|
||||
use rhai::{Engine, EvalAltResult, INT};
|
||||
|
||||
#[test]
|
||||
fn test_number_literal() -> Result<(), EvalAltResult> {
|
||||
fn test_number_literal() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
assert_eq!(engine.eval::<INT>("65")?, 65);
|
||||
@@ -10,7 +10,7 @@ fn test_number_literal() -> Result<(), EvalAltResult> {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_hex_literal() -> Result<(), EvalAltResult> {
|
||||
fn test_hex_literal() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
assert_eq!(engine.eval::<INT>("let x = 0xf; x")?, 15);
|
||||
@@ -20,7 +20,7 @@ fn test_hex_literal() -> Result<(), EvalAltResult> {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_octal_literal() -> Result<(), EvalAltResult> {
|
||||
fn test_octal_literal() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
assert_eq!(engine.eval::<INT>("let x = 0o77; x")?, 63);
|
||||
@@ -30,7 +30,7 @@ fn test_octal_literal() -> Result<(), EvalAltResult> {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_binary_literal() -> Result<(), EvalAltResult> {
|
||||
fn test_binary_literal() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
assert_eq!(engine.eval::<INT>("let x = 0b1111; x")?, 15);
|
||||
|
@@ -1,7 +1,7 @@
|
||||
use rhai::{Engine, EvalAltResult, INT};
|
||||
|
||||
#[test]
|
||||
fn test_ops() -> Result<(), EvalAltResult> {
|
||||
fn test_ops() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
assert_eq!(engine.eval::<INT>("60 + 5")?, 65);
|
||||
@@ -11,7 +11,7 @@ fn test_ops() -> Result<(), EvalAltResult> {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_op_precedence() -> Result<(), EvalAltResult> {
|
||||
fn test_op_precedence() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
assert_eq!(
|
||||
|
@@ -3,8 +3,8 @@
|
||||
use rhai::{Engine, EvalAltResult, OptimizationLevel, INT};
|
||||
|
||||
#[test]
|
||||
fn test_optimizer() -> Result<(), EvalAltResult> {
|
||||
fn run_test(engine: &mut Engine) -> Result<(), EvalAltResult> {
|
||||
fn test_optimizer() -> Result<(), Box<EvalAltResult>> {
|
||||
fn run_test(engine: &mut Engine) -> Result<(), Box<EvalAltResult>> {
|
||||
assert_eq!(engine.eval::<INT>(r"if true { 42 } else { 123 }")?, 42);
|
||||
assert_eq!(
|
||||
engine.eval::<INT>(r"if 1 == 1 || 2 > 3 { 42 } else { 123 }")?,
|
||||
|
@@ -7,7 +7,7 @@ use rhai::FLOAT;
|
||||
const EPSILON: FLOAT = 0.000_000_000_1;
|
||||
|
||||
#[test]
|
||||
fn test_power_of() -> Result<(), EvalAltResult> {
|
||||
fn test_power_of() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
assert_eq!(engine.eval::<INT>("2 ~ 3")?, 8);
|
||||
@@ -28,7 +28,7 @@ fn test_power_of() -> Result<(), EvalAltResult> {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_power_of_equals() -> Result<(), EvalAltResult> {
|
||||
fn test_power_of_equals() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
assert_eq!(engine.eval::<INT>("let x = 2; x ~= 3; x")?, 8);
|
||||
|
@@ -40,7 +40,7 @@ impl CommandWrapper {
|
||||
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
#[test]
|
||||
fn test_side_effects_command() -> Result<(), EvalAltResult> {
|
||||
fn test_side_effects_command() -> Result<(), Box<EvalAltResult>> {
|
||||
let mut engine = Engine::new();
|
||||
let mut scope = Scope::new();
|
||||
|
||||
@@ -80,7 +80,7 @@ fn test_side_effects_command() -> Result<(), EvalAltResult> {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_side_effects_print() -> Result<(), EvalAltResult> {
|
||||
fn test_side_effects_print() -> Result<(), Box<EvalAltResult>> {
|
||||
use std::sync::Arc;
|
||||
use std::sync::RwLock;
|
||||
|
||||
|
@@ -2,7 +2,7 @@
|
||||
use rhai::{Engine, EvalAltResult};
|
||||
|
||||
#[test]
|
||||
fn test_stack_overflow() -> Result<(), EvalAltResult> {
|
||||
fn test_stack_overflow() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
assert_eq!(
|
||||
@@ -22,8 +22,10 @@ fn test_stack_overflow() -> Result<(), EvalAltResult> {
|
||||
",
|
||||
) {
|
||||
Ok(_) => panic!("should be stack overflow"),
|
||||
Err(EvalAltResult::ErrorStackOverflow(_)) => (),
|
||||
Err(_) => panic!("should be stack overflow"),
|
||||
Err(err) => match *err {
|
||||
EvalAltResult::ErrorStackOverflow(_) => (),
|
||||
_ => panic!("should be stack overflow"),
|
||||
},
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@@ -1,7 +1,7 @@
|
||||
use rhai::{Engine, EvalAltResult, INT};
|
||||
|
||||
#[test]
|
||||
fn test_string() -> Result<(), EvalAltResult> {
|
||||
fn test_string() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
assert_eq!(
|
||||
@@ -37,7 +37,7 @@ fn test_string() -> Result<(), EvalAltResult> {
|
||||
#[cfg(not(feature = "no_stdlib"))]
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
#[test]
|
||||
fn test_string_substring() -> Result<(), EvalAltResult> {
|
||||
fn test_string_substring() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
assert_eq!(
|
||||
|
@@ -5,10 +5,12 @@ fn test_throw() {
|
||||
let engine = Engine::new();
|
||||
|
||||
assert!(matches!(
|
||||
engine.eval::<()>(r#"if true { throw "hello" }"#).expect_err("expects error"),
|
||||
EvalAltResult::ErrorRuntime(s, _) if s == "hello"));
|
||||
*engine.eval::<()>(r#"if true { throw "hello" }"#).expect_err("expects error"),
|
||||
EvalAltResult::ErrorRuntime(s, _) if s == "hello"
|
||||
));
|
||||
|
||||
assert!(matches!(
|
||||
engine.eval::<()>(r#"throw"#).expect_err("expects error"),
|
||||
EvalAltResult::ErrorRuntime(s, _) if s == ""));
|
||||
*engine.eval::<()>(r#"throw"#).expect_err("expects error"),
|
||||
EvalAltResult::ErrorRuntime(s, _) if s == ""
|
||||
));
|
||||
}
|
||||
|
@@ -7,7 +7,7 @@ use rhai::{Engine, EvalAltResult, INT};
|
||||
use rhai::FLOAT;
|
||||
|
||||
#[test]
|
||||
fn test_timestamp() -> Result<(), EvalAltResult> {
|
||||
fn test_timestamp() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
assert_eq!(engine.eval::<String>("type_of(timestamp())")?, "timestamp");
|
||||
|
@@ -1,7 +1,7 @@
|
||||
use rhai::{Engine, EvalAltResult, RegisterFn, INT};
|
||||
|
||||
#[test]
|
||||
fn test_type_of() -> Result<(), EvalAltResult> {
|
||||
fn test_type_of() -> Result<(), Box<EvalAltResult>> {
|
||||
#[derive(Clone)]
|
||||
struct TestStruct {
|
||||
x: INT,
|
||||
|
@@ -3,7 +3,7 @@ use rhai::{Engine, EvalAltResult, INT};
|
||||
#[test]
|
||||
// TODO also add test case for unary after compound
|
||||
// Hah, turns out unary + has a good use after all!
|
||||
fn test_unary_after_binary() -> Result<(), EvalAltResult> {
|
||||
fn test_unary_after_binary() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
assert_eq!(engine.eval::<INT>("10 % +4")?, 2);
|
||||
|
@@ -1,7 +1,7 @@
|
||||
use rhai::{Engine, EvalAltResult, INT};
|
||||
|
||||
#[test]
|
||||
fn test_unary_minus() -> Result<(), EvalAltResult> {
|
||||
fn test_unary_minus() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
assert_eq!(engine.eval::<INT>("let x = -5; x")?, -5);
|
||||
|
@@ -1,21 +1,21 @@
|
||||
use rhai::{Engine, EvalAltResult};
|
||||
|
||||
#[test]
|
||||
fn test_unit() -> Result<(), EvalAltResult> {
|
||||
fn test_unit() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
engine.eval::<()>("let x = (); x")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_unit_eq() -> Result<(), EvalAltResult> {
|
||||
fn test_unit_eq() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
assert_eq!(engine.eval::<bool>("let x = (); let y = (); x == y")?, true);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_unit_with_spaces() -> Result<(), EvalAltResult> {
|
||||
fn test_unit_with_spaces() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
engine.eval::<()>("let x = ( ); x")?;
|
||||
Ok(())
|
||||
|
@@ -1,7 +1,7 @@
|
||||
use rhai::{Engine, EvalAltResult, Scope, INT};
|
||||
|
||||
#[test]
|
||||
fn test_var_scope() -> Result<(), EvalAltResult> {
|
||||
fn test_var_scope() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
let mut scope = Scope::new();
|
||||
|
||||
@@ -20,7 +20,7 @@ fn test_var_scope() -> Result<(), EvalAltResult> {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_scope_eval() -> Result<(), EvalAltResult> {
|
||||
fn test_scope_eval() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
// First create the state
|
||||
|
@@ -1,7 +1,7 @@
|
||||
use rhai::{Engine, EvalAltResult, INT};
|
||||
|
||||
#[test]
|
||||
fn test_while() -> Result<(), EvalAltResult> {
|
||||
fn test_while() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
assert_eq!(
|
||||
|
Reference in New Issue
Block a user