Use unwrap_err.

This commit is contained in:
Stephen Chung 2023-04-10 23:23:59 +08:00
parent 20c535ecd3
commit 8662ffec62
24 changed files with 100 additions and 153 deletions

View File

@ -210,34 +210,25 @@ fn test_array_index_types() -> Result<(), Box<EvalAltResult>> {
engine.compile("[1, 2, 3][0]['x']")?;
assert!(matches!(
engine
.compile("[1, 2, 3]['x']")
.expect_err("should error")
.err_type(),
engine.compile("[1, 2, 3]['x']").unwrap_err().err_type(),
ParseErrorType::MalformedIndexExpr(..)
));
#[cfg(not(feature = "no_float"))]
assert!(matches!(
engine
.compile("[1, 2, 3][123.456]")
.expect_err("should error")
.err_type(),
engine.compile("[1, 2, 3][123.456]").unwrap_err().err_type(),
ParseErrorType::MalformedIndexExpr(..)
));
assert!(matches!(
engine
.compile("[1, 2, 3][()]")
.expect_err("should error")
.err_type(),
engine.compile("[1, 2, 3][()]").unwrap_err().err_type(),
ParseErrorType::MalformedIndexExpr(..)
));
assert!(matches!(
engine
.compile(r#"[1, 2, 3]["hello"]"#)
.expect_err("should error")
.unwrap_err()
.err_type(),
ParseErrorType::MalformedIndexExpr(..)
));
@ -245,7 +236,7 @@ fn test_array_index_types() -> Result<(), Box<EvalAltResult>> {
assert!(matches!(
engine
.compile("[1, 2, 3][true && false]")
.expect_err("should error")
.unwrap_err()
.err_type(),
ParseErrorType::MalformedIndexExpr(..)
));

View File

@ -21,71 +21,44 @@ fn test_assignments_bad_lhs() -> Result<(), Box<EvalAltResult>> {
let engine = Engine::new();
assert_eq!(
*engine
.compile("(x+y) = 42;")
.expect_err("should error")
.err_type(),
*engine.compile("(x+y) = 42;").unwrap_err().err_type(),
ParseErrorType::AssignmentToInvalidLHS(String::new())
);
assert_eq!(
*engine
.compile("foo(x) = 42;")
.expect_err("should error")
.err_type(),
*engine.compile("foo(x) = 42;").unwrap_err().err_type(),
ParseErrorType::AssignmentToInvalidLHS(String::new())
);
assert_eq!(
*engine
.compile("true = 42;")
.expect_err("should error")
.err_type(),
*engine.compile("true = 42;").unwrap_err().err_type(),
ParseErrorType::AssignmentToConstant(String::new())
);
assert_eq!(
*engine
.compile("123 = 42;")
.expect_err("should error")
.err_type(),
*engine.compile("123 = 42;").unwrap_err().err_type(),
ParseErrorType::AssignmentToConstant(String::new())
);
#[cfg(not(feature = "no_object"))]
{
assert_eq!(
*engine
.compile("x.foo() = 42;")
.expect_err("should error")
.err_type(),
*engine.compile("x.foo() = 42;").unwrap_err().err_type(),
ParseErrorType::AssignmentToInvalidLHS(String::new())
);
assert_eq!(
*engine
.compile("x.foo().x.y = 42;")
.expect_err("should error")
.err_type(),
*engine.compile("x.foo().x.y = 42;").unwrap_err().err_type(),
ParseErrorType::AssignmentToInvalidLHS(String::new())
);
assert_eq!(
*engine
.compile("x.y.z.foo() = 42;")
.expect_err("should error")
.err_type(),
*engine.compile("x.y.z.foo() = 42;").unwrap_err().err_type(),
ParseErrorType::AssignmentToInvalidLHS(String::new())
);
#[cfg(not(feature = "no_index"))]
assert_eq!(
*engine
.compile("x.foo()[0] = 42;")
.expect_err("should error")
.err_type(),
*engine.compile("x.foo()[0] = 42;").unwrap_err().err_type(),
ParseErrorType::AssignmentToInvalidLHS(String::new())
);
#[cfg(not(feature = "no_index"))]
assert_eq!(
*engine
.compile("x[y].z.foo() = 42;")
.expect_err("should error")
.err_type(),
*engine.compile("x[y].z.foo() = 42;").unwrap_err().err_type(),
ParseErrorType::AssignmentToInvalidLHS(String::new())
);
}

View File

@ -47,10 +47,7 @@ fn test_closures() -> Result<(), Box<EvalAltResult>> {
scope.push("x", 42 as INT);
assert!(matches!(
engine
.compile_expression("|x| {}")
.expect_err("should error")
.err_type(),
engine.compile_expression("|x| {}").unwrap_err().err_type(),
ParseErrorType::BadInput(..)
));
@ -292,7 +289,7 @@ fn test_closures_data_race() -> Result<(), Box<EvalAltResult>> {
a
"
)
.expect_err("should error"),
.unwrap_err(),
EvalAltResult::ErrorDataRace(..)
));

View File

@ -86,7 +86,7 @@ fn test_constant_mut() -> Result<(), Box<EvalAltResult>> {
MY_NUMBER.value = 42;
"
)
.expect_err("should error"),
.unwrap_err(),
EvalAltResult::ErrorNonPureMethodCallOnConstant(..)
));
@ -119,7 +119,7 @@ fn test_constant_mut() -> Result<(), Box<EvalAltResult>> {
assert!(matches!(
*engine
.run_with_scope(&mut scope, "MY_NUMBER.value = 42;")
.expect_err("should error"),
.unwrap_err(),
EvalAltResult::ErrorNonPureMethodCallOnConstant(..)
));

View File

@ -13,11 +13,11 @@ fn test_custom_syntax() -> Result<(), Box<EvalAltResult>> {
// Disable 'while' and make sure it still works with custom syntax
engine.disable_symbol("while");
assert!(matches!(
engine.compile("while false {}").expect_err("should error").err_type(),
engine.compile("while false {}").unwrap_err().err_type(),
ParseErrorType::Reserved(err) if err == "while"
));
assert!(matches!(
engine.compile("let while = 0").expect_err("should error").err_type(),
engine.compile("let while = 0").unwrap_err().err_type(),
ParseErrorType::Reserved(err) if err == "while"
));
@ -127,7 +127,7 @@ fn test_custom_syntax() -> Result<(), Box<EvalAltResult>> {
assert!(matches!(
*engine
.run("let foo = (exec [x<<15] -> { x += 2 } while x < 42) * 10;")
.expect_err("should error"),
.unwrap_err(),
EvalAltResult::ErrorRuntime(..)
));
@ -195,7 +195,7 @@ fn test_custom_syntax() -> Result<(), Box<EvalAltResult>> {
assert_eq!(
*engine
.register_custom_syntax(["!"], false, |_, _| Ok(Dynamic::UNIT))
.expect_err("should error")
.unwrap_err()
.err_type(),
ParseErrorType::BadInput(LexError::ImproperSymbol(
"!".to_string(),
@ -364,10 +364,7 @@ fn test_custom_syntax_raw() -> Result<(), Box<EvalAltResult>> {
);
assert_eq!(engine.eval::<INT>("(hello kitty) + foo")?, 1041);
assert_eq!(
*engine
.compile("hello hey")
.expect_err("should error")
.err_type(),
*engine.compile("hello hey").unwrap_err().err_type(),
ParseErrorType::BadInput(LexError::ImproperSymbol("hey".to_string(), String::new()))
);

View File

@ -15,7 +15,7 @@ fn test_max_string_size() -> Result<(), Box<EvalAltResult>> {
assert_eq!(
*engine
.compile(r#"let x = "hello, world!";"#)
.expect_err("should error")
.unwrap_err()
.err_type(),
ParseErrorType::LiteralTooLarge("Length of string".to_string(), 10)
);
@ -23,7 +23,7 @@ fn test_max_string_size() -> Result<(), Box<EvalAltResult>> {
assert_eq!(
*engine
.compile(r#"let x = "朝に紅顔、暮に白骨";"#)
.expect_err("should error")
.unwrap_err()
.err_type(),
ParseErrorType::LiteralTooLarge("Length of string".to_string(), 10)
);
@ -37,7 +37,7 @@ fn test_max_string_size() -> Result<(), Box<EvalAltResult>> {
x + y
"#
)
.expect_err("should error"),
.unwrap_err(),
EvalAltResult::ErrorDataTooLarge(..)
));
@ -51,7 +51,7 @@ fn test_max_string_size() -> Result<(), Box<EvalAltResult>> {
x
"#
)
.expect_err("should error"),
.unwrap_err(),
EvalAltResult::ErrorDataTooLarge(..)
));
@ -83,7 +83,7 @@ fn test_max_array_size() -> Result<(), Box<EvalAltResult>> {
assert_eq!(
*engine
.compile("let x = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15];")
.expect_err("should error")
.unwrap_err()
.err_type(),
ParseErrorType::LiteralTooLarge("Size of array literal".to_string(), 10)
);
@ -97,7 +97,7 @@ fn test_max_array_size() -> Result<(), Box<EvalAltResult>> {
x + y
"
)
.expect_err("should error"),
.unwrap_err(),
EvalAltResult::ErrorDataTooLarge(..)
));
@ -130,7 +130,7 @@ fn test_max_array_size() -> Result<(), Box<EvalAltResult>> {
}
"
)
.expect_err("should error"),
.unwrap_err(),
EvalAltResult::ErrorDataTooLarge(..)
));
@ -142,7 +142,7 @@ fn test_max_array_size() -> Result<(), Box<EvalAltResult>> {
loop { x[0] = x; }
"
)
.expect_err("should error"),
.unwrap_err(),
EvalAltResult::ErrorDataTooLarge(..)
));
@ -168,7 +168,7 @@ fn test_max_array_size() -> Result<(), Box<EvalAltResult>> {
x
"
)
.expect_err("should error"),
.unwrap_err(),
EvalAltResult::ErrorDataTooLarge(..)
));
@ -190,7 +190,7 @@ fn test_max_array_size() -> Result<(), Box<EvalAltResult>> {
[x, x, x, x]
"
)
.expect_err("should error"),
.unwrap_err(),
EvalAltResult::ErrorDataTooLarge(..)
));
@ -203,7 +203,7 @@ fn test_max_array_size() -> Result<(), Box<EvalAltResult>> {
[x, x, x, x]
"
)
.expect_err("should error"),
.unwrap_err(),
EvalAltResult::ErrorDataTooLarge(..)
));
@ -217,7 +217,7 @@ fn test_max_array_size() -> Result<(), Box<EvalAltResult>> {
[z, z, z]
"
)
.expect_err("should error"),
.unwrap_err(),
EvalAltResult::ErrorDataTooLarge(..)
));
@ -265,7 +265,7 @@ fn test_max_map_size() -> Result<(), Box<EvalAltResult>> {
.compile(
"let x = #{a:1,b:2,c:3,d:4,e:5,f:6,g:7,h:8,i:9,j:10,k:11,l:12,m:13,n:14,o:15};"
)
.expect_err("should error")
.unwrap_err()
.err_type(),
ParseErrorType::LiteralTooLarge(
"Number of properties in object map literal".to_string(),
@ -281,7 +281,7 @@ fn test_max_map_size() -> Result<(), Box<EvalAltResult>> {
loop { x.a = x; }
"
)
.expect_err("should error"),
.unwrap_err(),
EvalAltResult::ErrorDataTooLarge(..)
));
@ -294,7 +294,7 @@ fn test_max_map_size() -> Result<(), Box<EvalAltResult>> {
x + y
"
)
.expect_err("should error"),
.unwrap_err(),
EvalAltResult::ErrorDataTooLarge(..)
));
@ -306,7 +306,7 @@ fn test_max_map_size() -> Result<(), Box<EvalAltResult>> {
#{u:x, v:x, w:x, z:x}
"
)
.expect_err("should error"),
.unwrap_err(),
EvalAltResult::ErrorDataTooLarge(..)
));
@ -319,7 +319,7 @@ fn test_max_map_size() -> Result<(), Box<EvalAltResult>> {
#{u:x, v:x, w:x, z:x}
"
)
.expect_err("should error"),
.unwrap_err(),
EvalAltResult::ErrorDataTooLarge(..)
));

