diff --git a/tests/call_fn.rs b/tests/call_fn.rs index a22f7b6d..a7a5d514 100644 --- a/tests/call_fn.rs +++ b/tests/call_fn.rs @@ -1,7 +1,6 @@ #![cfg(not(feature = "no_function"))] use rhai::{ - Dynamic, Engine, EvalAltResult, FnPtr, Func, Module, ParseError, ParseErrorType, RegisterFn, - Scope, INT, + Dynamic, Engine, EvalAltResult, FnPtr, Func, Module, ParseErrorType, RegisterFn, Scope, INT, }; use std::any::TypeId; @@ -10,12 +9,13 @@ fn test_fn() -> Result<(), Box> { let engine = Engine::new(); // Expect duplicated parameters error - assert!(matches!( - engine + assert_eq!( + *engine .compile("fn hello(x, x) { x }") - .expect_err("should be error"), - ParseError(x, _) if *x == ParseErrorType::FnDuplicatedParam("hello".to_string(), "x".to_string()) - )); + .expect_err("should be error") + .0, + ParseErrorType::FnDuplicatedParam("hello".to_string(), "x".to_string()) + ); Ok(()) } diff --git a/tests/data_size.rs b/tests/data_size.rs index 33257cfd..ca91fb5c 100644 --- a/tests/data_size.rs +++ b/tests/data_size.rs @@ -1,5 +1,5 @@ #![cfg(not(feature = "unchecked"))] -use rhai::{Engine, EvalAltResult, ParseError, ParseErrorType}; +use rhai::{Engine, EvalAltResult, ParseErrorType}; #[cfg(not(feature = "no_index"))] use rhai::Array; @@ -12,15 +12,21 @@ fn test_max_string_size() -> Result<(), Box> { let mut engine = Engine::new(); engine.set_max_string_size(10); - assert!(matches!( - engine.compile(r#"let x = "hello, world!";"#).expect_err("should error"), - ParseError(x, _) if *x == ParseErrorType::LiteralTooLarge("Length of string literal".to_string(), 10) - )); + assert_eq!( + *engine + .compile(r#"let x = "hello, world!";"#) + .expect_err("should error") + .0, + ParseErrorType::LiteralTooLarge("Length of string literal".to_string(), 10) + ); - assert!(matches!( - engine.compile(r#"let x = "朝に紅顔、暮に白骨";"#).expect_err("should error"), - ParseError(x, _) if *x == ParseErrorType::LiteralTooLarge("Length of string literal".to_string(), 10) - )); + assert_eq!( + *engine + .compile(r#"let x = "朝に紅顔、暮に白骨";"#) + .expect_err("should error") + .0, + ParseErrorType::LiteralTooLarge("Length of string literal".to_string(), 10) + ); assert!(matches!( *engine @@ -74,12 +80,13 @@ fn test_max_array_size() -> Result<(), Box> { #[cfg(not(feature = "no_object"))] engine.set_max_map_size(10); - assert!(matches!( - engine + 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"), - ParseError(x, _) if *x == ParseErrorType::LiteralTooLarge("Size of array literal".to_string(), 10) - )); + .expect_err("should error") + .0, + ParseErrorType::LiteralTooLarge("Size of array literal".to_string(), 10) + ); assert!(matches!( *engine @@ -186,12 +193,18 @@ fn test_max_map_size() -> Result<(), Box> { #[cfg(not(feature = "no_index"))] engine.set_max_array_size(10); - assert!(matches!( - engine - .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"), - ParseError(x, _) if *x == ParseErrorType::LiteralTooLarge("Number of properties in object map literal".to_string(), 10) - )); + assert_eq!( + *engine + .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") + .0, + ParseErrorType::LiteralTooLarge( + "Number of properties in object map literal".to_string(), + 10 + ) + ); assert!(matches!( *engine diff --git a/tests/functions.rs b/tests/functions.rs index 58ef8d99..296f0ddd 100644 --- a/tests/functions.rs +++ b/tests/functions.rs @@ -1,5 +1,6 @@ #![cfg(not(feature = "no_function"))] -use rhai::{Engine, EvalAltResult, ParseError, ParseErrorType, INT}; +use rhai::{Engine, EvalAltResult, ParseErrorType, INT}; +use std::io::Read; #[test] fn test_functions() -> Result<(), Box> { @@ -155,8 +156,9 @@ fn test_function_captures() -> Result<(), Box> { #[cfg(not(feature = "no_object"))] assert!(matches!( - engine.compile( - r#" + *engine + .compile( + r#" fn foo() { this += x; } let x = 41; @@ -164,8 +166,10 @@ fn test_function_captures() -> Result<(), Box> { y.foo!(); "# - ).expect_err("should error"), - ParseError(err, _) if matches!(*err, ParseErrorType::MalformedCapture(_)) + ) + .expect_err("should error") + .0, + ParseErrorType::MalformedCapture(_) )); Ok(()) diff --git a/tests/looping.rs b/tests/looping.rs index 951f8cd7..23f87bb0 100644 --- a/tests/looping.rs +++ b/tests/looping.rs @@ -1,4 +1,4 @@ -use rhai::{Engine, EvalAltResult, ParseError, ParseErrorType, INT}; +use rhai::{Engine, EvalAltResult, ParseErrorType, INT}; #[test] fn test_loop() -> Result<(), Box> { @@ -26,15 +26,21 @@ fn test_loop() -> Result<(), Box> { 21 ); - assert!(matches!( - engine.compile("let x = 0; break;").expect_err("should error"), - ParseError(x, _) if *x == ParseErrorType::LoopBreak - )); + assert_eq!( + *engine + .compile("let x = 0; break;") + .expect_err("should error") + .0, + ParseErrorType::LoopBreak + ); - assert!(matches!( - engine.compile("let x = 0; if x > 0 { continue; }").expect_err("should error"), - ParseError(x, _) if *x == ParseErrorType::LoopBreak - )); + assert_eq!( + *engine + .compile("let x = 0; if x > 0 { continue; }") + .expect_err("should error") + .0, + ParseErrorType::LoopBreak + ); Ok(()) } diff --git a/tests/stack.rs b/tests/stack.rs index 47202b47..b7ff9a57 100644 --- a/tests/stack.rs +++ b/tests/stack.rs @@ -1,5 +1,5 @@ #![cfg(not(feature = "unchecked"))] -use rhai::{Engine, EvalAltResult, ParseError, ParseErrorType, INT}; +use rhai::{Engine, EvalAltResult, ParseErrorType, INT}; #[test] #[cfg(not(feature = "no_function"))] @@ -33,12 +33,12 @@ fn test_stack_overflow_fn_calls() -> Result<(), Box> { fn test_stack_overflow_parsing() -> Result<(), Box> { let mut engine = Engine::new(); - assert!(matches!( - engine.compile(r" + assert_eq!( + *engine.compile(r" let a = (1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+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1+(1+(1+(1+(1+(1+(1+(1+1)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) - ").expect_err("should error"), - ParseError(x, _) if *x == ParseErrorType::ExprTooDeep - )); + ").expect_err("should error").0, + ParseErrorType::ExprTooDeep + ); engine.set_max_expr_depths(100, 6); @@ -58,8 +58,10 @@ fn test_stack_overflow_parsing() -> Result<(), Box> { ", )?; - assert!(matches!( - engine.compile(r" + assert_eq!( + *engine + .compile( + r" 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 0 + @@ -70,9 +72,12 @@ fn test_stack_overflow_parsing() -> Result<(), Box> { 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 - ").expect_err("should error"), - ParseError(x, _) if *x == ParseErrorType::ExprTooDeep - )); + " + ) + .expect_err("should error") + .0, + ParseErrorType::ExprTooDeep + ); #[cfg(not(feature = "no_function"))] engine.compile("fn abc(x) { x + 1 }")?;