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

LibJS: Indent tests with 4 spaces instead of 2

This commit is contained in:
Matthew Olsson 2020-07-06 07:37:45 -07:00 committed by Andreas Kling
parent 15de2eda2b
commit 1ef573eb30
261 changed files with 8536 additions and 8497 deletions

View file

@ -1,55 +1,55 @@
let x;
test("basic functionality", () => {
x = 1;
expect((x = 2)).toBe(2);
expect(x).toBe(2);
x = 1;
expect((x = 2)).toBe(2);
expect(x).toBe(2);
x = 1;
expect((x += 2)).toBe(3);
expect(x).toBe(3);
x = 1;
expect((x += 2)).toBe(3);
expect(x).toBe(3);
x = 3;
expect((x -= 2)).toBe(1);
expect(x).toBe(1);
x = 3;
expect((x -= 2)).toBe(1);
expect(x).toBe(1);
x = 3;
expect((x *= 2)).toBe(6);
expect(x).toBe(6);
x = 3;
expect((x *= 2)).toBe(6);
expect(x).toBe(6);
x = 6;
expect((x /= 2)).toBe(3);
expect(x).toBe(3);
x = 6;
expect((x /= 2)).toBe(3);
expect(x).toBe(3);
x = 6;
expect((x %= 4)).toBe(2);
expect(x).toBe(2);
x = 6;
expect((x %= 4)).toBe(2);
expect(x).toBe(2);
x = 2;
expect((x **= 3)).toBe(8);
expect(x).toBe(8);
x = 2;
expect((x **= 3)).toBe(8);
expect(x).toBe(8);
x = 3;
expect((x &= 2)).toBe(2);
expect(x).toBe(2);
x = 3;
expect((x &= 2)).toBe(2);
expect(x).toBe(2);
x = 3;
expect((x |= 4)).toBe(7);
expect(x).toBe(7);
x = 3;
expect((x |= 4)).toBe(7);
expect(x).toBe(7);
x = 6;
expect((x ^= 2)).toBe(4);
expect(x).toBe(4);
x = 6;
expect((x ^= 2)).toBe(4);
expect(x).toBe(4);
x = 2;
expect((x <<= 2)).toBe(8);
expect(x).toBe(8);
x = 2;
expect((x <<= 2)).toBe(8);
expect(x).toBe(8);
x = 8;
expect((x >>= 2)).toBe(2);
expect(x).toBe(2);
x = 8;
expect((x >>= 2)).toBe(2);
expect(x).toBe(2);
x = -(2 ** 32 - 10);
expect((x >>>= 2)).toBe(2);
expect(x).toBe(2);
x = -(2 ** 32 - 10);
expect((x >>>= 2)).toBe(2);
expect(x).toBe(2);
});

View file

@ -1,60 +1,60 @@
test("basic numeric shifting", () => {
expect(0 << 0).toBe(0);
expect(0 << 1).toBe(0);
expect(0 << 2).toBe(0);
expect(0 << 3).toBe(0);
expect(0 << 4).toBe(0);
expect(0 << 5).toBe(0);
expect(0 << 0).toBe(0);
expect(0 << 1).toBe(0);
expect(0 << 2).toBe(0);
expect(0 << 3).toBe(0);
expect(0 << 4).toBe(0);
expect(0 << 5).toBe(0);
expect(1 << 0).toBe(1);
expect(1 << 1).toBe(2);
expect(1 << 2).toBe(4);
expect(1 << 3).toBe(8);
expect(1 << 4).toBe(16);
expect(1 << 5).toBe(32);
expect(1 << 0).toBe(1);
expect(1 << 1).toBe(2);
expect(1 << 2).toBe(4);
expect(1 << 3).toBe(8);
expect(1 << 4).toBe(16);
expect(1 << 5).toBe(32);
expect(2 << 0).toBe(2);
expect(2 << 1).toBe(4);
expect(2 << 2).toBe(8);
expect(2 << 3).toBe(16);
expect(2 << 4).toBe(32);
expect(2 << 5).toBe(64);
expect(2 << 0).toBe(2);
expect(2 << 1).toBe(4);
expect(2 << 2).toBe(8);
expect(2 << 3).toBe(16);
expect(2 << 4).toBe(32);
expect(2 << 5).toBe(64);
expect(3 << 0).toBe(3);
expect(3 << 1).toBe(6);
expect(3 << 2).toBe(12);
expect(3 << 3).toBe(24);
expect(3 << 4).toBe(48);
expect(3 << 5).toBe(96);
expect(3 << 0).toBe(3);
expect(3 << 1).toBe(6);
expect(3 << 2).toBe(12);
expect(3 << 3).toBe(24);
expect(3 << 4).toBe(48);
expect(3 << 5).toBe(96);
expect(4 << 0).toBe(4);
expect(4 << 1).toBe(8);
expect(4 << 2).toBe(16);
expect(4 << 3).toBe(32);
expect(4 << 4).toBe(64);
expect(4 << 5).toBe(128);
expect(4 << 0).toBe(4);
expect(4 << 1).toBe(8);
expect(4 << 2).toBe(16);
expect(4 << 3).toBe(32);
expect(4 << 4).toBe(64);
expect(4 << 5).toBe(128);
expect(5 << 0).toBe(5);
expect(5 << 1).toBe(10);
expect(5 << 2).toBe(20);
expect(5 << 3).toBe(40);
expect(5 << 4).toBe(80);
expect(5 << 5).toBe(160);
expect(5 << 0).toBe(5);
expect(5 << 1).toBe(10);
expect(5 << 2).toBe(20);
expect(5 << 3).toBe(40);
expect(5 << 4).toBe(80);
expect(5 << 5).toBe(160);
});
test("shifting with non-numeric values", () => {
let x = 3;
let y = 7;
let x = 3;
let y = 7;
expect("42" << 6).toBe(2688);
expect(x << y).toBe(384);
expect(x << [[[[12]]]]).toBe(12288);
expect(undefined << y).toBe(0);
expect("a" << "b").toBe(0);
expect(null << null).toBe(0);
expect(undefined << undefined).toBe(0);
expect(NaN << NaN).toBe(0);
expect(NaN << 6).toBe(0);
expect(Infinity << Infinity).toBe(0);
expect(-Infinity << Infinity).toBe(0);
expect("42" << 6).toBe(2688);
expect(x << y).toBe(384);
expect(x << [[[[12]]]]).toBe(12288);
expect(undefined << y).toBe(0);
expect("a" << "b").toBe(0);
expect(null << null).toBe(0);
expect(undefined << undefined).toBe(0);
expect(NaN << NaN).toBe(0);
expect(NaN << 6).toBe(0);
expect(Infinity << Infinity).toBe(0);
expect(-Infinity << Infinity).toBe(0);
});

