mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-28 12:18:25 +00:00
Libraries: Move to Userland/Libraries/
This commit is contained in:
53
Userland/Libraries/LibJS/Tests/update-expressions-basic.js
Normal file
53
Userland/Libraries/LibJS/Tests/update-expressions-basic.js
Normal file
@@ -0,0 +1,53 @@
|
||||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
let n = 0;
|
||||
expect(++n).toBe(1);
|
||||
expect(n).toBe(1);
|
||||
|
||||
n = 0;
|
||||
expect(n++).toBe(0);
|
||||
expect(n).toBe(1);
|
||||
|
||||
n = 0;
|
||||
expect(--n).toBe(-1);
|
||||
expect(n).toBe(-1);
|
||||
|
||||
n = 0;
|
||||
expect(n--).toBe(0);
|
||||
expect(n).toBe(-1);
|
||||
|
||||
let a = [];
|
||||
expect(a++).toBe(0);
|
||||
expect(a).toBe(1);
|
||||
|
||||
let b = true;
|
||||
expect(b--).toBe(1);
|
||||
expect(b).toBe(0);
|
||||
});
|
||||
|
||||
test("updates that produce NaN", () => {
|
||||
let s = "foo";
|
||||
expect(++s).toBeNaN();
|
||||
expect(s).toBeNaN();
|
||||
|
||||
s = "foo";
|
||||
expect(s++).toBeNaN();
|
||||
expect(s).toBeNaN();
|
||||
|
||||
s = "foo";
|
||||
expect(--s).toBeNaN();
|
||||
expect(s).toBeNaN();
|
||||
|
||||
s = "foo";
|
||||
expect(s--).toBeNaN();
|
||||
expect(s).toBeNaN();
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("update expression throws reference error", () => {
|
||||
expect(() => {
|
||||
++x;
|
||||
}).toThrowWithMessage(ReferenceError, "'x' is not defined");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user