Skip to content

Commit

Permalink
Fix wrong neg operation (#3926)
Browse files Browse the repository at this point in the history
* fix: fix wrong neg operation

* chore: merge match arm

* chore: add tests
  • Loading branch information
CrazyboyQCD authored Jul 23, 2024
1 parent 21a9778 commit 6e6d67c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 2 additions & 3 deletions core/engine/src/value/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,10 +477,9 @@ impl JsValue {
),
Self::String(ref str) => Self::new(-str.to_number()),
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::Boolean(true) => Self::new(1),
Self::Boolean(false) | Self::Null => Self::new(0),
Self::Boolean(true) => Self::new(-f64::from(1)),
Self::BigInt(ref x) => Self::new(JsBigInt::neg(x)),
})
}
Expand Down
3 changes: 3 additions & 0 deletions core/engine/src/value/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ fn abstract_equality_comparison() {
TestAction::assert("+0 == 0"),
TestAction::assert("-0 == 0"),
TestAction::assert("0 == false"),
TestAction::assert("-0 == -false"),
TestAction::assert("-0 == -null"),
TestAction::assert("-1 == -true"),
TestAction::assert("'' == false"),
TestAction::assert("'' == 0"),
TestAction::assert("'17' == 17"),
Expand Down

0 comments on commit 6e6d67c

Please sign in to comment.