View File

@ -169,7 +169,7 @@ fn test_eval_disabled() -> Result<(), Box<EvalAltResult>> {
assert!(matches!(
engine
.compile(r#"eval("40 + 2")"#)
.expect_err("should error")
.unwrap_err()
.err_type(),
ParseErrorType::BadInput(LexError::ImproperSymbol(err, ..)) if err == "eval"
));

View File

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

View File

@ -93,7 +93,7 @@ fn test_functions_global_module() -> Result<(), Box<EvalAltResult>> {
const ANSWER = 42;
foo()
}
").expect_err("should error"),
").unwrap_err(),
EvalAltResult::ErrorInFunctionCall(.., err, _)
if matches!(&*err, EvalAltResult::ErrorVariableNotFound(v, ..) if v == "global::ANSWER")
));
@ -112,7 +112,7 @@ fn test_functions_global_module() -> Result<(), Box<EvalAltResult>> {
const LOCAL_VALUE = 42;
global::LOCAL_VALUE
});
").expect_err("should error"),
").unwrap_err(),
EvalAltResult::ErrorInFunctionCall(.., err, _)
if matches!(&*err, EvalAltResult::ErrorVariableNotFound(v, ..) if v == "global::LOCAL_VALUE")
));

View File

@ -109,7 +109,7 @@ fn test_internal_fn_overloading() -> Result<(), Box<EvalAltResult>> {
fn abc(x) { x - 42 }
"
)
.expect_err("should error")
.unwrap_err()
.err_type(),
ParseErrorType::FnDuplicatedDefinition("abc".to_string(), 1)
);
@ -125,7 +125,7 @@ fn test_internal_fn_params() -> Result<(), Box<EvalAltResult>> {
assert_eq!(
*engine
.compile("fn hello(x, x) { x }")
.expect_err("should error")
.unwrap_err()
.err_type(),
ParseErrorType::FnDuplicatedParam("hello".to_string(), "x".to_string())
);
@ -169,7 +169,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"),
*engine.eval::<INT>(r#"let f = Fn("abc"); f.call(0)"#).unwrap_err(),
EvalAltResult::ErrorFunctionNotFound(f, ..) if f.starts_with("abc (")
));
@ -247,7 +247,7 @@ fn test_internal_fn_bang() -> Result<(), Box<EvalAltResult>> {
y.foo!();
"
)
.expect_err("should error")
.unwrap_err()
.err_type(),
ParseErrorType::MalformedCapture(..)
));

