Simplify using ..

This commit is contained in:
Stephen Chung
2022-02-08 09:02:15 +08:00
parent 187a20fd8b
commit f8cee0fe4e
54 changed files with 1184 additions and 1190 deletions

View File

@@ -330,7 +330,7 @@ fn test_call_fn_events() -> Result<(), Box<EvalAltResult>> {
"update" => engine
.call_fn(scope, ast, "update", (event_data,))
.or_else(|err| match *err {
EvalAltResult::ErrorFunctionNotFound(fn_name, _)
EvalAltResult::ErrorFunctionNotFound(fn_name, ..)
if fn_name.starts_with("update") =>
{
// Default implementation of 'update' event handler

View File

@@ -251,7 +251,7 @@ fn test_closures_data_race() -> Result<(), Box<EvalAltResult>> {
"
)
.expect_err("should error"),
EvalAltResult::ErrorDataRace(_, _)
EvalAltResult::ErrorDataRace(..)
));
Ok(())

View File

@@ -10,13 +10,13 @@ fn test_constant() -> Result<(), Box<EvalAltResult>> {
*engine
.eval::<INT>("const x = 123; x = 42;")
.expect_err("expects error"),
EvalAltResult::ErrorParsing(ParseErrorType::AssignmentToConstant(x), _) if x == "x"
EvalAltResult::ErrorParsing(ParseErrorType::AssignmentToConstant(x), ..) if x == "x"
));
#[cfg(not(feature = "no_index"))]
assert!(matches!(
*engine.run("const x = [1, 2, 3, 4, 5]; x[2] = 42;").expect_err("expects error"),
EvalAltResult::ErrorAssignmentToConstant(x, _) if x == "x"
EvalAltResult::ErrorAssignmentToConstant(x, ..) if x == "x"
));
Ok(())
@@ -31,7 +31,7 @@ fn test_constant_scope() -> Result<(), Box<EvalAltResult>> {
assert!(matches!(
*engine.run_with_scope(&mut scope, "x = 1").expect_err("expects error"),
EvalAltResult::ErrorAssignmentToConstant(x, _) if x == "x"
EvalAltResult::ErrorAssignmentToConstant(x, ..) if x == "x"
));
Ok(())
@@ -87,7 +87,7 @@ fn test_constant_mut() -> Result<(), Box<EvalAltResult>> {
"
)
.expect_err("should error"),
EvalAltResult::ErrorAssignmentToConstant(_, _)
EvalAltResult::ErrorAssignmentToConstant(..)
));
let mut scope = Scope::new();
@@ -120,7 +120,7 @@ fn test_constant_mut() -> Result<(), Box<EvalAltResult>> {
*engine
.run_with_scope(&mut scope, "MY_NUMBER.value = 42;")
.expect_err("should error"),
EvalAltResult::ErrorAssignmentToConstant(_, _)
EvalAltResult::ErrorAssignmentToConstant(..)
));
Ok(())

View File