View file

@ -1,60 +1,60 @@
test("basic numeric or", () => {
expect(0 | 0).toBe(0);
expect(0 | 1).toBe(1);
expect(0 | 2).toBe(2);
expect(0 | 3).toBe(3);
expect(0 | 4).toBe(4);
expect(0 | 5).toBe(5);
expect(0 | 0).toBe(0);
expect(0 | 1).toBe(1);
expect(0 | 2).toBe(2);
expect(0 | 3).toBe(3);
expect(0 | 4).toBe(4);
expect(0 | 5).toBe(5);
expect(1 | 0).toBe(1);
expect(1 | 1).toBe(1);
expect(1 | 2).toBe(3);
expect(1 | 3).toBe(3);
expect(1 | 4).toBe(5);
expect(1 | 5).toBe(5);
expect(1 | 0).toBe(1);
expect(1 | 1).toBe(1);
expect(1 | 2).toBe(3);
expect(1 | 3).toBe(3);
expect(1 | 4).toBe(5);
expect(1 | 5).toBe(5);
expect(2 | 0).toBe(2);
expect(2 | 1).toBe(3);
expect(2 | 2).toBe(2);
expect(2 | 3).toBe(3);
expect(2 | 4).toBe(6);
expect(2 | 5).toBe(7);
expect(2 | 0).toBe(2);
expect(2 | 1).toBe(3);
expect(2 | 2).toBe(2);
expect(2 | 3).toBe(3);
expect(2 | 4).toBe(6);
expect(2 | 5).toBe(7);
expect(3 | 0).toBe(3);
expect(3 | 1).toBe(3);
expect(3 | 2).toBe(3);
expect(3 | 3).toBe(3);
expect(3 | 4).toBe(7);
expect(3 | 5).toBe(7);
expect(3 | 0).toBe(3);
expect(3 | 1).toBe(3);
expect(3 | 2).toBe(3);
expect(3 | 3).toBe(3);
expect(3 | 4).toBe(7);
expect(3 | 5).toBe(7);
expect(4 | 0).toBe(4);
expect(4 | 1).toBe(5);
expect(4 | 2).toBe(6);
expect(4 | 3).toBe(7);
expect(4 | 4).toBe(4);
expect(4 | 5).toBe(5);
expect(4 | 0).toBe(4);
expect(4 | 1).toBe(5);
expect(4 | 2).toBe(6);
expect(4 | 3).toBe(7);
expect(4 | 4).toBe(4);
expect(4 | 5).toBe(5);
expect(5 | 0).toBe(5);
expect(5 | 1).toBe(5);
expect(5 | 2).toBe(7);
expect(5 | 3).toBe(7);
expect(5 | 4).toBe(5);
expect(5 | 5).toBe(5);
expect(5 | 0).toBe(5);
expect(5 | 1).toBe(5);
expect(5 | 2).toBe(7);
expect(5 | 3).toBe(7);
expect(5 | 4).toBe(5);
expect(5 | 5).toBe(5);
});
test("or with non-numeric values", () => {
let x = 3;
let y = 7;
let x = 3;
let y = 7;
expect("42" | 6).toBe(46);
expect(x | y).toBe(7);
expect(x | [[[[12]]]]).toBe(15);
expect(undefined | y).toBe(7);
expect("a" | "b").toBe(0);
expect(null | null).toBe(0);
expect(undefined | undefined).toBe(0);
expect(NaN | NaN).toBe(0);
expect(NaN | 6).toBe(6);
expect(Infinity | Infinity).toBe(0);
expect(-Infinity | Infinity).toBe(0);
expect("42" | 6).toBe(46);
expect(x | y).toBe(7);
expect(x | [[[[12]]]]).toBe(15);
expect(undefined | y).toBe(7);
expect("a" | "b").toBe(0);
expect(null | null).toBe(0);
expect(undefined | undefined).toBe(0);
expect(NaN | NaN).toBe(0);
expect(NaN | 6).toBe(6);
expect(Infinity | Infinity).toBe(0);
expect(-Infinity | Infinity).toBe(0);
});

View file

