Skip to content

Commit a72e9d6

Browse files
committed
fix(interpreter): updated test_relational_operators_error_with_strings → test_relational_operators_with_strings to verify that string equality and inequality work correctly instead of expecting an error.
1 parent 99a965e commit a72e9d6

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

src/interpreter/expression_eval.rs

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3032,21 +3032,35 @@ mod tests {
30323032
}
30333033

30343034
#[test]
3035-
fn test_relational_operators_error_with_strings() {
3035+
fn test_relational_operators_with_strings() {
30363036
let env = create_test_env();
3037-
let expr = Expression::EQ(
3037+
3038+
// Test string equality - equal strings
3039+
let expr_eq = Expression::EQ(
3040+
Box::new(Expression::CString("hello".to_string())),
30383041
Box::new(Expression::CString("hello".to_string())),
3039-
Box::new(Expression::CString("world".to_string())),
30403042
);
3043+
let result = eval(expr_eq, &env);
3044+
assert!(result.is_ok());
3045+
assert_eq!(result.unwrap(), ExpressionResult::Value(Expression::CTrue));
30413046

3042-
let result = eval(expr, &env);
3047+
// Test string equality - unequal strings
3048+
let expr_neq = Expression::EQ(
3049+
Box::new(Expression::CString("hello".to_string())),
3050+
Box::new(Expression::CString("world".to_string())),
3051+
);
3052+
let result = eval(expr_neq, &env);
3053+
assert!(result.is_ok());
3054+
assert_eq!(result.unwrap(), ExpressionResult::Value(Expression::CFalse));
30433055

3044-
assert!(result.is_err());
3045-
let error = result.unwrap_err();
3046-
assert_eq!(
3047-
error,
3048-
"equality '(==)' is only defined for numbers (integers and real)."
3056+
// Test string inequality
3057+
let expr_neq2 = Expression::NEQ(
3058+
Box::new(Expression::CString("hello".to_string())),
3059+
Box::new(Expression::CString("world".to_string())),
30493060
);
3061+
let result = eval(expr_neq2, &env);
3062+
assert!(result.is_ok());
3063+
assert_eq!(result.unwrap(), ExpressionResult::Value(Expression::CTrue));
30503064
}
30513065

30523066
#[test]

0 commit comments

Comments
 (0)