Browse Source

Fix wrong `neg` operation (#3926)

* fix: fix wrong neg operation

* chore: merge match arm

* chore: add tests
pull/3936/head
CrazyboyQCD 4 months ago committed by GitHub
parent
commit
6e6d67c56f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 5
      core/engine/src/value/operations.rs
  2. 3
      core/engine/src/value/tests.rs

5
core/engine/src/value/operations.rs

@ -477,10 +477,9 @@ impl JsValue {
), ),
Self::String(ref str) => Self::new(-str.to_number()), Self::String(ref str) => Self::new(-str.to_number()),
Self::Rational(num) => Self::new(-num), Self::Rational(num) => Self::new(-num),
Self::Integer(0) => Self::new(-f64::from(0)), Self::Integer(0) | Self::Boolean(false) | Self::Null => Self::new(-f64::from(0)),
Self::Integer(num) => Self::new(-num), Self::Integer(num) => Self::new(-num),
Self::Boolean(true) => Self::new(1), Self::Boolean(true) => Self::new(-f64::from(1)),
Self::Boolean(false) | Self::Null => Self::new(0),
Self::BigInt(ref x) => Self::new(JsBigInt::neg(x)), Self::BigInt(ref x) => Self::new(JsBigInt::neg(x)),
}) })
} }

3
core/engine/src/value/tests.rs

@ -64,6 +64,9 @@ fn abstract_equality_comparison() {
TestAction::assert("+0 == 0"), TestAction::assert("+0 == 0"),
TestAction::assert("-0 == 0"), TestAction::assert("-0 == 0"),
TestAction::assert("0 == false"), TestAction::assert("0 == false"),
TestAction::assert("-0 == -false"),
TestAction::assert("-0 == -null"),
TestAction::assert("-1 == -true"),
TestAction::assert("'' == false"), TestAction::assert("'' == false"),
TestAction::assert("'' == 0"), TestAction::assert("'' == 0"),
TestAction::assert("'17' == 17"), TestAction::assert("'17' == 17"),

Loading…
Cancel
Save