@ -1,62 +1,62 @@
test("basic numeric shifting", () => {
expect(0 >> 0).toBe(0);
expect(0 >> 1).toBe(0);
expect(0 >> 2).toBe(0);
expect(0 >> 3).toBe(0);
expect(0 >> 4).toBe(0);
expect(0 >> 5).toBe(0);
expect(0 >> 0).toBe(0);
expect(0 >> 1).toBe(0);
expect(0 >> 2).toBe(0);
expect(0 >> 3).toBe(0);
expect(0 >> 4).toBe(0);
expect(0 >> 5).toBe(0);
expect(1 >> 0).toBe(1);
expect(1 >> 1).toBe(0);
expect(1 >> 2).toBe(0);
expect(1 >> 3).toBe(0);
expect(1 >> 4).toBe(0);
expect(1 >> 5).toBe(0);
expect(1 >> 0).toBe(1);
expect(1 >> 1).toBe(0);
expect(1 >> 2).toBe(0);
expect(1 >> 3).toBe(0);
expect(1 >> 4).toBe(0);
expect(1 >> 5).toBe(0);
expect(5 >> 0).toBe(5);
expect(5 >> 1).toBe(2);
expect(5 >> 2).toBe(1);
expect(5 >> 3).toBe(0);
expect(5 >> 4).toBe(0);
expect(5 >> 5).toBe(0);
expect(5 >> 0).toBe(5);
expect(5 >> 1).toBe(2);
expect(5 >> 2).toBe(1);
expect(5 >> 3).toBe(0);
expect(5 >> 4).toBe(0);
expect(5 >> 5).toBe(0);
expect(42 >> 0).toBe(42);
expect(42 >> 1).toBe(21);
expect(42 >> 2).toBe(10);
expect(42 >> 3).toBe(5);
expect(42 >> 4).toBe(2);
expect(42 >> 5).toBe(1);
expect(42 >> 0).toBe(42);
expect(42 >> 1).toBe(21);
expect(42 >> 2).toBe(10);
expect(42 >> 3).toBe(5);
expect(42 >> 4).toBe(2);
expect(42 >> 5).toBe(1);
});
test("numeric shifting with negative lhs values", () => {
expect(-1 >> 0).toBe(-1);
expect(-1 >> 1).toBe(-1);
expect(-1 >> 2).toBe(-1);
expect(-1 >> 3).toBe(-1);
expect(-1 >> 4).toBe(-1);
expect(-1 >> 5).toBe(-1);
expect(-1 >> 0).toBe(-1);
expect(-1 >> 1).toBe(-1);
expect(-1 >> 2).toBe(-1);
expect(-1 >> 3).toBe(-1);
expect(-1 >> 4).toBe(-1);
expect(-1 >> 5).toBe(-1);
expect(-5 >> 0).toBe(-5);
expect(-5 >> 1).toBe(-3);
expect(-5 >> 2).toBe(-2);
expect(-5 >> 3).toBe(-1);
expect(-5 >> 4).toBe(-1);
expect(-5 >> 5).toBe(-1);
expect(-5 >> 0).toBe(-5);
expect(-5 >> 1).toBe(-3);
expect(-5 >> 2).toBe(-2);
expect(-5 >> 3).toBe(-1);
expect(-5 >> 4).toBe(-1);
expect(-5 >> 5).toBe(-1);
});
test("shifting with non-numeric values", () => {
let x = 67;
let y = 4;
let x = 67;
let y = 4;
expect("42" >> 3).toBe(5);
expect(x >> y).toBe(4);
expect(x >> [[[[5]]]]).toBe(2);
expect(undefined >> y).toBe(0);
expect("a" >> "b").toBe(0);
expect(null >> null).toBe(0);
expect(undefined >> undefined).toBe(0);
expect(NaN >> NaN).toBe(0);
expect(6 >> NaN).toBe(6);
expect(Infinity >> Infinity).toBe(0);
expect(-Infinity >> Infinity).toBe(0);
expect("42" >> 3).toBe(5);
expect(x >> y).toBe(4);
expect(x >> [[[[5]]]]).toBe(2);
expect(undefined >> y).toBe(0);
expect("a" >> "b").toBe(0);
expect(null >> null).toBe(0);
expect(undefined >> undefined).toBe(0);
expect(NaN >> NaN).toBe(0);
expect(6 >> NaN).toBe(6);
expect(Infinity >> Infinity).toBe(0);
expect(-Infinity >> Infinity).toBe(0);
});

View file