@@ -81,7 +81,7 @@ fn test_custom_syntax() -> Result<(), Box<EvalAltResult>> {
*engine
.run("let foo = (exec [x<<15] -> { x += 2 } while x < 42) * 10;")
.expect_err("should error"),
EvalAltResult::ErrorRuntime(_, _)
EvalAltResult::ErrorRuntime(..)
));
assert_eq!(

View File

@@ -38,7 +38,7 @@ fn test_max_string_size() -> Result<(), Box<EvalAltResult>> {
"#
)
.expect_err("should error"),
EvalAltResult::ErrorDataTooLarge(_, _)
EvalAltResult::ErrorDataTooLarge(..)
));
#[cfg(not(feature = "no_object"))]
@@ -52,7 +52,7 @@ fn test_max_string_size() -> Result<(), Box<EvalAltResult>> {
"#
)
.expect_err("should error"),
EvalAltResult::ErrorDataTooLarge(_, _)
EvalAltResult::ErrorDataTooLarge(..)
));
engine.set_max_string_size(0);
@@ -98,7 +98,7 @@ fn test_max_array_size() -> Result<(), Box<EvalAltResult>> {
"
)
.expect_err("should error"),
EvalAltResult::ErrorDataTooLarge(_, _)
EvalAltResult::ErrorDataTooLarge(..)
));
#[cfg(not(feature = "no_closure"))]
@@ -131,7 +131,7 @@ fn test_max_array_size() -> Result<(), Box<EvalAltResult>> {
"
)
.expect_err("should error"),
EvalAltResult::ErrorDataTooLarge(_, _)
EvalAltResult::ErrorDataTooLarge(..)
));
assert!(matches!(
@@ -143,7 +143,7 @@ fn test_max_array_size() -> Result<(), Box<EvalAltResult>> {
"
)
.expect_err("should error"),
EvalAltResult::ErrorDataTooLarge(_, _)
EvalAltResult::ErrorDataTooLarge(..)
));
#[cfg(not(feature = "no_object"))]
@@ -169,7 +169,7 @@ fn test_max_array_size() -> Result<(), Box<EvalAltResult>> {
"
)
.expect_err("should error"),
EvalAltResult::ErrorDataTooLarge(_, _)
EvalAltResult::ErrorDataTooLarge(..)
));
assert_eq!(
@@ -191,7 +191,7 @@ fn test_max_array_size() -> Result<(), Box<EvalAltResult>> {
"
)
.expect_err("should error"),
EvalAltResult::ErrorDataTooLarge(_, _)
EvalAltResult::ErrorDataTooLarge(..)
));
#[cfg(not(feature = "no_object"))]
@@ -204,7 +204,7 @@ fn test_max_array_size() -> Result<(), Box<EvalAltResult>> {
"
)
.expect_err("should error"),
EvalAltResult::ErrorDataTooLarge(_, _)
EvalAltResult::ErrorDataTooLarge(..)
));
assert!(matches!(
@@ -218,7 +218,7 @@ fn test_max_array_size() -> Result<(), Box<EvalAltResult>> {
"
)
.expect_err("should error"),
EvalAltResult::ErrorDataTooLarge(_, _)
EvalAltResult::ErrorDataTooLarge(..)
));
engine.set_max_array_size(0);
@@ -282,7 +282,7 @@ fn test_max_map_size() -> Result<(), Box<EvalAltResult>> {
"
)
.expect_err("should error"),
EvalAltResult::ErrorDataTooLarge(_, _)
EvalAltResult::ErrorDataTooLarge(..)
));
assert!(matches!(
@@ -295,7 +295,7 @@ fn test_max_map_size() -> Result<(), Box<EvalAltResult>> {
"
)
.expect_err("should error"),
EvalAltResult::ErrorDataTooLarge(_, _)
EvalAltResult::ErrorDataTooLarge(..)
));
assert!(matches!(
@@ -307,7 +307,7 @@ fn test_max_map_size() -> Result<(), Box<EvalAltResult>> {
"
)
.expect_err("should error"),
EvalAltResult::ErrorDataTooLarge(_, _)
EvalAltResult::ErrorDataTooLarge(..)
));
#[cfg(not(feature = "no_index"))]
@@ -320,7 +320,7 @@ fn test_max_map_size() -> Result<(), Box<EvalAltResult>> {
"
)
.expect_err("should error"),
EvalAltResult::ErrorDataTooLarge(_, _)
EvalAltResult::ErrorDataTooLarge(..)
));
engine.set_max_map_size(0);

View File

@@ -171,7 +171,7 @@ fn test_eval_disabled() -> Result<(), Box<EvalAltResult>> {
.compile(r#"eval("40 + 2")"#)
.expect_err("should error")
.0,
ParseErrorType::BadInput(LexError::ImproperSymbol(err, _)) if err == "eval"
ParseErrorType::BadInput(LexError::ImproperSymbol(err, ..)) if err == "eval"
));
Ok(())

View File

@@ -73,7 +73,7 @@ fn test_fn_ptr() -> Result<(), Box<EvalAltResult>> {
"#
)
.expect_err("should error"),
EvalAltResult::ErrorInFunctionCall(fn_name, _, err, _)
EvalAltResult::ErrorInFunctionCall(fn_name, _, err, ..)
if fn_name == "foo" && matches!(*err, EvalAltResult::ErrorUnboundThis(_))
));

View File

