Skip to content

Commit 1646e0e

Browse files
committed
Implement string equality ops
1 parent 0e60600 commit 1646e0e

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/stdlib/core/ops.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,12 @@ thread_local! {
156156
method
157157
};
158158

159-
let add_method = new_binop(BinaryOperator::Add);
159+
let add = new_binop(BinaryOperator::Add);
160160
new_binop(BinaryOperator::Sub);
161161
new_binop(BinaryOperator::Mul);
162162
new_binop(BinaryOperator::Div);
163-
new_binop(BinaryOperator::Equal);
164-
new_binop(BinaryOperator::NotEqual);
163+
let equal = new_binop(BinaryOperator::Equal);
164+
let not_equal = new_binop(BinaryOperator::NotEqual);
165165
new_binop(BinaryOperator::Lt);
166166
new_binop(BinaryOperator::Lte);
167167
new_binop(BinaryOperator::Gt);
@@ -175,8 +175,12 @@ thread_local! {
175175

176176
equality_ops!(m, Bool, Bool, bool);
177177

178-
let mut add_method = add_method.borrow_mut();
179-
add_method.register(binop!(String, String, String, |a, b| format!("{}{}", a, b).into_boxed_str()));
178+
let mut add = add.borrow_mut();
179+
let mut equal = equal.borrow_mut();
180+
let mut not_equal = not_equal.borrow_mut();
181+
add.register(binop!(String, String, String, |a, b| format!("{}{}", a, b).into_boxed_str()));
182+
equal.register(binop!(String, String, Bool, |a, b| a == b));
183+
not_equal.register(binop!(String, String, Bool, |a, b| a != b));
180184
}
181185

182186
m

tests/methods.rs

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ fn test_methods() {
2222
("10.1 > 10", Value::Bool(true)),
2323
("-1", Value::Int(-1)),
2424
("-10.5", Value::Float(-10.5)),
25+
("(\"hai\" + \"world\") == \"haiworld\"", Value::Bool(true)),
26+
("(\"hai\" + \"world\") == \"bye\"", Value::Bool(false)),
27+
("(\"hai\" + \"world\") != \"haiworld\"", Value::Bool(false)),
2528
]);
2629
}
2730

0 commit comments

Comments
 (0)