@ -1,62 +1,62 @@
test("basic numeric shifting", () => {
expect(0 >>> 0).toBe(0);
expect(0 >>> 1).toBe(0);
expect(0 >>> 2).toBe(0);
expect(0 >>> 3).toBe(0);
expect(0 >>> 4).toBe(0);
expect(0 >>> 5).toBe(0);
expect(0 >>> 0).toBe(0);
expect(0 >>> 1).toBe(0);
expect(0 >>> 2).toBe(0);
expect(0 >>> 3).toBe(0);
expect(0 >>> 4).toBe(0);
expect(0 >>> 5).toBe(0);
expect(1 >>> 0).toBe(1);
expect(1 >>> 1).toBe(0);
expect(1 >>> 2).toBe(0);
expect(1 >>> 3).toBe(0);
expect(1 >>> 4).toBe(0);
expect(1 >>> 5).toBe(0);
expect(1 >>> 0).toBe(1);
expect(1 >>> 1).toBe(0);
expect(1 >>> 2).toBe(0);
expect(1 >>> 3).toBe(0);
expect(1 >>> 4).toBe(0);
expect(1 >>> 5).toBe(0);
expect(5 >>> 0).toBe(5);
expect(5 >>> 1).toBe(2);
expect(5 >>> 2).toBe(1);
expect(5 >>> 3).toBe(0);
expect(5 >>> 4).toBe(0);
expect(5 >>> 5).toBe(0);
expect(5 >>> 0).toBe(5);
expect(5 >>> 1).toBe(2);
expect(5 >>> 2).toBe(1);
expect(5 >>> 3).toBe(0);
expect(5 >>> 4).toBe(0);
expect(5 >>> 5).toBe(0);
expect(42 >>> 0).toBe(42);
expect(42 >>> 1).toBe(21);
expect(42 >>> 2).toBe(10);
expect(42 >>> 3).toBe(5);
expect(42 >>> 4).toBe(2);
expect(42 >>> 5).toBe(1);
expect(42 >>> 0).toBe(42);
expect(42 >>> 1).toBe(21);
expect(42 >>> 2).toBe(10);
expect(42 >>> 3).toBe(5);
expect(42 >>> 4).toBe(2);
expect(42 >>> 5).toBe(1);
});
test("numeric shifting with negative lhs values", () => {
expect(-1 >>> 0).toBe(4294967295);
expect(-1 >>> 1).toBe(2147483647);
expect(-1 >>> 2).toBe(1073741823);
expect(-1 >>> 3).toBe(536870911);
expect(-1 >>> 4).toBe(268435455);
expect(-1 >>> 5).toBe(134217727);
expect(-1 >>> 0).toBe(4294967295);
expect(-1 >>> 1).toBe(2147483647);
expect(-1 >>> 2).toBe(1073741823);
expect(-1 >>> 3).toBe(536870911);
expect(-1 >>> 4).toBe(268435455);
expect(-1 >>> 5).toBe(134217727);
expect(-5 >>> 0).toBe(4294967291);
expect(-5 >>> 1).toBe(2147483645);
expect(-5 >>> 2).toBe(1073741822);
expect(-5 >>> 3).toBe(536870911);
expect(-5 >>> 4).toBe(268435455);
expect(-5 >>> 5).toBe(134217727);
expect(-5 >>> 0).toBe(4294967291);
expect(-5 >>> 1).toBe(2147483645);
expect(-5 >>> 2).toBe(1073741822);
expect(-5 >>> 3).toBe(536870911);
expect(-5 >>> 4).toBe(268435455);
expect(-5 >>> 5).toBe(134217727);
});
test("shifting with non-numeric values", () => {
let x = -67;
let y = 4;
let x = -67;
let y = 4;
expect("-42" >>> 3).toBe(536870906);
expect(x >>> y).toBe(268435451);
expect(x >>> [[[[5]]]]).toBe(134217725);
expect(undefined >>> y).toBe(0);
expect("a" >>> "b").toBe(0);
expect(null >>> null).toBe(0);
expect(undefined >>> undefined).toBe(0);
expect(NaN >>> NaN).toBe(0);
expect(6 >>> NaN).toBe(6);
expect(Infinity >>> Infinity).toBe(0);
expect(-Infinity >>> Infinity).toBe(0);
expect("-42" >>> 3).toBe(536870906);
expect(x >>> y).toBe(268435451);
expect(x >>> [[[[5]]]]).toBe(134217725);
expect(undefined >>> y).toBe(0);
expect("a" >>> "b").toBe(0);
expect(null >>> null).toBe(0);
expect(undefined >>> undefined).toBe(0);
expect(NaN >>> NaN).toBe(0);
expect(6 >>> NaN).toBe(6);
expect(Infinity >>> Infinity).toBe(0);
expect(-Infinity >>> Infinity).toBe(0);
});

File diff suppressed because it is too large Load diff

View file

@ -1,24 +1,24 @@
test("inside parenthesis", () => {
expect((1, 2, 3)).toBe(3);
expect((1, 2 + 3, 4)).toBe(4);
expect((1, 2, 3)).toBe(3);
expect((1, 2 + 3, 4)).toBe(4);
});
test("with post-increment operator", () => {
let foo = 0;
foo = (foo++, foo);
expect(foo).toBe(1);
let foo = 0;
foo = (foo++, foo);
expect(foo).toBe(1);
});
test("with assignment operator", () => {
var a, b, c;
expect(((a = b = 3), (c = 4))).toBe(4);
expect(a).toBe(3);
expect(b).toBe(3);
expect(c).toBe(4);
var a, b, c;
expect(((a = b = 3), (c = 4))).toBe(4);
expect(a).toBe(3);
expect(b).toBe(3);
expect(c).toBe(4);
var x, y, z;
expect((x = ((y = 5), (z = 6)))).toBe(6);
expect(x).toBe(6);
expect(y).toBe(5);
expect(z).toBe(6);
var x, y, z;
expect((x = ((y = 5), (z = 6)))).toBe(6);
expect(x).toBe(6);
expect(y).toBe(5);
expect(z).toBe(6);
});

View file

@ -1,58 +1,58 @@
test("deleting object properties", () => {
const o = {};
o.x = 1;
o.y = 2;
o.z = 3;
expect(Object.getOwnPropertyNames(o)).toHaveLength(3);
const o = {};
o.x = 1;
o.y = 2;
o.z = 3;
expect(Object.getOwnPropertyNames(o)).toHaveLength(3);
expect(delete o.x).toBeTrue();
expect(o.hasOwnProperty("x")).toBeFalse();
expect(o.hasOwnProperty("y")).toBeTrue();
expect(o.hasOwnProperty("z")).toBeTrue();
expect(Object.getOwnPropertyNames(o)).toHaveLength(2);
expect(delete o.x).toBeTrue();
expect(o.hasOwnProperty("x")).toBeFalse();
expect(o.hasOwnProperty("y")).toBeTrue();
expect(o.hasOwnProperty("z")).toBeTrue();
expect(Object.getOwnPropertyNames(o)).toHaveLength(2);
expect(delete o.y).toBeTrue();
expect(o.hasOwnProperty("x")).toBeFalse();
expect(o.hasOwnProperty("y")).toBeFalse();
expect(o.hasOwnProperty("z")).toBeTrue();
expect(Object.getOwnPropertyNames(o)).toHaveLength(1);
expect(delete o.y).toBeTrue();
expect(o.hasOwnProperty("x")).toBeFalse();
expect(o.hasOwnProperty("y")).toBeFalse();
expect(o.hasOwnProperty("z")).toBeTrue();
expect(Object.getOwnPropertyNames(o)).toHaveLength(1);
expect(delete o.z).toBeTrue();
expect(o.hasOwnProperty("x")).toBeFalse();
expect(o.hasOwnProperty("y")).toBeFalse();
expect(o.hasOwnProperty("z")).toBeFalse();
expect(Object.getOwnPropertyNames(o)).toHaveLength(0);
expect(delete o.z).toBeTrue();
expect(o.hasOwnProperty("x")).toBeFalse();
expect(o.hasOwnProperty("y")).toBeFalse();
expect(o.hasOwnProperty("z")).toBeFalse();
expect(Object.getOwnPropertyNames(o)).toHaveLength(0);
});
test("deleting array indices", () => {
const a = [3, 5, 7];
const a = [3, 5, 7];
expect(Object.getOwnPropertyNames(a)).toHaveLength(4);
expect(Object.getOwnPropertyNames(a)).toHaveLength(4);
expect(delete a[0]).toBeTrue();
expect(a.hasOwnProperty(0)).toBeFalse();
expect(a.hasOwnProperty(1)).toBeTrue();
expect(a.hasOwnProperty(2)).toBeTrue();
expect(Object.getOwnPropertyNames(a)).toHaveLength(3);
expect(delete a[0]).toBeTrue();
expect(a.hasOwnProperty(0)).toBeFalse();
expect(a.hasOwnProperty(1)).toBeTrue();
expect(a.hasOwnProperty(2)).toBeTrue();
expect(Object.getOwnPropertyNames(a)).toHaveLength(3);
expect(delete a[1]).toBeTrue();
expect(a.hasOwnProperty(0)).toBeFalse();
expect(a.hasOwnProperty(1)).toBeFalse();
expect(a.hasOwnProperty(2)).toBeTrue();
expect(Object.getOwnPropertyNames(a)).toHaveLength(2);
expect(delete a[1]).toBeTrue();
expect(a.hasOwnProperty(0)).toBeFalse();
expect(a.hasOwnProperty(1)).toBeFalse();
expect(a.hasOwnProperty(2)).toBeTrue();
expect(Object.getOwnPropertyNames(a)).toHaveLength(2);
expect(delete a[2]).toBeTrue();
expect(a.hasOwnProperty(0)).toBeFalse();
expect(a.hasOwnProperty(1)).toBeFalse();
expect(a.hasOwnProperty(2)).toBeFalse();
expect(Object.getOwnPropertyNames(a)).toHaveLength(1);
expect(delete a[2]).toBeTrue();
expect(a.hasOwnProperty(0)).toBeFalse();
expect(a.hasOwnProperty(1)).toBeFalse();
expect(a.hasOwnProperty(2)).toBeFalse();
expect(Object.getOwnPropertyNames(a)).toHaveLength(1);
});
test("deleting non-configurable property", () => {
const q = {};
Object.defineProperty(q, "foo", { value: 1, writable: false, enumerable: false });
expect(q.foo).toBe(1);
const q = {};
Object.defineProperty(q, "foo", { value: 1, writable: false, enumerable: false });
expect(q.foo).toBe(1);
expect(delete q.foo).toBeFalse();
expect(q.hasOwnProperty("foo")).toBeTrue();
expect(delete q.foo).toBeFalse();
expect(q.hasOwnProperty("foo")).toBeTrue();
});

View file

@ -1,9 +1,9 @@
a = 1;
test("basic functionality", () => {
expect(delete a).toBeTrue();
expect(delete a).toBeTrue();
expect(() => {
a;
}).toThrowWithMessage(ReferenceError, "'a' is not defined");
expect(() => {
a;
}).toThrowWithMessage(ReferenceError, "'a' is not defined");
});

View file

@ -1,8 +1,8 @@
a = 1;
test("basic functionality", () => {
expect(delete globalThis.a).toBeTrue();
expect(() => {
a = 2;
}).not.toThrow();
expect(delete globalThis.a).toBeTrue();
expect(() => {
a = 2;
}).not.toThrow();
});

View file

@ -1,32 +1,32 @@
test("in operator with objects", () => {
const o = { foo: "bar", bar: undefined };
expect("" in o).toBeFalse();
expect("foo" in o).toBeTrue();
expect("bar" in o).toBeTrue();
expect("baz" in o).toBeFalse();
expect("toString" in o).toBeTrue();
const o = { foo: "bar", bar: undefined };
expect("" in o).toBeFalse();
expect("foo" in o).toBeTrue();
expect("bar" in o).toBeTrue();
expect("baz" in o).toBeFalse();
expect("toString" in o).toBeTrue();
});
test("in operator with arrays", () => {
const a = ["hello", "friends"];
expect(0 in a).toBeTrue();
expect(1 in a).toBeTrue();
expect(2 in a).toBeFalse();
expect("0" in a).toBeTrue();
expect("hello" in a).toBeFalse();
expect("friends" in a).toBeFalse();
expect("length" in a).toBeTrue();
const a = ["hello", "friends"];
expect(0 in a).toBeTrue();
expect(1 in a).toBeTrue();
expect(2 in a).toBeFalse();
expect("0" in a).toBeTrue();
expect("hello" in a).toBeFalse();
expect("friends" in a).toBeFalse();
expect("length" in a).toBeTrue();
});
test("in operator with string object", () => {
const s = new String("foo");
expect("length" in s).toBeTrue();
const s = new String("foo");
expect("length" in s).toBeTrue();
});
test("error when used with primitives", () => {
["foo", 123, null, undefined].forEach(value => {
expect(() => {
"prop" in value;
}).toThrowWithMessage(TypeError, "'in' operator must be used on an object");
});
["foo", 123, null, undefined].forEach(value => {
expect(() => {
"prop" in value;
}).toThrowWithMessage(TypeError, "'in' operator must be used on an object");
});
});

View file

@ -1,24 +1,24 @@
test("basic functionality", () => {
function Foo() {
this.x = 123;
}
function Foo() {
this.x = 123;
}
const foo = new Foo();
expect(foo instanceof Foo).toBeTrue();
const foo = new Foo();
expect(foo instanceof Foo).toBeTrue();
});
test("derived ES5 classes", () => {
function Base() {
this.is_base = true;
}
function Base() {
this.is_base = true;
}
function Derived() {
this.is_derived = true;
}
function Derived() {
this.is_derived = true;
}
Object.setPrototypeOf(Derived.prototype, Base.prototype);
Object.setPrototypeOf(Derived.prototype, Base.prototype);
const d = new Derived();
expect(d instanceof Derived).toBeTrue();
expect(d instanceof Base).toBeTrue();
const d = new Derived();
expect(d instanceof Derived).toBeTrue();
expect(d instanceof Base).toBeTrue();
});

View file

@ -1,50 +1,50 @@
test("booleans", () => {
expect(true && true).toBeTrue();
expect(false && false).toBeFalse();
expect(true && false).toBeFalse();
expect(false && true).toBeFalse();
expect(true && true).toBeTrue();
expect(false && false).toBeFalse();
expect(true && false).toBeFalse();
expect(false && true).toBeFalse();
});
test("strings", () => {
expect("" && "").toBe("");
expect("" && false).toBe("");
expect("" && true).toBe("");
expect(false && "").toBeFalse();
expect(true && "").toBe("");
expect("foo" && "bar").toBe("bar");
expect("foo" && false).toBeFalse();
expect("foo" && true).toBeTrue();
expect(false && "bar").toBeFalse();
expect(true && "bar").toBe("bar");
expect("" && "").toBe("");
expect("" && false).toBe("");
expect("" && true).toBe("");
expect(false && "").toBeFalse();
expect(true && "").toBe("");
expect("foo" && "bar").toBe("bar");
expect("foo" && false).toBeFalse();
expect("foo" && true).toBeTrue();
expect(false && "bar").toBeFalse();
expect(true && "bar").toBe("bar");
});
test("numbers", () => {
expect(false && 1 === 2).toBeFalse();
expect(true && 1 === 2).toBeFalse();
expect(0 && false).toBe(0);
expect(0 && true).toBe(0);
expect(42 && false).toBeFalse();
expect(42 && true).toBeTrue();
expect(false && 0).toBeFalse();
expect(true && 0).toBe(0);
expect(false && 42).toBeFalse();
expect(true && 42).toBe(42);
expect(false && 1 === 2).toBeFalse();
expect(true && 1 === 2).toBeFalse();
expect(0 && false).toBe(0);
expect(0 && true).toBe(0);
expect(42 && false).toBeFalse();
expect(42 && true).toBeTrue();
expect(false && 0).toBeFalse();
expect(true && 0).toBe(0);
expect(false && 42).toBeFalse();
expect(true && 42).toBe(42);
});
test("objects", () => {
expect([] && false).toBeFalse();
expect([] && true).toBeTrue();
expect(false && []).toBeFalse();
expect(true && []).toHaveLength(0);
expect([] && false).toBeFalse();
expect([] && true).toBeTrue();
expect(false && []).toBeFalse();
expect(true && []).toHaveLength(0);
});
test("null & undefined", () => {
expect(null && false).toBeNull();
expect(null && true).toBeNull();
expect(false && null).toBeFalse();
expect(true && null).toBeNull();
expect(undefined && false).toBeUndefined();
expect(undefined && true).toBeUndefined();
expect(false && undefined).toBeFalse();
expect(true && undefined).toBeUndefined();
expect(null && false).toBeNull();
expect(null && true).toBeNull();
expect(false && null).toBeFalse();
expect(true && null).toBeNull();
expect(undefined && false).toBeUndefined();
expect(undefined && true).toBeUndefined();
expect(false && undefined).toBeFalse();
expect(true && undefined).toBeUndefined();
});

View file

@ -1,13 +1,13 @@
test("basic functionality", () => {
let foo = 1;
false && (foo = 2);
expect(foo).toBe(1);
let foo = 1;
false && (foo = 2);
expect(foo).toBe(1);
foo = 1;
true || (foo = 2);
expect(foo).toBe(1);
foo = 1;
true || (foo = 2);
expect(foo).toBe(1);
foo = 1;
true ?? (foo = 2);
expect(foo).toBe(1);
foo = 1;
true ?? (foo = 2);
expect(foo).toBe(1);
});

View file

@ -1,50 +1,50 @@
test("booleans", () => {
expect(true ?? true).toBeTrue();
expect(false ?? false).toBeFalse();
expect(true ?? false).toBeTrue();
expect(false ?? true).toBeFalse();
expect(true ?? true).toBeTrue();
expect(false ?? false).toBeFalse();
expect(true ?? false).toBeTrue();
expect(false ?? true).toBeFalse();
});
test("strings", () => {
expect("" ?? "").toBe("");
expect("" ?? false).toBe("");
expect("" ?? true).toBe("");
expect(false ?? "").toBeFalse();
expect(true ?? "").toBeTrue();
expect("foo" ?? "bar").toBe("foo");
expect("foo" ?? false).toBe("foo");
expect("foo" ?? true).toBe("foo");
expect(false ?? "bar").toBeFalse();
expect(true ?? "bar").toBeTrue();
expect("" ?? "").toBe("");
expect("" ?? false).toBe("");
expect("" ?? true).toBe("");
expect(false ?? "").toBeFalse();
expect(true ?? "").toBeTrue();
expect("foo" ?? "bar").toBe("foo");
expect("foo" ?? false).toBe("foo");
expect("foo" ?? true).toBe("foo");
expect(false ?? "bar").toBeFalse();
expect(true ?? "bar").toBeTrue();
});
test("numbers", () => {
expect(false ?? 1 === 2).toBeFalse();
expect(true ?? 1 === 2).toBeTrue();
expect(0 ?? false).toBe(0);
expect(0 ?? true).toBe(0);
expect(42 ?? false).toBe(42);
expect(42 ?? true).toBe(42);
expect(false ?? 0).toBeFalse();
expect(true ?? 0).toBeTrue();
expect(false ?? 42).toBeFalse();
expect(true ?? 42).toBeTrue();
expect(false ?? 1 === 2).toBeFalse();
expect(true ?? 1 === 2).toBeTrue();
expect(0 ?? false).toBe(0);
expect(0 ?? true).toBe(0);
expect(42 ?? false).toBe(42);
expect(42 ?? true).toBe(42);
expect(false ?? 0).toBeFalse();
expect(true ?? 0).toBeTrue();
expect(false ?? 42).toBeFalse();
expect(true ?? 42).toBeTrue();
});
test("objects", () => {
expect([] ?? false).toHaveLength(0);
expect([] ?? true).toHaveLength(0);
expect(false ?? []).toBeFalse();
expect(true ?? []).toBeTrue();
expect([] ?? false).toHaveLength(0);
expect([] ?? true).toHaveLength(0);
expect(false ?? []).toBeFalse();
expect(true ?? []).toBeTrue();
});
test("null & undefined", () => {
expect(null ?? false).toBeFalse();
expect(null ?? true).toBeTrue();
expect(false ?? null).toBeFalse();
expect(true ?? null).toBeTrue();
expect(undefined ?? false).toBeFalse();
expect(undefined ?? true).toBeTrue();
expect(false ?? undefined).toBeFalse();
expect(true ?? undefined).toBeTrue();
expect(null ?? false).toBeFalse();
expect(null ?? true).toBeTrue();
expect(false ?? null).toBeFalse();
expect(true ?? null).toBeTrue();
expect(undefined ?? false).toBeFalse();
expect(undefined ?? true).toBeTrue();
expect(false ?? undefined).toBeFalse();
expect(true ?? undefined).toBeTrue();
});

View file

@ -1,50 +1,50 @@
test("booleans", () => {
expect(true || true).toBeTrue();
expect(false || false).toBeFalse();
expect(true || false).toBeTrue();
expect(false || true).toBeTrue();
expect(true || true).toBeTrue();
expect(false || false).toBeFalse();
expect(true || false).toBeTrue();
expect(false || true).toBeTrue();
});
test("strings", () => {
expect("" || "").toBe("");
expect("" || false).toBeFalse();
expect("" || true).toBeTrue();
expect(false || "").toBe("");
expect(true || "").toBeTrue();
expect("foo" || "bar").toBe("foo");
expect("foo" || false).toBe("foo");
expect("foo" || true).toBe("foo");
expect(false || "bar").toBe("bar");
expect(true || "bar").toBeTrue();
expect("" || "").toBe("");
expect("" || false).toBeFalse();
expect("" || true).toBeTrue();
expect(false || "").toBe("");
expect(true || "").toBeTrue();
expect("foo" || "bar").toBe("foo");
expect("foo" || false).toBe("foo");
expect("foo" || true).toBe("foo");
expect(false || "bar").toBe("bar");
expect(true || "bar").toBeTrue();
});
test("numbers", () => {
expect(false || 1 === 2).toBeFalse();
expect(true || 1 === 2).toBeTrue();
expect(0 || false).toBeFalse();
expect(0 || true).toBeTrue();
expect(42 || false).toBe(42);
expect(42 || true).toBe(42);
expect(false || 0).toBe(0);
expect(true || 0).toBeTrue();
expect(false || 42).toBe(42);
expect(true || 42).toBeTrue();
expect(false || 1 === 2).toBeFalse();
expect(true || 1 === 2).toBeTrue();
expect(0 || false).toBeFalse();
expect(0 || true).toBeTrue();
expect(42 || false).toBe(42);
expect(42 || true).toBe(42);
expect(false || 0).toBe(0);
expect(true || 0).toBeTrue();
expect(false || 42).toBe(42);
expect(true || 42).toBeTrue();
});
test("objects", () => {
expect([] || false).toHaveLength(0);
expect([] || true).toHaveLength(0);
expect(false || []).toHaveLength(0);
expect(true || []).toBeTrue();
expect([] || false).toHaveLength(0);
expect([] || true).toHaveLength(0);
expect(false || []).toHaveLength(0);
expect(true || []).toBeTrue();
});
test("null & undefined", () => {
expect(null || false).toBeFalse();
expect(null || true).toBeTrue();
expect(false || null).toBeNull();
expect(true || null).toBeTrue();
expect(undefined || false).toBeFalse();
expect(undefined || true).toBeTrue();
expect(false || undefined).toBeUndefined();
expect(true || undefined).toBeTrue();
expect(null || false).toBeFalse();
expect(null || true).toBeTrue();
expect(false || null).toBeNull();
expect(true || null).toBeTrue();
expect(undefined || false).toBeFalse();
expect(undefined || true).toBeTrue();
expect(false || undefined).toBeUndefined();
expect(true || undefined).toBeTrue();
});

View file

@ -1,16 +1,16 @@
test("basic functionality", () => {
expect(10 % 3).toBe(1);
expect(10.5 % 2.5).toBe(0.5);
expect(-0.99 % 0.99).toBe(-0);
expect(10 % 3).toBe(1);
expect(10.5 % 2.5).toBe(0.5);
expect(-0.99 % 0.99).toBe(-0);
// Examples from MDN:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
expect(12 % 5).toBe(2);
expect(-1 % 2).toBe(-1);
expect(1 % -2).toBe(1);
expect(1 % 2).toBe(1);
expect(2 % 3).toBe(2);
expect(-4 % 2).toBe(-0);
expect(5.5 % 2).toBe(1.5);
expect(NaN % 2).toBeNaN();
// Examples from MDN:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
expect(12 % 5).toBe(2);
expect(-1 % 2).toBe(-1);
expect(1 % -2).toBe(1);
expect(1 % 2).toBe(1);
expect(2 % 3).toBe(2);
expect(-4 % 2).toBe(-0);
expect(5.5 % 2).toBe(1.5);
expect(NaN % 2).toBeNaN();
});

View file

@ -1,16 +1,16 @@
test("basic functionality", () => {
const x = 1;
const x = 1;
expect(x === 1 ? true : false).toBeTrue();
expect(x ? x : 0).toBe(x);
expect(1 < 2 ? true : false).toBeTrue();
expect(0 ? 1 : 1 ? 10 : 20).toBe(10);
expect(0 ? (1 ? 1 : 10) : 20).toBe(20);
expect(x === 1 ? true : false).toBeTrue();
expect(x ? x : 0).toBe(x);
expect(1 < 2 ? true : false).toBeTrue();
expect(0 ? 1 : 1 ? 10 : 20).toBe(10);
expect(0 ? (1 ? 1 : 10) : 20).toBe(20);
});
test("object values", () => {
const o = {};
o.f = true;
expect(o.f ? true : false).toBeTrue();
expect(1 ? o.f : null).toBeTrue();
const o = {};
o.f = true;
expect(o.f ? true : false).toBeTrue();
expect(1 ? o.f : null).toBeTrue();
});

View file

@ -1,27 +1,27 @@
test("basic functionality", () => {
expect(typeof "foo").toBe("string");
expect(typeof (1 + 2)).toBe("number");
expect(typeof {}).toBe("object");
expect(typeof null).toBe("object");
expect(typeof undefined).toBe("undefined");
expect(typeof 1n).toBe("bigint");
expect(typeof Symbol()).toBe("symbol");
expect(typeof function () {}).toBe("function");
expect(typeof "foo").toBe("string");
expect(typeof (1 + 2)).toBe("number");
expect(typeof {}).toBe("object");
expect(typeof null).toBe("object");
expect(typeof undefined).toBe("undefined");
expect(typeof 1n).toBe("bigint");
expect(typeof Symbol()).toBe("symbol");
expect(typeof function () {}).toBe("function");
var iExist = 1;
expect(typeof iExist).toBe("number");
expect(typeof iDontExist).toBe("undefined");
var iExist = 1;
expect(typeof iExist).toBe("number");
expect(typeof iDontExist).toBe("undefined");
});
test("typeof calls property getter", () => {
var calls = 0;
Object.defineProperty(globalThis, "foo", {
get() {
calls++;
return 10;
},
});
var calls = 0;
Object.defineProperty(globalThis, "foo", {
get() {
calls++;
return 10;
},
});
expect(typeof foo).toBe("number");
expect(calls).toBe(1);
expect(typeof foo).toBe("number");
expect(calls).toBe(1);
});

View file

@ -1,14 +1,14 @@
test("basic functionality", () => {
expect(void "").toBeUndefined();
expect(void "foo").toBeUndefined();
expect(void 1).toBeUndefined();
expect(void 42).toBeUndefined();
expect(void true).toBeUndefined();
expect(void false).toBeUndefined();
expect(void null).toBeUndefined();
expect(void undefined).toBeUndefined();
expect(void function () {}).toBeUndefined();
expect(void (() => {})).toBeUndefined();
expect(void (() => "hello friends")()).toBeUndefined();
expect((() => void "hello friends")()).toBeUndefined();
expect(void "").toBeUndefined();
expect(void "foo").toBeUndefined();
expect(void 1).toBeUndefined();
expect(void 42).toBeUndefined();
expect(void true).toBeUndefined();
expect(void false).toBeUndefined();
expect(void null).toBeUndefined();
expect(void undefined).toBeUndefined();
expect(void function () {}).toBeUndefined();
expect(void (() => {})).toBeUndefined();
expect(void (() => "hello friends")()).toBeUndefined();
expect((() => void "hello friends")()).toBeUndefined();
});