@@ -92,8 +92,8 @@ fn test_functions_global_module() -> Result<(), Box<EvalAltResult>> {
foo()
}
").expect_err("should error"),
EvalAltResult::ErrorInFunctionCall(_, _, err, _)
if matches!(&*err, EvalAltResult::ErrorVariableNotFound(v, _) if v == "global::ANSWER")
EvalAltResult::ErrorInFunctionCall(.., err, _)
if matches!(&*err, EvalAltResult::ErrorVariableNotFound(v, ..) if v == "global::ANSWER")
));
engine.register_result_fn(
@@ -110,8 +110,8 @@ fn test_functions_global_module() -> Result<(), Box<EvalAltResult>> {
global::LOCAL_VALUE
});
").expect_err("should error"),
EvalAltResult::ErrorInFunctionCall(_, _, err, _)
if matches!(&*err, EvalAltResult::ErrorVariableNotFound(v, _) if v == "global::LOCAL_VALUE")
EvalAltResult::ErrorInFunctionCall(.., err, _)
if matches!(&*err, EvalAltResult::ErrorVariableNotFound(v, ..) if v == "global::LOCAL_VALUE")
));
#[cfg(not(feature = "no_closure"))]

View File

@@ -170,7 +170,7 @@ fn test_function_pointers() -> Result<(), Box<EvalAltResult>> {
#[cfg(not(feature = "no_object"))]
assert!(matches!(
*engine.eval::<INT>(r#"let f = Fn("abc"); f.call(0)"#).expect_err("should error"),
EvalAltResult::ErrorFunctionNotFound(f, _) if f.starts_with("abc (")
EvalAltResult::ErrorFunctionNotFound(f, ..) if f.starts_with("abc (")
));
#[cfg(not(feature = "no_object"))]

View File

@@ -53,7 +53,7 @@ b`: 1}; y["a\nb"]
*engine
.eval::<INT>("let y = #{`a${1}`: 1}; y.a1")
.expect_err("should error"),
EvalAltResult::ErrorParsing(ParseErrorType::PropertyExpected, _)
EvalAltResult::ErrorParsing(ParseErrorType::PropertyExpected, ..)
));
assert!(engine.eval::<bool>(r#"let y = #{a: 1, b: 2, c: 3}; "c" in y"#)?);
@@ -205,7 +205,7 @@ fn test_map_json() -> Result<(), Box<EvalAltResult>> {
assert!(matches!(
*engine.parse_json(" 123", true).expect_err("should error"),
EvalAltResult::ErrorParsing(ParseErrorType::MissingToken(token, _), _)
EvalAltResult::ErrorParsing(ParseErrorType::MissingToken(token, ..), ..)
if token == "{"
));

View File

@@ -37,37 +37,37 @@ fn test_math() -> Result<(), Box<EvalAltResult>> {
*engine
.eval::<INT>("abs(-9223372036854775808)")
.expect_err("expects negation overflow"),
EvalAltResult::ErrorArithmetic(_, _)
EvalAltResult::ErrorArithmetic(..)
));
assert!(matches!(
*engine
.eval::<INT>("9223372036854775807 + 1")
.expect_err("expects overflow"),
EvalAltResult::ErrorArithmetic(_, _)
EvalAltResult::ErrorArithmetic(..)
));
assert!(matches!(
*engine
.eval::<INT>("-9223372036854775808 - 1")
.expect_err("expects underflow"),
EvalAltResult::ErrorArithmetic(_, _)
EvalAltResult::ErrorArithmetic(..)
));
assert!(matches!(
*engine
.eval::<INT>("9223372036854775807 * 9223372036854775807")
.expect_err("expects overflow"),
EvalAltResult::ErrorArithmetic(_, _)
EvalAltResult::ErrorArithmetic(..)
));
assert!(matches!(
*engine
.eval::<INT>("9223372036854775807 / 0")
.expect_err("expects division by zero"),
EvalAltResult::ErrorArithmetic(_, _)
EvalAltResult::ErrorArithmetic(..)
));
assert!(matches!(
*engine
.eval::<INT>("9223372036854775807 % 0")
.expect_err("expects division by zero"),
EvalAltResult::ErrorArithmetic(_, _)
EvalAltResult::ErrorArithmetic(..)
));
}
@@ -77,31 +77,31 @@ fn test_math() -> Result<(), Box<EvalAltResult>> {
*engine
.eval::<INT>("2147483647 + 1")
.expect_err("expects overflow"),
EvalAltResult::ErrorArithmetic(_, _)
EvalAltResult::ErrorArithmetic(..)
));
assert!(matches!(
*engine
.eval::<INT>("-2147483648 - 1")
.expect_err("expects underflow"),
EvalAltResult::ErrorArithmetic(_, _)
EvalAltResult::ErrorArithmetic(..)
));
assert!(matches!(
*engine
.eval::<INT>("2147483647 * 2147483647")
.expect_err("expects overflow"),
EvalAltResult::ErrorArithmetic(_, _)
EvalAltResult::ErrorArithmetic(..)
));
assert!(matches!(
*engine
.eval::<INT>("2147483647 / 0")
.expect_err("expects division by zero"),
EvalAltResult::ErrorArithmetic(_, _)
EvalAltResult::ErrorArithmetic(..)
));
assert!(matches!(
*engine
.eval::<INT>("2147483647 % 0")
.expect_err("expects division by zero"),
EvalAltResult::ErrorArithmetic(_, _)
EvalAltResult::ErrorArithmetic(..)
));
}
}

View File

@@ -6,7 +6,7 @@ fn test_mismatched_op() {
assert!(matches!(
*engine.eval::<INT>(r#""hello, " + "world!""#).expect_err("expects error"),
EvalAltResult::ErrorMismatchOutputType(need, actual, _) if need == std::any::type_name::<INT>() && actual == "string"
EvalAltResult::ErrorMismatchOutputType(need, actual, ..) if need == std::any::type_name::<INT>() && actual == "string"
));
}
@@ -35,18 +35,18 @@ fn test_mismatched_op_custom_type() -> Result<(), Box<EvalAltResult>> {
let y = new_ts();
x == y
").expect_err("should error"),
EvalAltResult::ErrorFunctionNotFound(f, _) if f == "== (TestStruct, TestStruct)"));
EvalAltResult::ErrorFunctionNotFound(f, ..) if f == "== (TestStruct, TestStruct)"));
assert!(!engine.eval::<bool>("new_ts() == 42")?);
assert!(matches!(
*engine.eval::<INT>("60 + new_ts()").expect_err("should error"),
EvalAltResult::ErrorFunctionNotFound(f, _) if f == format!("+ ({}, TestStruct)", std::any::type_name::<INT>())
EvalAltResult::ErrorFunctionNotFound(f, ..) if f == format!("+ ({}, TestStruct)", std::any::type_name::<INT>())
));
assert!(matches!(
*engine.eval::<TestStruct>("42").expect_err("should error"),
EvalAltResult::ErrorMismatchOutputType(need, actual, _)
EvalAltResult::ErrorMismatchOutputType(need, actual, ..)
if need == "TestStruct" && actual == std::any::type_name::<INT>()
));

View File

@@ -237,7 +237,7 @@ fn test_module_resolver() -> Result<(), Box<EvalAltResult>> {
"#
)
.expect_err("should error"),
EvalAltResult::ErrorInFunctionCall(fn_name, _, _, _) if fn_name == "foo"
EvalAltResult::ErrorInFunctionCall(fn_name, _, ..) if fn_name == "foo"
));
engine.set_max_modules(1000);
@@ -369,7 +369,7 @@ fn test_module_from_ast() -> Result<(), Box<EvalAltResult>> {
*engine
.run(r#"import "testing" as ttt; ttt::hidden()"#)
.expect_err("should error"),
EvalAltResult::ErrorFunctionNotFound(fn_name, _) if fn_name == "ttt::hidden ()"
EvalAltResult::ErrorFunctionNotFound(fn_name, ..) if fn_name == "ttt::hidden ()"
));
Ok(())
@@ -381,13 +381,13 @@ fn test_module_export() -> Result<(), Box<EvalAltResult>> {
assert!(matches!(
engine.compile("let x = 10; { export x; }").expect_err("should error"),
ParseError(x, _) if *x == ParseErrorType::WrongExport
ParseError(x, ..) if *x == ParseErrorType::WrongExport
));
#[cfg(not(feature = "no_function"))]
assert!(matches!(
engine.compile("fn abc(x) { export x; }").expect_err("should error"),
ParseError(x, _) if *x == ParseErrorType::WrongExport
ParseError(x, ..) if *x == ParseErrorType::WrongExport
));
Ok(())

View File

@@ -138,7 +138,7 @@ fn test_max_operations_eval() -> Result<(), Box<EvalAltResult>> {
"#
)
.expect_err("should error"),
EvalAltResult::ErrorInFunctionCall(_, _, err, _) if matches!(*err, EvalAltResult::ErrorTooManyOperations(_))
EvalAltResult::ErrorInFunctionCall(.., err, _) if matches!(*err, EvalAltResult::ErrorTooManyOperations(_))
));
Ok(())
@@ -163,7 +163,7 @@ fn test_max_operations_progress() -> Result<(), Box<EvalAltResult>> {
*engine
.run("for x in 0..500 {}")
.expect_err("should error"),
EvalAltResult::ErrorTerminated(x, _) if x.as_int()? == 42
EvalAltResult::ErrorTerminated(x, ..) if x.as_int()? == 42
));
Ok(())

View File

@@ -27,12 +27,12 @@ fn test_ops_other_number_types() -> Result<(), Box<EvalAltResult>> {
assert!(matches!(
*engine.eval_with_scope::<bool>(&mut scope, "x == 42").expect_err("should error"),
EvalAltResult::ErrorFunctionNotFound(f, _) if f.starts_with("== (u16,")
EvalAltResult::ErrorFunctionNotFound(f, ..) if f.starts_with("== (u16,")
));
#[cfg(not(feature = "no_float"))]
assert!(matches!(
*engine.eval_with_scope::<bool>(&mut scope, "x == 42.0").expect_err("should error"),
EvalAltResult::ErrorFunctionNotFound(f, _) if f.starts_with("== (u16,")
EvalAltResult::ErrorFunctionNotFound(f, ..) if f.starts_with("== (u16,")
));
assert!(!engine.eval_with_scope::<bool>(&mut scope, r#"x == "hello""#)?);

View File

@@ -93,7 +93,7 @@ fn test_plugins_package() -> Result<(), Box<EvalAltResult>> {
assert!(
matches!(*engine.run("const A = [1, 2, 3]; A.test(42);").expect_err("should error"),
EvalAltResult::ErrorAssignmentToConstant(x, _) if x == "array")
EvalAltResult::ErrorAssignmentToConstant(x, ..) if x == "array")
)
}

View File

@@ -117,7 +117,7 @@ fn test_string_mut() -> Result<(), Box<EvalAltResult>> {
assert_eq!(engine.eval::<INT>(r#"bar("hello")"#)?, 5);
assert!(
matches!(*engine.eval::<INT>(r#"baz("hello")"#).expect_err("should error"),
EvalAltResult::ErrorFunctionNotFound(f, _) if f == "baz (&str | ImmutableString | String)"
EvalAltResult::ErrorFunctionNotFound(f, ..) if f == "baz (&str | ImmutableString | String)"
)
);

View File

@@ -6,12 +6,12 @@ fn test_throw() {
assert!(matches!(
*engine.run("if true { throw 42 }").expect_err("expects error"),
EvalAltResult::ErrorRuntime(s, _) if s.as_int().unwrap() == 42
EvalAltResult::ErrorRuntime(s, ..) if s.as_int().unwrap() == 42
));
assert!(matches!(
*engine.run(r#"throw"#).expect_err("expects error"),
EvalAltResult::ErrorRuntime(s, _) if s.is::<()>()
EvalAltResult::ErrorRuntime(s, ..) if s.is::<()>()
));
}
@@ -96,7 +96,7 @@ fn test_try_catch() -> Result<(), Box<EvalAltResult>> {
*engine
.run("try { 42/0; } catch { throw; }")
.expect_err("expects error"),
EvalAltResult::ErrorArithmetic(_, _)
EvalAltResult::ErrorArithmetic(..)
));
Ok(())

View File

@@ -115,7 +115,7 @@ fn test_var_resolver() -> Result<(), Box<EvalAltResult>> {
assert_eq!(engine.eval_with_scope::<INT>(&mut scope, "chameleon")?, 1);
assert!(
matches!(*engine.eval_with_scope::<INT>(&mut scope, "DO_NOT_USE").expect_err("should error"),
EvalAltResult::ErrorVariableNotFound(n, _) if n == "DO_NOT_USE")
EvalAltResult::ErrorVariableNotFound(n, ..) if n == "DO_NOT_USE")
);
Ok(())