mirror of
https://github.com/RGBCube/serenity
synced 2025-05-16 19:05:08 +00:00
test-js: Use prettier and format all files
This commit is contained in:
parent
e532888242
commit
6d58c48c2f
248 changed files with 8291 additions and 7725 deletions
|
@ -1,158 +1,166 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
class X {
|
||||
constructor() {
|
||||
this.x = 3;
|
||||
}
|
||||
getX() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
init() {
|
||||
this.y = 3;
|
||||
}
|
||||
class X {
|
||||
constructor() {
|
||||
this.x = 3;
|
||||
}
|
||||
getX() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
assert(X.name === "X");
|
||||
assert(X.length === 0);
|
||||
init() {
|
||||
this.y = 3;
|
||||
}
|
||||
}
|
||||
|
||||
class Y extends X {
|
||||
init() {
|
||||
super.init();
|
||||
this.y += 3;
|
||||
}
|
||||
assert(X.name === "X");
|
||||
assert(X.length === 0);
|
||||
|
||||
class Y extends X {
|
||||
init() {
|
||||
super.init();
|
||||
this.y += 3;
|
||||
}
|
||||
}
|
||||
|
||||
assert(new Y().getX() === 3);
|
||||
assert(new Y().x === 3);
|
||||
|
||||
let x = new X();
|
||||
assert(x.x === 3);
|
||||
assert(x.getX() === 3);
|
||||
|
||||
let y = new Y();
|
||||
assert(y.x === 3);
|
||||
assert(y.y === undefined);
|
||||
y.init();
|
||||
assert(y.y === 6);
|
||||
assert(y.hasOwnProperty("y"));
|
||||
|
||||
class Foo {
|
||||
constructor(x) {
|
||||
this.x = x;
|
||||
}
|
||||
}
|
||||
assert(Foo.length === 1);
|
||||
|
||||
class Bar extends Foo {
|
||||
constructor() {
|
||||
super(5);
|
||||
}
|
||||
}
|
||||
|
||||
class Baz {
|
||||
constructor() {
|
||||
this.foo = 55;
|
||||
this._bar = 33;
|
||||
}
|
||||
|
||||
assert(new Y().getX() === 3);
|
||||
assert(new Y().x === 3);
|
||||
|
||||
let x = new X();
|
||||
assert(x.x === 3);
|
||||
assert(x.getX() === 3);
|
||||
|
||||
let y = new Y();
|
||||
assert(y.x === 3);
|
||||
assert(y.y === undefined);
|
||||
y.init();
|
||||
assert(y.y === 6);
|
||||
assert(y.hasOwnProperty("y"));
|
||||
|
||||
class Foo {
|
||||
constructor(x) {
|
||||
this.x = x;
|
||||
}
|
||||
}
|
||||
assert(Foo.length === 1);
|
||||
|
||||
class Bar extends Foo {
|
||||
constructor() {
|
||||
super(5);
|
||||
}
|
||||
get bar() {
|
||||
return this._bar;
|
||||
}
|
||||
|
||||
class Baz {
|
||||
"constructor"() {
|
||||
this.foo = 55;
|
||||
this._bar = 33;
|
||||
}
|
||||
|
||||
get bar() {
|
||||
return this._bar;
|
||||
}
|
||||
|
||||
set bar(value) {
|
||||
this._bar = value;
|
||||
}
|
||||
|
||||
["get" + "Foo"]() {
|
||||
return this.foo;
|
||||
}
|
||||
|
||||
static get staticFoo() {
|
||||
assert(this === Baz);
|
||||
return 11;
|
||||
}
|
||||
set bar(value) {
|
||||
this._bar = value;
|
||||
}
|
||||
|
||||
|
||||
let barPropertyDescriptor = Object.getOwnPropertyDescriptor(Baz.prototype, "bar");
|
||||
assert(barPropertyDescriptor.get.name === "get bar");
|
||||
assert(barPropertyDescriptor.set.name === "set bar");
|
||||
|
||||
let baz = new Baz();
|
||||
assert(baz.foo === 55);
|
||||
assert(baz.bar === 33);
|
||||
baz.bar = 22;
|
||||
assert(baz.bar === 22);
|
||||
|
||||
assert(baz.getFoo() === 55);
|
||||
assert(Baz.staticFoo === 11);
|
||||
|
||||
assert(new Bar().x === 5);
|
||||
|
||||
class ExtendsFunction extends function () { this.foo = 22; } { }
|
||||
assert(new ExtendsFunction().foo === 22);
|
||||
|
||||
class ExtendsString extends String { }
|
||||
assert(new ExtendsString() instanceof String);
|
||||
assert(new ExtendsString() instanceof ExtendsString);
|
||||
assert(new ExtendsString("abc").charAt(1) === "b");
|
||||
|
||||
class MyWeirdString extends ExtendsString {
|
||||
charAt(i) {
|
||||
return "#" + super.charAt(i);
|
||||
}
|
||||
}
|
||||
assert(new MyWeirdString("abc").charAt(1) === "#b")
|
||||
|
||||
class ExtendsNull extends null { }
|
||||
|
||||
assertThrowsError(() => {
|
||||
new ExtendsNull();
|
||||
}, {
|
||||
error: ReferenceError
|
||||
});
|
||||
assert(Object.getPrototypeOf(ExtendsNull.prototype) === null);
|
||||
|
||||
class ExtendsClassExpression extends class { constructor(x) { this.x = x; } } {
|
||||
constructor(y) {
|
||||
super(5);
|
||||
this.y = 6;
|
||||
}
|
||||
}
|
||||
let extendsClassExpression = new ExtendsClassExpression();
|
||||
assert(extendsClassExpression.x === 5);
|
||||
assert(extendsClassExpression.y === 6);
|
||||
|
||||
class InStrictMode {
|
||||
constructor() {
|
||||
assert(isStrictMode());
|
||||
}
|
||||
|
||||
method() {
|
||||
assert(isStrictMode());
|
||||
}
|
||||
["get" + "Foo"]() {
|
||||
return this.foo;
|
||||
}
|
||||
|
||||
let resultOfAnExpression = new (class {
|
||||
constructor(x) {
|
||||
this.x = x;
|
||||
}
|
||||
getX() {
|
||||
return this.x + 10;
|
||||
}
|
||||
})(55);
|
||||
assert(resultOfAnExpression.x === 55);
|
||||
assert(resultOfAnExpression.getX() === 65);
|
||||
static get staticFoo() {
|
||||
assert(this === Baz);
|
||||
return 11;
|
||||
}
|
||||
}
|
||||
|
||||
let ClassExpression = class Foo { };
|
||||
assert(ClassExpression.name === "Foo");
|
||||
let barPropertyDescriptor = Object.getOwnPropertyDescriptor(Baz.prototype, "bar");
|
||||
assert(barPropertyDescriptor.get.name === "get bar");
|
||||
assert(barPropertyDescriptor.set.name === "set bar");
|
||||
|
||||
new InStrictMode().method();
|
||||
assert(!isStrictMode());
|
||||
let baz = new Baz();
|
||||
assert(baz.foo === 55);
|
||||
assert(baz.bar === 33);
|
||||
baz.bar = 22;
|
||||
assert(baz.bar === 22);
|
||||
|
||||
assertIsSyntaxError(`
|
||||
assert(baz.getFoo() === 55);
|
||||
assert(Baz.staticFoo === 11);
|
||||
|
||||
assert(new Bar().x === 5);
|
||||
|
||||
class ExtendsFunction extends function () {
|
||||
this.foo = 22;
|
||||
} {}
|
||||
assert(new ExtendsFunction().foo === 22);
|
||||
|
||||
class ExtendsString extends String {}
|
||||
assert(new ExtendsString() instanceof String);
|
||||
assert(new ExtendsString() instanceof ExtendsString);
|
||||
assert(new ExtendsString("abc").charAt(1) === "b");
|
||||
|
||||
class MyWeirdString extends ExtendsString {
|
||||
charAt(i) {
|
||||
return "#" + super.charAt(i);
|
||||
}
|
||||
}
|
||||
assert(new MyWeirdString("abc").charAt(1) === "#b");
|
||||
|
||||
class ExtendsNull extends null {}
|
||||
|
||||
assertThrowsError(
|
||||
() => {
|
||||
new ExtendsNull();
|
||||
},
|
||||
{
|
||||
error: ReferenceError,
|
||||
}
|
||||
);
|
||||
assert(Object.getPrototypeOf(ExtendsNull.prototype) === null);
|
||||
|
||||
class ExtendsClassExpression extends class {
|
||||
constructor(x) {
|
||||
this.x = x;
|
||||
}
|
||||
} {
|
||||
constructor(y) {
|
||||
super(5);
|
||||
this.y = 6;
|
||||
}
|
||||
}
|
||||
let extendsClassExpression = new ExtendsClassExpression();
|
||||
assert(extendsClassExpression.x === 5);
|
||||
assert(extendsClassExpression.y === 6);
|
||||
|
||||
class InStrictMode {
|
||||
constructor() {
|
||||
assert(isStrictMode());
|
||||
}
|
||||
|
||||
method() {
|
||||
assert(isStrictMode());
|
||||
}
|
||||
}
|
||||
|
||||
let resultOfAnExpression = new (class {
|
||||
constructor(x) {
|
||||
this.x = x;
|
||||
}
|
||||
getX() {
|
||||
return this.x + 10;
|
||||
}
|
||||
})(55);
|
||||
assert(resultOfAnExpression.x === 55);
|
||||
assert(resultOfAnExpression.getX() === 65);
|
||||
|
||||
let ClassExpression = class Foo {};
|
||||
assert(ClassExpression.name === "Foo");
|
||||
|
||||
new InStrictMode().method();
|
||||
assert(!isStrictMode());
|
||||
|
||||
assertIsSyntaxError(`
|
||||
class GetterWithArgument {
|
||||
get foo(bar) {
|
||||
return 0;
|
||||
|
@ -160,21 +168,21 @@ try {
|
|||
}
|
||||
`);
|
||||
|
||||
assertIsSyntaxError(`
|
||||
assertIsSyntaxError(`
|
||||
class SetterWithNoArgumetns {
|
||||
set foo() {
|
||||
}
|
||||
}
|
||||
`);
|
||||
|
||||
assertIsSyntaxError(`
|
||||
assertIsSyntaxError(`
|
||||
class SetterWithMoreThanOneArgument {
|
||||
set foo(bar, baz) {
|
||||
}
|
||||
}
|
||||
`);
|
||||
|
||||
assertIsSyntaxError(`
|
||||
assertIsSyntaxError(`
|
||||
class FooBase {}
|
||||
class IsASyntaxError extends FooBase {
|
||||
bar() {
|
||||
|
@ -183,7 +191,7 @@ try {
|
|||
}
|
||||
`);
|
||||
|
||||
assertIsSyntaxError(`
|
||||
assertIsSyntaxError(`
|
||||
class NoBaseSuper {
|
||||
constructor() {
|
||||
super();
|
||||
|
@ -191,58 +199,71 @@ try {
|
|||
}
|
||||
`);
|
||||
|
||||
assertThrowsError(() => {
|
||||
class BadExtends extends 3 { }
|
||||
|
||||
}, {
|
||||
error: TypeError
|
||||
});
|
||||
|
||||
assertThrowsError(() => {
|
||||
class BadExtends extends undefined { }
|
||||
}, {
|
||||
error: TypeError
|
||||
});
|
||||
|
||||
class SuperNotASyntaxError {
|
||||
bar() {
|
||||
() => { super.baz };
|
||||
}
|
||||
assertThrowsError(
|
||||
() => {
|
||||
class BadExtends extends 3 {}
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
}
|
||||
);
|
||||
|
||||
class SuperNoBasePropertyLookup {
|
||||
assertThrowsError(
|
||||
() => {
|
||||
class BadExtends extends undefined {}
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
}
|
||||
);
|
||||
|
||||
class SuperNotASyntaxError {
|
||||
bar() {
|
||||
() => {
|
||||
super.baz;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class SuperNoBasePropertyLookup {
|
||||
constructor() {
|
||||
super.foo;
|
||||
}
|
||||
}
|
||||
|
||||
assertThrowsError(
|
||||
() => {
|
||||
class Base {}
|
||||
class DerivedDoesntCallSuper extends Base {
|
||||
constructor() {
|
||||
super.foo;
|
||||
this;
|
||||
}
|
||||
}
|
||||
|
||||
new DerivedDoesntCallSuper();
|
||||
},
|
||||
{
|
||||
error: ReferenceError,
|
||||
}
|
||||
|
||||
assertThrowsError(() => {
|
||||
class Base { }
|
||||
class DerivedDoesntCallSuper extends Base {
|
||||
constructor() {
|
||||
this;
|
||||
}
|
||||
);
|
||||
assertThrowsError(
|
||||
() => {
|
||||
class Base {}
|
||||
class CallsSuperTwice extends Base {
|
||||
constructor() {
|
||||
super();
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
new DerivedDoesntCallSuper();
|
||||
}, {
|
||||
error: ReferenceError,
|
||||
});
|
||||
assertThrowsError(() => {
|
||||
class Base { }
|
||||
class CallsSuperTwice extends Base {
|
||||
constructor() {
|
||||
super();
|
||||
super();
|
||||
}
|
||||
}
|
||||
new CallsSuperTwice();
|
||||
},
|
||||
{
|
||||
error: ReferenceError,
|
||||
}
|
||||
);
|
||||
|
||||
new CallsSuperTwice();
|
||||
}, {
|
||||
error: ReferenceError,
|
||||
});
|
||||
|
||||
console.log("PASS");
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue