mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:07:35 +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,119 +1,122 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
let getNumber = () => 42;
|
||||
assert(getNumber() === 42);
|
||||
let getNumber = () => 42;
|
||||
assert(getNumber() === 42);
|
||||
|
||||
getNumber = () => 99;
|
||||
assert(getNumber() === 99);
|
||||
getNumber = () => 99;
|
||||
assert(getNumber() === 99);
|
||||
|
||||
let add = (a, b) => a + b;
|
||||
assert(add(2, 3) === 5);
|
||||
let add = (a, b) => a + b;
|
||||
assert(add(2, 3) === 5);
|
||||
|
||||
const addBlock = (a, b) => {
|
||||
let res = a + b;
|
||||
return res;
|
||||
const addBlock = (a, b) => {
|
||||
let res = a + b;
|
||||
return res;
|
||||
};
|
||||
assert(addBlock(5, 4) === 9);
|
||||
|
||||
let chompy = [x => x, 2];
|
||||
assert(chompy.length === 2);
|
||||
assert(chompy[0](1) === 1);
|
||||
|
||||
const makeObject = (a, b) => ({ a, b });
|
||||
const obj = makeObject(33, 44);
|
||||
assert(typeof obj === "object");
|
||||
assert(obj.a === 33);
|
||||
assert(obj.b === 44);
|
||||
|
||||
let returnUndefined = () => {};
|
||||
assert(typeof returnUndefined() === "undefined");
|
||||
|
||||
const makeArray = (a, b) => [a, b];
|
||||
const array = makeArray("3", { foo: 4 });
|
||||
assert(array[0] === "3");
|
||||
assert(array[1].foo === 4);
|
||||
|
||||
let square = x => x * x;
|
||||
assert(square(3) === 9);
|
||||
|
||||
let squareBlock = x => {
|
||||
return x * x;
|
||||
};
|
||||
assert(squareBlock(4) === 16);
|
||||
|
||||
const message = (who => "Hello " + who)("friends!");
|
||||
assert(message === "Hello friends!");
|
||||
|
||||
const sum = ((x, y, z) => x + y + z)(1, 2, 3);
|
||||
assert(sum === 6);
|
||||
|
||||
const product = ((x, y, z) => {
|
||||
let res = x * y * z;
|
||||
return res;
|
||||
})(5, 4, 2);
|
||||
assert(product === 40);
|
||||
|
||||
const half = (x => {
|
||||
return x / 2;
|
||||
})(10);
|
||||
assert(half === 5);
|
||||
|
||||
var foo, bar;
|
||||
(foo = bar), baz => {};
|
||||
assert(foo === undefined);
|
||||
assert(bar === undefined);
|
||||
|
||||
function FooBar() {
|
||||
this.x = {
|
||||
y: () => this,
|
||||
z: function () {
|
||||
return (() => this)();
|
||||
},
|
||||
};
|
||||
assert(addBlock(5, 4) === 9);
|
||||
}
|
||||
|
||||
let chompy = [(x) => x, 2];
|
||||
assert(chompy.length === 2);
|
||||
assert(chompy[0](1) === 1);
|
||||
var foobar = new FooBar();
|
||||
assert(foobar.x.y() === foobar);
|
||||
assert(foobar.x.z() === foobar.x);
|
||||
|
||||
const makeObject = (a, b) => ({ a, b });
|
||||
const obj = makeObject(33, 44);
|
||||
assert(typeof obj === "object");
|
||||
assert(obj.a === 33);
|
||||
assert(obj.b === 44);
|
||||
var Baz = () => {};
|
||||
|
||||
let returnUndefined = () => { };
|
||||
assert(typeof returnUndefined() === "undefined");
|
||||
assert(Baz.prototype === undefined);
|
||||
|
||||
const makeArray = (a, b) => [a, b];
|
||||
const array = makeArray("3", { foo: 4 });
|
||||
assert(array[0] === "3");
|
||||
assert(array[1].foo === 4);
|
||||
|
||||
let square = x => x * x;
|
||||
assert(square(3) === 9);
|
||||
|
||||
let squareBlock = x => {
|
||||
return x * x;
|
||||
};
|
||||
assert(squareBlock(4) === 16);
|
||||
|
||||
const message = (who => "Hello " + who)("friends!");
|
||||
assert(message === "Hello friends!");
|
||||
|
||||
const sum = ((x, y, z) => x + y + z)(1, 2, 3);
|
||||
assert(sum === 6);
|
||||
|
||||
const product = ((x, y, z) => {
|
||||
let res = x * y * z;
|
||||
return res;
|
||||
})(5, 4, 2);
|
||||
assert(product === 40);
|
||||
|
||||
const half = (x => {
|
||||
return x / 2;
|
||||
})(10);
|
||||
assert(half === 5);
|
||||
|
||||
var foo, bar;
|
||||
foo = bar, baz => {};
|
||||
assert(foo === undefined);
|
||||
assert(bar === undefined);
|
||||
|
||||
function FooBar() {
|
||||
this.x = {
|
||||
y: () => this,
|
||||
z: function () {
|
||||
return (() => this)();
|
||||
}
|
||||
};
|
||||
assertThrowsError(
|
||||
() => {
|
||||
new Baz();
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Baz is not a constructor",
|
||||
}
|
||||
);
|
||||
|
||||
var foobar = new FooBar();
|
||||
assert(foobar.x.y() === foobar);
|
||||
assert(foobar.x.z() === foobar.x);
|
||||
|
||||
var Baz = () => {};
|
||||
|
||||
assert(Baz.prototype === undefined);
|
||||
|
||||
assertThrowsError(() => {
|
||||
new Baz();
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "Baz is not a constructor"
|
||||
});
|
||||
(() => {
|
||||
"use strict";
|
||||
assert(isStrictMode());
|
||||
|
||||
(() => {
|
||||
"use strict";
|
||||
assert(isStrictMode());
|
||||
|
||||
(() => {
|
||||
assert(isStrictMode());
|
||||
})();
|
||||
assert(isStrictMode());
|
||||
})();
|
||||
})();
|
||||
|
||||
(() => {
|
||||
"use strict";
|
||||
assert(isStrictMode());
|
||||
})();
|
||||
|
||||
(() => {
|
||||
assert(!isStrictMode());
|
||||
|
||||
(() => {
|
||||
'use strict';
|
||||
assert(isStrictMode());
|
||||
"use strict";
|
||||
assert(isStrictMode());
|
||||
})();
|
||||
|
||||
(() => {
|
||||
assert(!isStrictMode());
|
||||
assert(!isStrictMode());
|
||||
})();
|
||||
|
||||
(() => {
|
||||
"use strict";
|
||||
assert(isStrictMode());
|
||||
})();
|
||||
|
||||
assert(!isStrictMode());
|
||||
})();
|
||||
|
||||
console.log("PASS");
|
||||
console.log("PASS");
|
||||
} catch {
|
||||
console.log("FAIL");
|
||||
console.log("FAIL");
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ load("test-common.js");
|
|||
|
||||
try {
|
||||
function Foo() {
|
||||
this.x = 123;
|
||||
this.x = 123;
|
||||
}
|
||||
|
||||
assert(Foo.prototype.constructor === Foo);
|
||||
|
|
|
@ -1,52 +1,70 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
assertThrowsError(() => {
|
||||
var b = true;
|
||||
b();
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "true is not a function (evaluated from 'b')"
|
||||
});
|
||||
assertThrowsError(
|
||||
() => {
|
||||
var b = true;
|
||||
b();
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "true is not a function (evaluated from 'b')",
|
||||
}
|
||||
);
|
||||
|
||||
assertThrowsError(() => {
|
||||
var n = 100 + 20 + 3;
|
||||
n();
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "123 is not a function (evaluated from 'n')"
|
||||
});
|
||||
assertThrowsError(
|
||||
() => {
|
||||
var n = 100 + 20 + 3;
|
||||
n();
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "123 is not a function (evaluated from 'n')",
|
||||
}
|
||||
);
|
||||
|
||||
assertThrowsError(() => {
|
||||
var o = {};
|
||||
o.a();
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "undefined is not a function (evaluated from 'o.a')"
|
||||
});
|
||||
assertThrowsError(
|
||||
() => {
|
||||
var o = {};
|
||||
o.a();
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "undefined is not a function (evaluated from 'o.a')",
|
||||
}
|
||||
);
|
||||
|
||||
assertThrowsError(() => {
|
||||
Math();
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "[object MathObject] is not a function (evaluated from 'Math')"
|
||||
});
|
||||
assertThrowsError(
|
||||
() => {
|
||||
Math();
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "[object MathObject] is not a function (evaluated from 'Math')",
|
||||
}
|
||||
);
|
||||
|
||||
assertThrowsError(() => {
|
||||
new Math();
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "[object MathObject] is not a constructor (evaluated from 'Math')"
|
||||
});
|
||||
assertThrowsError(
|
||||
() => {
|
||||
new Math();
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "[object MathObject] is not a constructor (evaluated from 'Math')",
|
||||
}
|
||||
);
|
||||
|
||||
assertThrowsError(() => {
|
||||
new isNaN();
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "[object NativeFunction] is not a constructor (evaluated from 'isNaN')"
|
||||
});
|
||||
assertThrowsError(
|
||||
() => {
|
||||
new isNaN();
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "[object NativeFunction] is not a constructor (evaluated from 'isNaN')",
|
||||
}
|
||||
);
|
||||
|
||||
console.log("PASS");
|
||||
} catch(e) {
|
||||
console.log("FAIL: " + e);
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
|
|
|
@ -1,112 +1,136 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
function func1(a, b = 1) {
|
||||
return a + b;
|
||||
function func1(a, b = 1) {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
const arrowFunc1 = (a, b = 1) => a + b;
|
||||
|
||||
assert(func1(4, 5) === 9);
|
||||
assert(func1(4) === 5);
|
||||
assert(func1(4, undefined) === 5);
|
||||
assert(Number.isNaN(func1()));
|
||||
|
||||
assert(arrowFunc1(4, 5) === 9);
|
||||
assert(arrowFunc1(4) === 5);
|
||||
assert(arrowFunc1(4, undefined) === 5);
|
||||
assert(Number.isNaN(arrowFunc1()));
|
||||
|
||||
function func2(a = 6) {
|
||||
return typeof a;
|
||||
}
|
||||
|
||||
const arrowFunc2 = (a = 6) => typeof a;
|
||||
|
||||
assert(func2() === "number");
|
||||
assert(func2(5) === "number");
|
||||
assert(func2(undefined) === "number");
|
||||
assert(func2(false) === "boolean");
|
||||
assert(func2(null) === "object");
|
||||
assert(func2({}) === "object");
|
||||
|
||||
assert(arrowFunc2() === "number");
|
||||
assert(arrowFunc2(5) === "number");
|
||||
assert(arrowFunc2(undefined) === "number");
|
||||
assert(arrowFunc2(false) === "boolean");
|
||||
assert(arrowFunc2(null) === "object");
|
||||
assert(arrowFunc2({}) === "object");
|
||||
|
||||
function func3(a = 5, b) {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
const arrowFunc3 = (a = 5, b) => a + b;
|
||||
|
||||
assert(func3(4, 5) === 9);
|
||||
assert(func3(undefined, 4) === 9);
|
||||
assert(Number.isNaN(func3()));
|
||||
|
||||
assert(arrowFunc3(4, 5) === 9);
|
||||
assert(arrowFunc3(undefined, 4) === 9);
|
||||
assert(Number.isNaN(arrowFunc3()));
|
||||
|
||||
function func4(a, b = a) {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
const arrowFunc4 = (a, b = a) => a + b;
|
||||
|
||||
assert(func4(4, 5) === 9);
|
||||
assert(func4(4) === 8);
|
||||
assert(func4("hf") === "hfhf");
|
||||
assert(func4(true) === 2);
|
||||
assert(Number.isNaN(func4()));
|
||||
|
||||
assert(arrowFunc4(4, 5) === 9);
|
||||
assert(arrowFunc4(4) === 8);
|
||||
assert(arrowFunc4("hf") === "hfhf");
|
||||
assert(arrowFunc4(true) === 2);
|
||||
assert(Number.isNaN(arrowFunc4()));
|
||||
|
||||
function func5(
|
||||
a = function () {
|
||||
return 5;
|
||||
}
|
||||
) {
|
||||
return a();
|
||||
}
|
||||
|
||||
const arrowFunc1 = (a, b = 1) => a + b;
|
||||
|
||||
assert(func1(4, 5) === 9);
|
||||
assert(func1(4) === 5);
|
||||
assert(func1(4, undefined) === 5);
|
||||
assert(Number.isNaN(func1()));
|
||||
|
||||
assert(arrowFunc1(4, 5) === 9);
|
||||
assert(arrowFunc1(4) === 5);
|
||||
assert(arrowFunc1(4, undefined) === 5);
|
||||
assert(Number.isNaN(arrowFunc1()));
|
||||
|
||||
function func2(a = 6) {
|
||||
return typeof a;
|
||||
const arrowFunc5 = (
|
||||
a = function () {
|
||||
return 5;
|
||||
}
|
||||
) => a();
|
||||
|
||||
const arrowFunc2 = (a = 6) => typeof a;
|
||||
assert(func5() === 5);
|
||||
assert(
|
||||
func5(function () {
|
||||
return 10;
|
||||
}) === 10
|
||||
);
|
||||
assert(func5(() => 10) === 10);
|
||||
assert(arrowFunc5() === 5);
|
||||
assert(
|
||||
arrowFunc5(function () {
|
||||
return 10;
|
||||
}) === 10
|
||||
);
|
||||
assert(arrowFunc5(() => 10) === 10);
|
||||
|
||||
assert(func2() === "number");
|
||||
assert(func2(5) === "number");
|
||||
assert(func2(undefined) === "number");
|
||||
assert(func2(false) === "boolean");
|
||||
assert(func2(null) === "object");
|
||||
assert(func2({}) === "object");
|
||||
function func6(a = () => 5) {
|
||||
return a();
|
||||
}
|
||||
|
||||
assert(arrowFunc2() === "number");
|
||||
assert(arrowFunc2(5) === "number");
|
||||
assert(arrowFunc2(undefined) === "number");
|
||||
assert(arrowFunc2(false) === "boolean");
|
||||
assert(arrowFunc2(null) === "object");
|
||||
assert(arrowFunc2({}) === "object");
|
||||
const arrowFunc6 = (a = () => 5) => a();
|
||||
|
||||
function func3(a = 5, b) {
|
||||
return a + b;
|
||||
}
|
||||
assert(func6() === 5);
|
||||
assert(
|
||||
func6(function () {
|
||||
return 10;
|
||||
}) === 10
|
||||
);
|
||||
assert(func6(() => 10) === 10);
|
||||
assert(arrowFunc6() === 5);
|
||||
assert(
|
||||
arrowFunc6(function () {
|
||||
return 10;
|
||||
}) === 10
|
||||
);
|
||||
assert(arrowFunc6(() => 10) === 10);
|
||||
|
||||
const arrowFunc3 = (a = 5, b) => a + b;
|
||||
function func7(a = { foo: "bar" }) {
|
||||
return a.foo;
|
||||
}
|
||||
|
||||
assert(func3(4, 5) === 9);
|
||||
assert(func3(undefined, 4) === 9);
|
||||
assert(Number.isNaN(func3()));
|
||||
const arrowFunc7 = (a = { foo: "bar" }) => a.foo;
|
||||
|
||||
assert(arrowFunc3(4, 5) === 9);
|
||||
assert(arrowFunc3(undefined, 4) === 9);
|
||||
assert(Number.isNaN(arrowFunc3()));
|
||||
assert(func7() === "bar");
|
||||
assert(func7({ foo: "baz" }) === "baz");
|
||||
assert(arrowFunc7() === "bar");
|
||||
assert(arrowFunc7({ foo: "baz" }) === "baz");
|
||||
|
||||
function func4(a, b = a) {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
const arrowFunc4 = (a, b = a) => a + b;
|
||||
|
||||
assert(func4(4, 5) === 9);
|
||||
assert(func4(4) === 8);
|
||||
assert(func4("hf") === "hfhf");
|
||||
assert(func4(true) === 2);
|
||||
assert(Number.isNaN(func4()));
|
||||
|
||||
assert(arrowFunc4(4, 5) === 9);
|
||||
assert(arrowFunc4(4) === 8);
|
||||
assert(arrowFunc4("hf") === "hfhf");
|
||||
assert(arrowFunc4(true) === 2);
|
||||
assert(Number.isNaN(arrowFunc4()));
|
||||
|
||||
function func5(a = function() { return 5; }) {
|
||||
return a();
|
||||
}
|
||||
|
||||
const arrowFunc5 = (a = function() { return 5; }) => a();
|
||||
|
||||
assert(func5() === 5);
|
||||
assert(func5(function() { return 10; }) === 10);
|
||||
assert(func5(() => 10) === 10);
|
||||
assert(arrowFunc5() === 5);
|
||||
assert(arrowFunc5(function() { return 10; }) === 10);
|
||||
assert(arrowFunc5(() => 10) === 10);
|
||||
|
||||
function func6(a = () => 5) {
|
||||
return a();
|
||||
}
|
||||
|
||||
const arrowFunc6 = (a = () => 5) => a();
|
||||
|
||||
assert(func6() === 5);
|
||||
assert(func6(function() { return 10; }) === 10);
|
||||
assert(func6(() => 10) === 10);
|
||||
assert(arrowFunc6() === 5);
|
||||
assert(arrowFunc6(function() { return 10; }) === 10);
|
||||
assert(arrowFunc6(() => 10) === 10);
|
||||
|
||||
function func7(a = { foo: "bar" }) {
|
||||
return a.foo;
|
||||
}
|
||||
|
||||
const arrowFunc7 = (a = { foo: "bar" }) => a.foo
|
||||
|
||||
assert(func7() === "bar");
|
||||
assert(func7({ foo: "baz" }) === "baz");
|
||||
assert(arrowFunc7() === "bar");
|
||||
assert(arrowFunc7({ foo: "baz" }) === "baz");
|
||||
|
||||
console.log("PASS");
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
|
|
|
@ -1,37 +1,37 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
var callHoisted = hoisted();
|
||||
function hoisted() {
|
||||
return true;
|
||||
}
|
||||
assert(hoisted() === true);
|
||||
assert(callHoisted === true);
|
||||
var callHoisted = hoisted();
|
||||
function hoisted() {
|
||||
return true;
|
||||
}
|
||||
assert(hoisted() === true);
|
||||
assert(callHoisted === true);
|
||||
|
||||
{
|
||||
var callScopedHoisted = scopedHoisted();
|
||||
function scopedHoisted() {
|
||||
return "foo";
|
||||
}
|
||||
assert(scopedHoisted() === "foo");
|
||||
assert(callScopedHoisted === "foo");
|
||||
{
|
||||
var callScopedHoisted = scopedHoisted();
|
||||
function scopedHoisted() {
|
||||
return "foo";
|
||||
}
|
||||
assert(scopedHoisted() === "foo");
|
||||
assert(callScopedHoisted === "foo");
|
||||
}
|
||||
assert(scopedHoisted() === "foo");
|
||||
assert(callScopedHoisted === "foo");
|
||||
|
||||
const test = () => {
|
||||
var iife = (function () {
|
||||
return declaredLater();
|
||||
})();
|
||||
function declaredLater() {
|
||||
return "yay";
|
||||
}
|
||||
return iife;
|
||||
};
|
||||
assert(typeof declaredLater === "undefined");
|
||||
assert(test() === "yay");
|
||||
const test = () => {
|
||||
var iife = (function () {
|
||||
return declaredLater();
|
||||
})();
|
||||
function declaredLater() {
|
||||
return "yay";
|
||||
}
|
||||
return iife;
|
||||
};
|
||||
assert(typeof declaredLater === "undefined");
|
||||
assert(test() === "yay");
|
||||
|
||||
console.log("PASS");
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
function foo() { }
|
||||
assert(foo.length === 0);
|
||||
assert((foo.length = 5) === 5);
|
||||
assert(foo.length === 0);
|
||||
function foo() {}
|
||||
assert(foo.length === 0);
|
||||
assert((foo.length = 5) === 5);
|
||||
assert(foo.length === 0);
|
||||
|
||||
function bar(a, b, c) {}
|
||||
assert(bar.length === 3);
|
||||
assert((bar.length = 5) === 5);
|
||||
assert(bar.length === 3);
|
||||
function bar(a, b, c) {}
|
||||
assert(bar.length === 3);
|
||||
assert((bar.length = 5) === 5);
|
||||
assert(bar.length === 3);
|
||||
|
||||
function baz(a, b = 1, c) {}
|
||||
assert(baz.length === 1);
|
||||
assert((baz.length = 5) === 5);
|
||||
assert(baz.length === 1);
|
||||
function baz(a, b = 1, c) {}
|
||||
assert(baz.length === 1);
|
||||
assert((baz.length = 5) === 5);
|
||||
assert(baz.length === 1);
|
||||
|
||||
function qux(a, b, ...c) {}
|
||||
assert(qux.length === 2);
|
||||
assert((qux.length = 5) === 5);
|
||||
assert(qux.length === 2);
|
||||
function qux(a, b, ...c) {}
|
||||
assert(qux.length === 2);
|
||||
assert((qux.length = 5) === 5);
|
||||
assert(qux.length === 2);
|
||||
|
||||
console.log("PASS");
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
load("test-common.js");
|
||||
|
||||
function foo(a, b) { return a + b; }
|
||||
function foo(a, b) {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
try {
|
||||
assert(isNaN(foo()) === true);
|
||||
assert(isNaN(foo(1)) === true);
|
||||
assert(foo(2, 3) === 5);
|
||||
assert(foo(2, 3, 4) === 5);
|
||||
console.log("PASS");
|
||||
assert(isNaN(foo()) === true);
|
||||
assert(isNaN(foo(1)) === true);
|
||||
assert(foo(2, 3) === 5);
|
||||
assert(foo(2, 3, 4) === 5);
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
|
|
|
@ -1,49 +1,45 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
assert((function () { }).name === "");
|
||||
assert(function () {}.name === "");
|
||||
|
||||
var foo = function () { }
|
||||
assert(foo.name === "foo");
|
||||
assert((foo.name = "bar") === "bar");
|
||||
assert(foo.name === "foo");
|
||||
var foo = function () {};
|
||||
assert(foo.name === "foo");
|
||||
assert((foo.name = "bar") === "bar");
|
||||
assert(foo.name === "foo");
|
||||
|
||||
var a, b;
|
||||
a = b = function () { }
|
||||
assert(a.name === "b");
|
||||
assert(b.name === "b");
|
||||
var a, b;
|
||||
a = b = function () {};
|
||||
assert(a.name === "b");
|
||||
assert(b.name === "b");
|
||||
|
||||
var arr = [
|
||||
function () { },
|
||||
function () { },
|
||||
function () { }
|
||||
];
|
||||
assert(arr[0].name === "arr");
|
||||
assert(arr[1].name === "arr");
|
||||
assert(arr[2].name === "arr");
|
||||
var arr = [function () {}, function () {}, function () {}];
|
||||
assert(arr[0].name === "arr");
|
||||
assert(arr[1].name === "arr");
|
||||
assert(arr[2].name === "arr");
|
||||
|
||||
var f;
|
||||
var o = { a: function () { } };
|
||||
assert(o.a.name === "a");
|
||||
f = o.a;
|
||||
assert(f.name === "a");
|
||||
assert(o.a.name === "a");
|
||||
o = { ...o, b: f };
|
||||
assert(o.a.name === "a");
|
||||
assert(o.b.name === "a");
|
||||
o.c = function () { };
|
||||
assert(o.c.name === "c");
|
||||
var f;
|
||||
var o = { a: function () {} };
|
||||
assert(o.a.name === "a");
|
||||
f = o.a;
|
||||
assert(f.name === "a");
|
||||
assert(o.a.name === "a");
|
||||
o = { ...o, b: f };
|
||||
assert(o.a.name === "a");
|
||||
assert(o.b.name === "a");
|
||||
o.c = function () {};
|
||||
assert(o.c.name === "c");
|
||||
|
||||
function bar() { }
|
||||
assert(bar.name === "bar");
|
||||
assert((bar.name = "baz") === "baz");
|
||||
assert(bar.name === "bar");
|
||||
function bar() {}
|
||||
assert(bar.name === "bar");
|
||||
assert((bar.name = "baz") === "baz");
|
||||
assert(bar.name === "bar");
|
||||
|
||||
assert(console.log.name === "log");
|
||||
assert((console.log.name = "warn") === "warn");
|
||||
assert(console.log.name === "log");
|
||||
assert(console.log.name === "log");
|
||||
assert((console.log.name = "warn") === "warn");
|
||||
assert(console.log.name === "log");
|
||||
|
||||
console.log("PASS");
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
|
|
|
@ -1,57 +1,57 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
function foo(...a) {
|
||||
assert(a instanceof Array);
|
||||
assert(a.length === 0);
|
||||
}
|
||||
foo();
|
||||
function foo(...a) {
|
||||
assert(a instanceof Array);
|
||||
assert(a.length === 0);
|
||||
}
|
||||
foo();
|
||||
|
||||
function foo1(...a) {
|
||||
assert(a instanceof Array);
|
||||
assert(a.length === 4);
|
||||
assert(a[0] === "foo");
|
||||
assert(a[1] === 123);
|
||||
assert(a[2] === undefined);
|
||||
assert(a[3].foo === "bar");
|
||||
}
|
||||
foo1("foo", 123, undefined, { foo: "bar" });
|
||||
function foo1(...a) {
|
||||
assert(a instanceof Array);
|
||||
assert(a.length === 4);
|
||||
assert(a[0] === "foo");
|
||||
assert(a[1] === 123);
|
||||
assert(a[2] === undefined);
|
||||
assert(a[3].foo === "bar");
|
||||
}
|
||||
foo1("foo", 123, undefined, { foo: "bar" });
|
||||
|
||||
function foo2(a, b, ...c) {
|
||||
assert(a === "foo");
|
||||
assert(b === 123);
|
||||
assert(c instanceof Array);
|
||||
assert(c.length === 0);
|
||||
}
|
||||
foo2("foo", 123);
|
||||
function foo2(a, b, ...c) {
|
||||
assert(a === "foo");
|
||||
assert(b === 123);
|
||||
assert(c instanceof Array);
|
||||
assert(c.length === 0);
|
||||
}
|
||||
foo2("foo", 123);
|
||||
|
||||
function foo3(a, b, ...c) {
|
||||
assert(a === "foo");
|
||||
assert(b === 123);
|
||||
assert(c instanceof Array);
|
||||
assert(c.length === 2);
|
||||
assert(c[0] === undefined);
|
||||
assert(c[1].foo === "bar");
|
||||
}
|
||||
foo3("foo", 123, undefined, { foo: "bar" });
|
||||
function foo3(a, b, ...c) {
|
||||
assert(a === "foo");
|
||||
assert(b === 123);
|
||||
assert(c instanceof Array);
|
||||
assert(c.length === 2);
|
||||
assert(c[0] === undefined);
|
||||
assert(c[1].foo === "bar");
|
||||
}
|
||||
foo3("foo", 123, undefined, { foo: "bar" });
|
||||
|
||||
var foo = (...a) => {
|
||||
assert(a instanceof Array);
|
||||
assert(a.length === 0);
|
||||
};
|
||||
foo();
|
||||
var foo = (...a) => {
|
||||
assert(a instanceof Array);
|
||||
assert(a.length === 0);
|
||||
};
|
||||
foo();
|
||||
|
||||
var foo = (a, b, ...c) => {
|
||||
assert(a === "foo");
|
||||
assert(b === 123);
|
||||
assert(c instanceof Array);
|
||||
assert(c.length === 2);
|
||||
assert(c[0] === undefined);
|
||||
assert(c[1].foo === "bar");
|
||||
};
|
||||
foo("foo", 123, undefined, { foo: "bar" });
|
||||
var foo = (a, b, ...c) => {
|
||||
assert(a === "foo");
|
||||
assert(b === 123);
|
||||
assert(c instanceof Array);
|
||||
assert(c.length === 2);
|
||||
assert(c[0] === undefined);
|
||||
assert(c[1].foo === "bar");
|
||||
};
|
||||
foo("foo", 123, undefined, { foo: "bar" });
|
||||
|
||||
console.log("PASS");
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
|
|
|
@ -1,27 +1,30 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
const sum = (a, b, c) => a + b + c;
|
||||
const a = [1, 2, 3];
|
||||
const sum = (a, b, c) => a + b + c;
|
||||
const a = [1, 2, 3];
|
||||
|
||||
assert(sum(...a) === 6);
|
||||
assert(sum(1, ...a) === 4);
|
||||
assert(sum(...a, 10) === 6);
|
||||
assert(sum(...a) === 6);
|
||||
assert(sum(1, ...a) === 4);
|
||||
assert(sum(...a, 10) === 6);
|
||||
|
||||
const foo = (a, b, c) => c;
|
||||
const foo = (a, b, c) => c;
|
||||
|
||||
const o = { bar: [1, 2, 3] };
|
||||
assert(foo(...o.bar) === 3);
|
||||
assert(foo(..."abc") === "c");
|
||||
const o = { bar: [1, 2, 3] };
|
||||
assert(foo(...o.bar) === 3);
|
||||
assert(foo(..."abc") === "c");
|
||||
|
||||
assertThrowsError(() => {
|
||||
[...1];
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "1 is not iterable",
|
||||
});
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[...1];
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "1 is not iterable",
|
||||
}
|
||||
);
|
||||
|
||||
console.log("PASS");
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
|
|
|
@ -1,52 +1,52 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
(function() {
|
||||
assert(!isStrictMode());
|
||||
})();
|
||||
(function () {
|
||||
assert(!isStrictMode());
|
||||
})();
|
||||
|
||||
(function() {
|
||||
'use strict';
|
||||
assert(isStrictMode());
|
||||
})();
|
||||
(function () {
|
||||
"use strict";
|
||||
assert(isStrictMode());
|
||||
})();
|
||||
|
||||
(function() {
|
||||
"use strict";
|
||||
assert(isStrictMode());
|
||||
})();
|
||||
(function () {
|
||||
"use strict";
|
||||
assert(isStrictMode());
|
||||
})();
|
||||
|
||||
(function() {
|
||||
`use strict`;
|
||||
assert(!isStrictMode());
|
||||
})();
|
||||
(function () {
|
||||
`use strict`;
|
||||
assert(!isStrictMode());
|
||||
})();
|
||||
|
||||
(function() {
|
||||
;'use strict';
|
||||
assert(!isStrictMode());
|
||||
})();
|
||||
(function () {
|
||||
("use strict");
|
||||
assert(!isStrictMode());
|
||||
})();
|
||||
|
||||
(function() {
|
||||
;"use strict";
|
||||
assert(!isStrictMode());
|
||||
})();
|
||||
(function () {
|
||||
("use strict");
|
||||
assert(!isStrictMode());
|
||||
})();
|
||||
|
||||
(function() {
|
||||
"use strict";
|
||||
(function() {
|
||||
assert(isStrictMode());
|
||||
})();
|
||||
(function () {
|
||||
"use strict";
|
||||
(function () {
|
||||
assert(isStrictMode());
|
||||
})();
|
||||
})();
|
||||
|
||||
(function() {
|
||||
assert(!isStrictMode());
|
||||
(function(){
|
||||
"use strict";
|
||||
assert(isStrictMode());
|
||||
})();
|
||||
assert(!isStrictMode());
|
||||
(function () {
|
||||
assert(!isStrictMode());
|
||||
(function () {
|
||||
"use strict";
|
||||
assert(isStrictMode());
|
||||
})();
|
||||
assert(!isStrictMode());
|
||||
})();
|
||||
|
||||
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