mirror of
https://github.com/RGBCube/serenity
synced 2025-05-25 19:25:07 +00:00
LibJS: Convert all remaining non-Array tests to the new system :)
This commit is contained in:
parent
918f4affd5
commit
15de2eda2b
72 changed files with 2394 additions and 1998 deletions
|
@ -1,57 +1,47 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
test("rest parameter with no arguments", () => {
|
||||
function foo(...a) {
|
||||
assert(a instanceof Array);
|
||||
assert(a.length === 0);
|
||||
expect(a).toBeInstanceOf(Array);
|
||||
expect(a).toHaveLength(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");
|
||||
test("rest parameter with arguments", () => {
|
||||
function foo(...a) {
|
||||
expect(a).toEqual(["foo", 123, undefined, { foo: "bar" }]);
|
||||
}
|
||||
foo1("foo", 123, undefined, { foo: "bar" });
|
||||
foo("foo", 123, undefined, { foo: "bar" });
|
||||
});
|
||||
|
||||
function foo2(a, b, ...c) {
|
||||
assert(a === "foo");
|
||||
assert(b === 123);
|
||||
assert(c instanceof Array);
|
||||
assert(c.length === 0);
|
||||
test("rest parameter after normal parameters with no arguments", () => {
|
||||
function foo(a, b, ...c) {
|
||||
expect(a).toBe("foo");
|
||||
expect(b).toBe(123);
|
||||
expect(c).toEqual([]);
|
||||
}
|
||||
foo2("foo", 123);
|
||||
foo("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");
|
||||
test("rest parameter after normal parameters with arguments", () => {
|
||||
function foo(a, b, ...c) {
|
||||
expect(a).toBe("foo");
|
||||
expect(b).toBe(123);
|
||||
expect(c).toEqual([undefined, { foo: "bar" }]);
|
||||
}
|
||||
foo3("foo", 123, undefined, { foo: "bar" });
|
||||
foo("foo", 123, undefined, { foo: "bar" });
|
||||
});
|
||||
|
||||
var foo = (...a) => {
|
||||
assert(a instanceof Array);
|
||||
assert(a.length === 0);
|
||||
test("basic arrow function rest parameters", () => {
|
||||
let foo = (...a) => {
|
||||
expect(a).toBeInstanceOf(Array);
|
||||
expect(a).toHaveLength(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 = (a, b, ...c) => {
|
||||
expect(a).toBe("foo");
|
||||
expect(b).toBe(123);
|
||||
expect(c).toEqual([undefined, { foo: "bar" }]);
|
||||
};
|
||||
foo("foo", 123, undefined, { foo: "bar" });
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue