feat: 添加严格比较运算符与一元加法

This commit is contained in:
爱特每羊队
2026-06-06 20:08:10 +08:00
parent 33314265eb
commit e245ab347a
7 changed files with 263 additions and 0 deletions
+55
View File
@@ -1,5 +1,7 @@
use oxide_compiler::compiler::Compiler;
use oxide_parser::Allocator;
use oxide_types::value::JsValue;
use oxide_vm::coercion;
use oxide_vm::vm::Vm;
fn eval(source: &str) -> String {
@@ -33,3 +35,56 @@ fn eval_coercion_bool_equals_int() {
fn eval_not_falsy() {
assert_eq!(eval("!0"), "true");
}
#[test]
fn test_same_value_signed_zero() {
assert!(!coercion::same_value(
JsValue::float(0.0),
JsValue::float(-0.0)
));
}
#[test]
fn test_strict_equality_signed_zero() {
assert!(coercion::strict_equality(
JsValue::float(0.0),
JsValue::float(-0.0)
));
}
#[test]
fn test_same_value_nan() {
assert!(coercion::same_value(
JsValue::float(f64::NAN),
JsValue::float(f64::NAN)
));
}
#[test]
fn test_same_value_type_mismatch() {
assert!(!coercion::same_value(JsValue::int(1), JsValue::float(1.0)));
}
#[test]
fn test_strict_equality_nan() {
assert!(!coercion::strict_equality(
JsValue::float(f64::NAN),
JsValue::float(f64::NAN)
));
}
#[test]
fn test_strict_equality_type_mismatch() {
assert!(!coercion::strict_equality(
JsValue::int(1),
JsValue::float(1.0)
));
}
#[test]
fn test_strict_equality_null_undefined() {
assert!(!coercion::strict_equality(
JsValue::null(),
JsValue::undefined()
));
}