View File

@ -27,10 +27,7 @@ fn test_loop() -> Result<(), Box<EvalAltResult>> {
);
assert_eq!(
*engine
.compile("let x = 0; break;")
.expect_err("should error")
.err_type(),
*engine.compile("let x = 0; break;").unwrap_err().err_type(),
ParseErrorType::LoopBreak
);
@ -38,7 +35,7 @@ fn test_loop() -> Result<(), Box<EvalAltResult>> {
assert_eq!(
*engine
.compile("loop { let f = || { break; } }")
.expect_err("should error")
.unwrap_err()
.err_type(),
ParseErrorType::LoopBreak
);
@ -46,7 +43,7 @@ fn test_loop() -> Result<(), Box<EvalAltResult>> {
assert_eq!(
*engine
.compile("let x = 0; if x > 0 { continue; }")
.expect_err("should error")
.unwrap_err()
.err_type(),
ParseErrorType::LoopBreak
);

View File

@ -52,7 +52,7 @@ b`: 1}; y["a\nb"]
assert!(matches!(
*engine
.eval::<INT>("let y = #{`a${1}`: 1}; y.a1")
.expect_err("should error"),
.unwrap_err(),
EvalAltResult::ErrorParsing(ParseErrorType::PropertyExpected, ..)
));
@ -116,7 +116,7 @@ fn test_map_prop() -> Result<(), Box<EvalAltResult>> {
engine.set_fail_on_invalid_map_property(true);
assert!(
matches!(*engine.eval::<()>("let x = #{a: 42}; x.b").expect_err("should error"),
matches!(*engine.eval::<()>("let x = #{a: 42}; x.b").unwrap_err(),
EvalAltResult::ErrorPropertyNotFound(prop, _) if prop == "b"
)
);
@ -134,7 +134,7 @@ fn test_map_index_types() -> Result<(), Box<EvalAltResult>> {
assert!(matches!(
engine
.compile("#{a:1, b:2, c:3}['x']")
.expect_err("should error")
.unwrap_err()
.err_type(),
ParseErrorType::MalformedIndexExpr(..)
));
@ -142,7 +142,7 @@ fn test_map_index_types() -> Result<(), Box<EvalAltResult>> {
assert!(matches!(
engine
.compile("#{a:1, b:2, c:3}[1]")
.expect_err("should error")
.unwrap_err()
.err_type(),
ParseErrorType::MalformedIndexExpr(..)
));
@ -151,7 +151,7 @@ fn test_map_index_types() -> Result<(), Box<EvalAltResult>> {
assert!(matches!(
engine
.compile("#{a:1, b:2, c:3}[123.456]")
.expect_err("should error")
.unwrap_err()
.err_type(),
ParseErrorType::MalformedIndexExpr(..)
));
@ -159,7 +159,7 @@ fn test_map_index_types() -> Result<(), Box<EvalAltResult>> {
assert!(matches!(
engine
.compile("#{a:1, b:2, c:3}[()]")
.expect_err("should error")
.unwrap_err()
.err_type(),
ParseErrorType::MalformedIndexExpr(..)
));
@ -167,7 +167,7 @@ fn test_map_index_types() -> Result<(), Box<EvalAltResult>> {
assert!(matches!(
engine
.compile("#{a:1, b:2, c:3}[true && false]")
.expect_err("should error")
.unwrap_err()
.err_type(),
ParseErrorType::MalformedIndexExpr(..)
));
@ -272,38 +272,32 @@ fn test_map_json() -> Result<(), Box<EvalAltResult>> {
engine.parse_json(json, true)?;
assert!(matches!(
*engine.parse_json("123", true).expect_err("should error"),
*engine.parse_json("123", true).unwrap_err(),
EvalAltResult::ErrorMismatchOutputType(..)
));
assert!(matches!(
*engine.parse_json("{a:42}", true).expect_err("should error"),
*engine.parse_json("{a:42}", true).unwrap_err(),
EvalAltResult::ErrorParsing(..)
));
assert!(matches!(
*engine
.parse_json("#{a:123}", true)
.expect_err("should error"),
*engine.parse_json("#{a:123}", true).unwrap_err(),
EvalAltResult::ErrorParsing(..)
));
assert!(matches!(
*engine.parse_json("{a:()}", true).expect_err("should error"),
*engine.parse_json("{a:()}", true).unwrap_err(),
EvalAltResult::ErrorParsing(..)
));
assert!(matches!(
*engine
.parse_json("#{a:123+456}", true)
.expect_err("should error"),
*engine.parse_json("#{a:123+456}", true).unwrap_err(),
EvalAltResult::ErrorParsing(..)
));
assert!(matches!(
*engine
.parse_json("{a:`hello${world}`}", true)
.expect_err("should error"),
*engine.parse_json("{a:`hello${world}`}", true).unwrap_err(),
EvalAltResult::ErrorParsing(..)
));

View File

@ -127,7 +127,7 @@ fn test_method_call_typed() -> Result<(), Box<EvalAltResult>> {
foo(1000);
"#
)
.expect_err("should error"),
.unwrap_err(),
EvalAltResult::ErrorFunctionNotFound(f, ..) if f.starts_with("foo")
));
@ -142,7 +142,7 @@ fn test_method_call_typed() -> Result<(), Box<EvalAltResult>> {
x.foo(1000);
"#
)
.expect_err("should error"),
.unwrap_err(),
EvalAltResult::ErrorFunctionNotFound(f, ..) if f.starts_with("foo")
));

View File

@ -36,21 +36,21 @@ fn test_mismatched_op_custom_type() -> Result<(), Box<EvalAltResult>> {
let x = new_ts();
let y = new_ts();
x == y
").expect_err("should error"),
").unwrap_err(),
EvalAltResult::ErrorFunctionNotFound(f, ..) if f == "== (TestStruct, TestStruct)"));
assert!(
matches!(*engine.eval::<bool>("new_ts() == 42").expect_err("should error"),
matches!(*engine.eval::<bool>("new_ts() == 42").unwrap_err(),
EvalAltResult::ErrorFunctionNotFound(f, ..) if f.starts_with("== (TestStruct, "))
);
assert!(matches!(
*engine.eval::<INT>("60 + new_ts()").expect_err("should error"),
*engine.eval::<INT>("60 + new_ts()").unwrap_err(),
EvalAltResult::ErrorFunctionNotFound(f, ..) if f == format!("+ ({}, TestStruct)", std::any::type_name::<INT>())
));
assert!(matches!(
*engine.eval::<TestStruct>("42").expect_err("should error"),
*engine.eval::<TestStruct>("42").unwrap_err(),
EvalAltResult::ErrorMismatchOutputType(need, actual, ..)
if need == "TestStruct" && actual == std::any::type_name::<INT>()
));

View File

@ -227,7 +227,7 @@ fn test_module_resolver() -> Result<(), Box<EvalAltResult>> {
sum
"#
)
.expect_err("should error"),
.unwrap_err(),
EvalAltResult::ErrorTooManyModules(..)
));
@ -250,7 +250,7 @@ fn test_module_resolver() -> Result<(), Box<EvalAltResult>> {
sum
"#
)
.expect_err("should error"),
.unwrap_err(),
EvalAltResult::ErrorInFunctionCall(fn_name, ..) if fn_name == "foo"
));
@ -403,7 +403,7 @@ fn test_module_from_ast() -> Result<(), Box<EvalAltResult>> {
assert!(matches!(
*engine
.run(r#"import "testing" as ttt; ttt::hidden()"#)
.expect_err("should error"),
.unwrap_err(),
EvalAltResult::ErrorFunctionNotFound(fn_name, ..) if fn_name == "ttt::hidden ()"
));
@ -415,13 +415,13 @@ fn test_module_export() -> Result<(), Box<EvalAltResult>> {
let engine = Engine::new();
assert!(matches!(
engine.compile("let x = 10; { export x; }").expect_err("should error"),
engine.compile("let x = 10; { export x; }").unwrap_err(),
ParseError(x, ..) if *x == ParseErrorType::WrongExport
));
#[cfg(not(feature = "no_function"))]
assert!(matches!(
engine.compile("fn abc(x) { export x; }").expect_err("should error"),
engine.compile("fn abc(x) { export x; }").unwrap_err(),
ParseError(x, ..) if *x == ParseErrorType::WrongExport
));

View File

@ -18,7 +18,7 @@ fn test_max_operations() -> Result<(), Box<EvalAltResult>> {
engine.run("let x = 0; while x < 20 { x += 1; }")?;
assert!(matches!(
*engine.run("for x in 0..500 {}").expect_err("should error"),
*engine.run("for x in 0..500 {}").unwrap_err(),
EvalAltResult::ErrorTooManyOperations(..)
));
@ -41,9 +41,7 @@ fn test_max_operations_literal() -> Result<(), Box<EvalAltResult>> {
#[cfg(not(feature = "no_index"))]
assert!(matches!(
*engine
.run("[1, 2, 3, 4, 5, 6, 7, 8, 9]")
.expect_err("should error"),
*engine.run("[1, 2, 3, 4, 5, 6, 7, 8, 9]").unwrap_err(),
EvalAltResult::ErrorTooManyOperations(..)
));
@ -54,7 +52,7 @@ fn test_max_operations_literal() -> Result<(), Box<EvalAltResult>> {
assert!(matches!(
*engine
.run("#{a:1, b:2, c:3, d:4, e:5, f:6, g:7, h:8, i:9}")
.expect_err("should error"),
.unwrap_err(),
EvalAltResult::ErrorTooManyOperations(..)
));
@ -110,7 +108,7 @@ fn test_max_operations_functions() -> Result<(), Box<EvalAltResult>> {
}
"#,
)
.expect_err("should error"),
.unwrap_err(),
EvalAltResult::ErrorTooManyOperations(..)
));
@ -137,7 +135,7 @@ fn test_max_operations_eval() -> Result<(), Box<EvalAltResult>> {
eval(script);
"#
)
.expect_err("should error"),
.unwrap_err(),
EvalAltResult::ErrorInFunctionCall(.., err, _) if matches!(*err, EvalAltResult::ErrorTooManyOperations(..))
));
@ -162,7 +160,7 @@ fn test_max_operations_progress() -> Result<(), Box<EvalAltResult>> {
assert!(matches!(
*engine
.run("for x in 0..500 {}")
.expect_err("should error"),
.unwrap_err(),
EvalAltResult::ErrorTerminated(x, ..) if x.as_int()? == 42
));

View File

@ -26,17 +26,17 @@ fn test_ops_other_number_types() -> Result<(), Box<EvalAltResult>> {
scope.push("x", 42_u16);
assert!(matches!(
*engine.eval_with_scope::<bool>(&mut scope, "x == 42").expect_err("should error"),
*engine.eval_with_scope::<bool>(&mut scope, "x == 42").unwrap_err(),
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"),
*engine.eval_with_scope::<bool>(&mut scope, "x == 42.0").unwrap_err(),
EvalAltResult::ErrorFunctionNotFound(f, ..) if f.starts_with("== (u16,")
));
assert!(
matches!(*engine.eval_with_scope::<bool>(&mut scope, r#"x == "hello""#).expect_err("should error"),
matches!(*engine.eval_with_scope::<bool>(&mut scope, r#"x == "hello""#).unwrap_err(),
EvalAltResult::ErrorFunctionNotFound(f, ..) if f.starts_with("== (u16,")
)
);

View File

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

File diff suppressed because one or more lines are too long

View File

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

View File

@ -110,7 +110,7 @@ fn test_switch_errors() -> Result<(), Box<EvalAltResult>> {
assert!(matches!(
engine
.compile("switch x { _ => 123, 1 => 42 }")
.expect_err("should error")
.unwrap_err()
.err_type(),
ParseErrorType::WrongSwitchDefaultCase
));
@ -174,7 +174,7 @@ fn test_switch_condition() -> Result<(), Box<EvalAltResult>> {
assert!(matches!(
engine
.compile("switch x { 1 => 123, _ if true => 42 }")
.expect_err("should error")
.unwrap_err()
.err_type(),
ParseErrorType::WrongSwitchCaseCondition
));
@ -269,14 +269,14 @@ fn test_switch_ranges() -> Result<(), Box<EvalAltResult>> {
assert!(matches!(
engine.compile(
"switch x { 10..20 => (), 20..=42 => 'a', 25..45 => 'z', 42 => 'x', 30..100 => true }"
).expect_err("should error").err_type(),
).unwrap_err().err_type(),
ParseErrorType::WrongSwitchIntegerCase
));
#[cfg(not(feature = "no_float"))]
assert!(matches!(
engine.compile(
"switch x { 10..20 => (), 20..=42 => 'a', 25..45 => 'z', 42.0 => 'x', 30..100 => true }"
).expect_err("should error").err_type(),
).unwrap_err().err_type(),
ParseErrorType::WrongSwitchIntegerCase
));
assert_eq!(

View File

@ -9,7 +9,7 @@ fn test_tokens_disabled() {
assert!(matches!(
engine
.compile("let x = if true { 42 } else { 0 };")
.expect_err("should error")
.unwrap_err()
.err_type(),
ParseErrorType::Reserved(err) if err == "if"
));
@ -19,13 +19,13 @@ fn test_tokens_disabled() {
assert_eq!(
*engine
.compile("let x = 40 + 2; x += 1;")
.expect_err("should error")
.unwrap_err()
.err_type(),
ParseErrorType::UnknownOperator("+=".to_string())
);
assert!(matches!(
engine.compile("let x = += 0;").expect_err("should error").err_type(),
engine.compile("let x = += 0;").unwrap_err().err_type(),
ParseErrorType::Reserved(err) if err == "+="
));
}

View File

@ -17,6 +17,6 @@ fn test_unit_eq() -> Result<(), Box<EvalAltResult>> {
#[test]
fn test_unit_with_spaces() -> Result<(), Box<EvalAltResult>> {
let engine = Engine::new();
let _ = engine.run("let x = ( ); x").expect_err("should error");
let _ = engine.run("let x = ( ); x").unwrap_err();
Ok(())
}

View File

@ -209,7 +209,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"),
matches!(*engine.eval_with_scope::<INT>(&mut scope, "DO_NOT_USE").unwrap_err(),
EvalAltResult::ErrorVariableNotFound(n, ..) if n == "DO_NOT_USE")
);
@ -235,7 +235,7 @@ fn test_var_def_filter() -> Result<(), Box<EvalAltResult>> {
);
assert!(matches!(
engine.compile("let x = 42;").expect_err("should error").err_type(),
engine.compile("let x = 42;").unwrap_err().err_type(),
ParseErrorType::ForbiddenVariable(s) if s == "x"
));
assert!(matches!(