1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:07:34 +00:00

LibJS: Convert some top-level tests to the new system

First test conversions! These look really good :)
This commit is contained in:
Matthew Olsson 2020-07-03 14:39:25 -07:00 committed by Andreas Kling
parent 4b8a3e6d78
commit eea6041302
22 changed files with 464 additions and 451 deletions

View file

@ -1,51 +1,49 @@
load("test-common.js");
try {
test("new-expression parsing", () => {
function Foo() { this.x = 1; }
let foo = new Foo();
assert(foo.x === 1);
expect(foo.x).toBe(1);
foo = new Foo
assert(foo.x === 1);
expect(foo.x).toBe(1);
foo = new
Foo
()
assert(foo.x === 1);
expect(foo.x).toBe(1);
foo = new Foo + 2
assert(foo === "[object Object]2");
expect(foo).toBe("[object Object]2");
});
test("new-expressions with object keys", () => {
let a = {
b: function() {
this.x = 2;
},
};
foo = new a.b();
assert(foo.x === 2);
expect(foo.x).toBe(2);
foo = new a.b;
assert(foo.x === 2);
expect(foo.x).toBe(2);
foo = new
a.b();
assert(foo.x === 2);
expect(foo.x).toBe(2);
});
test("new-expressions with function calls", () => {
function funcGetter() {
return function(a, b) {
this.x = a + b;
};
};
foo = new funcGetter()(1, 5);
assert(foo === undefined);
expect(foo).toBeUndefined();
foo = new (funcGetter())(1, 5);
assert(foo.x === 6);
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}
expect(foo.x).toBe(6);
});