ladybird/Userland/Libraries/LibJS/Tests/parser-unary-associativity.js
Sam Kravitz 073eb46824 LibJS: Apply the correct precedence for unary + and - operators
When determining the precedence of the + and - operators, the parser
always returned the precedence using these operators in a binary
expression (lower than division!). The context of whether the operator
is used in a unary or binary expression must be taken into account.
2023-08-08 07:41:07 +02:00

18 lines
525 B
JavaScript

test("basic functionality", () => {
const o = {};
o.a = 1;
expect(o.a === 1).toBeTrue();
expect(!o.a === false).toBeTrue();
expect(!o.a === !o.a).toBeTrue();
expect(~o.a === ~o.a).toBeTrue();
expect(+o.a === +o.a).toBeTrue();
expect(-o.a === -o.a).toBeTrue();
expect((typeof "x" === "string") === true).toBeTrue();
expect(!(typeof "x" === "string") === false).toBeTrue();
});
test("unary +/- operators bind higher than binary", () => {
expect(10 ** -3 / 2).toEqual(0.0005);
});