Use String::new() for empty strings.

This commit is contained in:
Stephen Chung
2022-08-21 17:35:44 +08:00
parent 248888ce0b
commit 2f02b30b6e
7 changed files with 25 additions and 27 deletions

View File

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

View File

@@ -303,7 +303,7 @@ fn test_custom_syntax_raw() -> Result<(), Box<EvalAltResult>> {
.compile("hello hey")
.expect_err("should error")
.err_type(),
ParseErrorType::BadInput(LexError::ImproperSymbol("hey".to_string(), "".to_string()))
ParseErrorType::BadInput(LexError::ImproperSymbol("hey".to_string(), String::new()))
);
Ok(())