mirror of
https://github.com/RGBCube/serenity
synced 2025-05-30 21:58:10 +00:00
LibJS: Convert Array tests to new testing framework
This commit is contained in:
parent
8ebdf685a6
commit
461d90d042
33 changed files with 1315 additions and 1382 deletions
|
@ -1,50 +1,59 @@
|
|||
load("test-common.js");
|
||||
test("length is 0", () => {
|
||||
expect(Array.of).toHaveLength(0);
|
||||
});
|
||||
|
||||
try {
|
||||
assert(Array.of.length === 0);
|
||||
|
||||
assert(typeof Array.of() === "object");
|
||||
|
||||
var a;
|
||||
|
||||
a = Array.of(5);
|
||||
assert(a.length === 1);
|
||||
assert(a[0] === 5);
|
||||
|
||||
a = Array.of("5");
|
||||
assert(a.length === 1);
|
||||
assert(a[0] === "5");
|
||||
|
||||
a = Array.of(Infinity);
|
||||
assert(a.length === 1);
|
||||
assert(a[0] === Infinity);
|
||||
|
||||
a = Array.of(1, 2, 3);
|
||||
assert(a.length === 3);
|
||||
assert(a[0] === 1);
|
||||
assert(a[1] === 2);
|
||||
assert(a[2] === 3);
|
||||
|
||||
a = Array.of([1, 2, 3]);
|
||||
assert(a.length === 1);
|
||||
assert(a[0][0] === 1);
|
||||
assert(a[0][1] === 2);
|
||||
assert(a[0][2] === 3);
|
||||
|
||||
let t = [1, 2, 3];
|
||||
Object.defineProperty(t, 3, {
|
||||
get() {
|
||||
return 4;
|
||||
},
|
||||
describe("normal behavior", () => {
|
||||
test("single numeric argument", () => {
|
||||
var a = Array.of(5);
|
||||
expect(a instanceof Array).toBeTrue();
|
||||
expect(a).toHaveLength(1);
|
||||
expect(a[0]).toBe(5);
|
||||
});
|
||||
a = Array.of(...t);
|
||||
assert(a.length === 4);
|
||||
assert(a[0] === 1);
|
||||
assert(a[1] === 2);
|
||||
assert(a[2] === 3);
|
||||
assert(a[3] === 4);
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
test("single non-numeric argument", () => {
|
||||
var a = Array.of("5");
|
||||
expect(a instanceof Array).toBeTrue();
|
||||
expect(a).toHaveLength(1);
|
||||
expect(a[0]).toBe("5");
|
||||
});
|
||||
|
||||
test("single infinite numeric argument", () => {
|
||||
var a = Array.of(Infinity);
|
||||
expect(a instanceof Array).toBeTrue();
|
||||
expect(a).toHaveLength(1);
|
||||
expect(a[0]).toBe(Infinity);
|
||||
});
|
||||
|
||||
test("multiple numeric arguments", () => {
|
||||
var a = Array.of(1, 2, 3);
|
||||
expect(a instanceof Array).toBeTrue();
|
||||
expect(a).toHaveLength(3);
|
||||
expect(a[0]).toBe(1);
|
||||
expect(a[1]).toBe(2);
|
||||
expect(a[2]).toBe(3);
|
||||
});
|
||||
|
||||
test("single array argument", () => {
|
||||
var a = Array.of([1, 2, 3]);
|
||||
expect(a instanceof Array).toBeTrue();
|
||||
expect(a).toHaveLength(1);
|
||||
expect(a[0][0]).toBe(1);
|
||||
expect(a[0][1]).toBe(2);
|
||||
expect(a[0][2]).toBe(3);
|
||||
});
|
||||
|
||||
test("getter property is included in returned array", () => {
|
||||
var t = [1, 2, 3];
|
||||
Object.defineProperty(t, 3, {
|
||||
get() {
|
||||
return 4;
|
||||
},
|
||||
});
|
||||
var a = Array.of(...t);
|
||||
expect(a).toHaveLength(4);
|
||||
expect(a[0]).toBe(1);
|
||||
expect(a[1]).toBe(2);
|
||||
expect(a[2]).toBe(3);
|
||||
expect(a[3]).toBe(4);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue