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

LibJS: Convert all remaining non-Array tests to the new system :)

This commit is contained in:
Matthew Olsson 2020-07-05 17:26:26 -07:00 committed by Andreas Kling
parent 918f4affd5
commit 15de2eda2b
72 changed files with 2394 additions and 1998 deletions

View file

@ -1,61 +1,55 @@
load("test-common.js");
let x;
try {
var x;
test("basic functionality", () => {
x = 1;
expect((x = 2)).toBe(2);
expect(x).toBe(2);
x = 1;
assert((x = 2) === 2);
assert(x === 2);
x = 1;
assert((x += 2) === 3);
assert(x === 3);
expect((x += 2)).toBe(3);
expect(x).toBe(3);
x = 3;
assert((x -= 2) === 1);
assert(x === 1);
expect((x -= 2)).toBe(1);
expect(x).toBe(1);
x = 3;
assert((x *= 2) === 6);
assert(x === 6);
expect((x *= 2)).toBe(6);
expect(x).toBe(6);
x = 6;
assert((x /= 2) === 3);
assert(x === 3);
expect((x /= 2)).toBe(3);
expect(x).toBe(3);
x = 6;
assert((x %= 4) === 2);
assert(x === 2);
expect((x %= 4)).toBe(2);
expect(x).toBe(2);
x = 2;
assert((x **= 3) === 8);
assert(x === 8);
expect((x **= 3)).toBe(8);
expect(x).toBe(8);
x = 3;
assert((x &= 2) === 2);
assert(x === 2);
expect((x &= 2)).toBe(2);
expect(x).toBe(2);
x = 3;
assert((x |= 4) === 7);
assert(x === 7);
expect((x |= 4)).toBe(7);
expect(x).toBe(7);
x = 6;
assert((x ^= 2) === 4);
assert(x === 4);
expect((x ^= 2)).toBe(4);
expect(x).toBe(4);
x = 2;
assert((x <<= 2) === 8);
assert(x === 8);
expect((x <<= 2)).toBe(8);
expect(x).toBe(8);
x = 8;
assert((x >>= 2) === 2);
assert(x === 2);
expect((x >>= 2)).toBe(2);
expect(x).toBe(2);
x = -(2 ** 32 - 10);
assert((x >>>= 2) === 2);
assert(x === 2);
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}
expect((x >>>= 2)).toBe(2);
expect(x).toBe(2);
});

View file

@ -1,63 +1,60 @@
load("test-common.js");
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);
try {
assert(0 << 0 === 0);
assert(0 << 1 === 0);
assert(0 << 2 === 0);
assert(0 << 3 === 0);
assert(0 << 4 === 0);
assert(0 << 5 === 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);
assert(1 << 0 === 1);
assert(1 << 1 === 2);
assert(1 << 2 === 4);
assert(1 << 3 === 8);
assert(1 << 4 === 16);
assert(1 << 5 === 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);
assert(2 << 0 === 2);
assert(2 << 1 === 4);
assert(2 << 2 === 8);
assert(2 << 3 === 16);
assert(2 << 4 === 32);
assert(2 << 5 === 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);
assert(3 << 0 === 3);
assert(3 << 1 === 6);
assert(3 << 2 === 12);
assert(3 << 3 === 24);
assert(3 << 4 === 48);
assert(3 << 5 === 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);
assert(4 << 0 === 4);
assert(4 << 1 === 8);
assert(4 << 2 === 16);
assert(4 << 3 === 32);
assert(4 << 4 === 64);
assert(4 << 5 === 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);
});
assert(5 << 0 === 5);
assert(5 << 1 === 10);
assert(5 << 2 === 20);
assert(5 << 3 === 40);
assert(5 << 4 === 80);
assert(5 << 5 === 160);
test("shifting with non-numeric values", () => {
let x = 3;
let y = 7;
var x = 3;
var y = 7;
assert("42" << 6 === 2688);
assert(x << y === 384);
assert(x << [[[[12]]]] === 12288);
assert(undefined << y === 0);
assert("a" << "b" === 0);
assert(null << null === 0);
assert(undefined << undefined === 0);
assert(NaN << NaN === 0);
assert(NaN << 6 === 0);
assert(Infinity << Infinity === 0);
assert(-Infinity << Infinity === 0);
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}
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,63 +1,60 @@
load("test-common.js");
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);
try {
assert((0 | 0) === 0);
assert((0 | 1) === 1);
assert((0 | 2) === 2);
assert((0 | 3) === 3);
assert((0 | 4) === 4);
assert((0 | 5) === 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);
assert((1 | 0) === 1);
assert((1 | 1) === 1);
assert((1 | 2) === 3);
assert((1 | 3) === 3);
assert((1 | 4) === 5);
assert((1 | 5) === 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);
assert((2 | 0) === 2);
assert((2 | 1) === 3);
assert((2 | 2) === 2);
assert((2 | 3) === 3);
assert((2 | 4) === 6);
assert((2 | 5) === 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);
assert((3 | 0) === 3);
assert((3 | 1) === 3);
assert((3 | 2) === 3);
assert((3 | 3) === 3);
assert((3 | 4) === 7);
assert((3 | 5) === 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);
assert((4 | 0) === 4);
assert((4 | 1) === 5);
assert((4 | 2) === 6);
assert((4 | 3) === 7);
assert((4 | 4) === 4);
assert((4 | 5) === 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);
});
assert((5 | 0) === 5);
assert((5 | 1) === 5);
assert((5 | 2) === 7);
assert((5 | 3) === 7);
assert((5 | 4) === 5);
assert((5 | 5) === 5);
test("or with non-numeric values", () => {
let x = 3;
let y = 7;
var x = 3;
var y = 7;
assert(("42" | 6) === 46);
assert((x | y) === 7);
assert((x | [[[[12]]]]) === 15);
assert((undefined | y) === 7);
assert(("a" | "b") === 0);
assert((null | null) === 0);
assert((undefined | undefined) === 0);
assert((NaN | NaN) === 0);
assert((NaN | 6) === 6);
assert((Infinity | Infinity) === 0);
assert((-Infinity | Infinity) === 0);
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}
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,63 +1,62 @@
load("test-common.js");
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);
try {
assert(0 >> 0 === 0);
assert(0 >> 1 === 0);
assert(0 >> 2 === 0);
assert(0 >> 3 === 0);
assert(0 >> 4 === 0);
assert(0 >> 5 === 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);
assert(1 >> 0 === 1);
assert(1 >> 1 === 0);
assert(1 >> 2 === 0);
assert(1 >> 3 === 0);
assert(1 >> 4 === 0);
assert(1 >> 5 === 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);
assert(5 >> 0 === 5);
assert(5 >> 1 === 2);
assert(5 >> 2 === 1);
assert(5 >> 3 === 0);
assert(5 >> 4 === 0);
assert(5 >> 5 === 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);
});
assert(42 >> 0 === 42);
assert(42 >> 1 === 21);
assert(42 >> 2 === 10);
assert(42 >> 3 === 5);
assert(42 >> 4 === 2);
assert(42 >> 5 === 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);
assert(-1 >> 0 === -1);
assert(-1 >> 1 === -1);
assert(-1 >> 2 === -1);
assert(-1 >> 3 === -1);
assert(-1 >> 4 === -1);
assert(-1 >> 5 === -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);
});
assert(-5 >> 0 === -5);
assert(-5 >> 1 === -3);
assert(-5 >> 2 === -2);
assert(-5 >> 3 === -1);
assert(-5 >> 4 === -1);
assert(-5 >> 5 === -1);
test("shifting with non-numeric values", () => {
let x = 67;
let y = 4;
var x = 67;
var y = 4;
assert("42" >> 3 === 5);
assert(x >> y === 4);
assert(x >> [[[[5]]]] === 2);
assert(undefined >> y === 0);
assert("a" >> "b" === 0);
assert(null >> null === 0);
assert(undefined >> undefined === 0);
assert(NaN >> NaN === 0);
assert(6 >> NaN === 6);
assert(Infinity >> Infinity === 0);
assert(-Infinity >> Infinity === 0);
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}
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,63 +1,62 @@
load("test-common.js");
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);
try {
assert(0 >>> 0 === 0);
assert(0 >>> 1 === 0);
assert(0 >>> 2 === 0);
assert(0 >>> 3 === 0);
assert(0 >>> 4 === 0);
assert(0 >>> 5 === 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);
assert(1 >>> 0 === 1);
assert(1 >>> 1 === 0);
assert(1 >>> 2 === 0);
assert(1 >>> 3 === 0);
assert(1 >>> 4 === 0);
assert(1 >>> 5 === 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);
assert(5 >>> 0 === 5);
assert(5 >>> 1 === 2);
assert(5 >>> 2 === 1);
assert(5 >>> 3 === 0);
assert(5 >>> 4 === 0);
assert(5 >>> 5 === 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);
});
assert(42 >>> 0 === 42);
assert(42 >>> 1 === 21);
assert(42 >>> 2 === 10);
assert(42 >>> 3 === 5);
assert(42 >>> 4 === 2);
assert(42 >>> 5 === 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);
assert(-1 >>> 0 === 4294967295);
assert(-1 >>> 1 === 2147483647);
assert(-1 >>> 2 === 1073741823);
assert(-1 >>> 3 === 536870911);
assert(-1 >>> 4 === 268435455);
assert(-1 >>> 5 === 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);
});
assert(-5 >>> 0 === 4294967291);
assert(-5 >>> 1 === 2147483645);
assert(-5 >>> 2 === 1073741822);
assert(-5 >>> 3 === 536870911);
assert(-5 >>> 4 === 268435455);
assert(-5 >>> 5 === 134217727);
test("shifting with non-numeric values", () => {
let x = -67;
let y = 4;
var x = -67;
var y = 4;
assert("-42" >>> 3 === 536870906);
assert(x >>> y === 268435451);
assert(x >>> [[[[5]]]] === 134217725);
assert(undefined >>> y === 0);
assert("a" >>> "b" === 0);
assert(null >>> null === 0);
assert(undefined >>> undefined === 0);
assert(NaN >>> NaN === 0);
assert(6 >>> NaN === 6);
assert(Infinity >>> Infinity === 0);
assert(-Infinity >>> Infinity === 0);
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}
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);
});

View file

@ -1,6 +1,4 @@
load("test-common.js");
try {
test("basic functionality", () => {
const vals = [
1,
2,
@ -723,13 +721,9 @@ try {
let x = vals[test[0]];
let y = vals[test[1]];
assert(x < y === test[2]);
assert(x > y === test[3]);
assert(x <= y === test[4]);
assert(x >= y === test[5]);
expect(x < y).toBe(test[2]);
expect(x > y).toBe(test[3]);
expect(x <= y).toBe(test[4]);
expect(x >= y).toBe(test[5]);
}
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}
});

View file

@ -1,26 +1,24 @@
load("test-common.js");
test("inside parenthesis", () => {
expect((1, 2, 3)).toBe(3);
expect((1, 2 + 3, 4)).toBe(4);
});
try {
assert((1, 2, 3) === 3);
assert((1, 2 + 3, 4) === 4);
var foo = 0;
test("with post-increment operator", () => {
let foo = 0;
foo = (foo++, foo);
assert(foo === 1);
expect(foo).toBe(1);
});
test("with assignment operator", () => {
var a, b, c;
assert(((a = b = 3), (c = 4)) === 4);
assert(a === 3);
assert(b === 3);
assert(c === 4);
expect(((a = b = 3), (c = 4))).toBe(4);
expect(a).toBe(3);
expect(b).toBe(3);
expect(c).toBe(4);
var x, y, z;
assert((x = ((y = 5), (z = 6))) === 6);
assert(x === 6);
assert(y === 5);
assert(z === 6);
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}
expect((x = ((y = 5), (z = 6)))).toBe(6);
expect(x).toBe(6);
expect(y).toBe(5);
expect(z).toBe(6);
});

View file

@ -1,60 +1,58 @@
load("test-common.js");
try {
o = {};
test("deleting object properties", () => {
const o = {};
o.x = 1;
o.y = 2;
o.z = 3;
assert(Object.getOwnPropertyNames(o).length === 3);
expect(Object.getOwnPropertyNames(o)).toHaveLength(3);
assert(delete o.x === true);
assert(o.hasOwnProperty("x") === false);
assert(o.hasOwnProperty("y") === true);
assert(o.hasOwnProperty("z") === true);
assert(Object.getOwnPropertyNames(o).length === 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);
assert(delete o.y === true);
assert(o.hasOwnProperty("x") === false);
assert(o.hasOwnProperty("y") === false);
assert(o.hasOwnProperty("z") === true);
assert(Object.getOwnPropertyNames(o).length === 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);
assert(delete o.z === true);
assert(o.hasOwnProperty("x") === false);
assert(o.hasOwnProperty("y") === false);
assert(o.hasOwnProperty("z") === false);
assert(Object.getOwnPropertyNames(o).length === 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);
});
a = [3, 5, 7];
test("deleting array indices", () => {
const a = [3, 5, 7];
assert(Object.getOwnPropertyNames(a).length === 4);
expect(Object.getOwnPropertyNames(a)).toHaveLength(4);
assert(delete a[0] === true);
assert(a.hasOwnProperty(0) === false);
assert(a.hasOwnProperty(1) === true);
assert(a.hasOwnProperty(2) === true);
assert(Object.getOwnPropertyNames(a).length === 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);
assert(delete a[1] === true);
assert(a.hasOwnProperty(0) === false);
assert(a.hasOwnProperty(1) === false);
assert(a.hasOwnProperty(2) === true);
assert(Object.getOwnPropertyNames(a).length === 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);
assert(delete a[2] === true);
assert(a.hasOwnProperty(0) === false);
assert(a.hasOwnProperty(1) === false);
assert(a.hasOwnProperty(2) === false);
assert(Object.getOwnPropertyNames(a).length === 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);
});
q = {};
test("deleting non-configurable property", () => {
const q = {};
Object.defineProperty(q, "foo", { value: 1, writable: false, enumerable: false });
assert(q.foo === 1);
expect(q.foo).toBe(1);
assert(delete q.foo === false);
assert(q.hasOwnProperty("foo") === true);
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}
expect(delete q.foo).toBeFalse();
expect(q.hasOwnProperty("foo")).toBeTrue();
});

View file

@ -1,19 +1,9 @@
load("test-common.js");
a = 1;
try {
a = 1;
assert(delete a === true);
test("basic functionality", () => {
expect(delete a).toBeTrue();
assertThrowsError(
() => {
a;
},
{
error: ReferenceError,
}
);
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}
expect(() => {
a;
}).toThrowWithMessage(ReferenceError, "'a' is not defined");
});

View file

@ -1,10 +1,8 @@
load("test-common.js");
a = 1;
try {
a = 1;
assert(delete globalThis.a === true);
a = 2;
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}
test("basic functionality", () => {
expect(delete globalThis.a).toBeTrue();
expect(() => {
a = 2;
}).not.toThrow();
});

View file

@ -1,38 +1,32 @@
load("test-common.js");
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();
});
try {
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();
});
test("in operator with string object", () => {
const s = new String("foo");
expect("length" in s).toBeTrue();
});
test("error when used with primitives", () => {
["foo", 123, null, undefined].forEach(value => {
assertThrowsError(
() => {
"prop" in value;
},
{
error: TypeError,
message: "'in' operator must be used on an object",
}
);
expect(() => {
"prop" in value;
}).toThrowWithMessage(TypeError, "'in' operator must be used on an object");
});
var o = { foo: "bar", bar: undefined };
assert("" in o === false);
assert("foo" in o === true);
assert("bar" in o === true);
assert("baz" in o === false);
assert("toString" in o === true);
var a = ["hello", "friends"];
assert(0 in a === true);
assert(1 in a === true);
assert(2 in a === false);
assert("0" in a === true);
assert("hello" in a === false);
assert("friends" in a === false);
assert("length" in a === true);
var s = new String("foo");
assert("length" in s);
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}
});

View file

@ -1,13 +1,13 @@
load("test-common.js");
try {
test("basic functionality", () => {
function Foo() {
this.x = 123;
}
var foo = new Foo();
assert(foo instanceof Foo);
const foo = new Foo();
expect(foo instanceof Foo).toBeTrue();
});
test("derived ES5 classes", () => {
function Base() {
this.is_base = true;
}
@ -18,11 +18,7 @@ try {
Object.setPrototypeOf(Derived.prototype, Base.prototype);
var d = new Derived();
assert(d instanceof Derived);
assert(d instanceof Base);
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}
const d = new Derived();
expect(d instanceof Derived).toBeTrue();
expect(d instanceof Base).toBeTrue();
});

View file

@ -0,0 +1,50 @@
test("booleans", () => {
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");
});
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);
});
test("objects", () => {
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();
});

View file

@ -1,118 +0,0 @@
load("test-common.js");
try {
assert((true && true) === true);
assert((false && false) === false);
assert((true && false) === false);
assert((false && true) === false);
assert((false && 1 === 2) === false);
assert((true && 1 === 2) === false);
assert(("" && "") === "");
assert(("" && false) === "");
assert(("" && true) === "");
assert((false && "") === false);
assert((true && "") === "");
assert(("foo" && "bar") === "bar");
assert(("foo" && false) === false);
assert(("foo" && true) === true);
assert((false && "bar") === false);
assert((true && "bar") === "bar");
assert((0 && false) === 0);
assert((0 && true) === 0);
assert((42 && false) === false);
assert((42 && true) === true);
assert((false && 0) === false);
assert((true && 0) === 0);
assert((false && 42) === false);
assert((true && 42) === 42);
assert(([] && false) === false);
assert(([] && true) === true);
assert((false && []) === false);
assert((true && []).length === 0);
assert((null && false) === null);
assert((null && true) === null);
assert((false && null) === false);
assert((true && null) === null);
assert((undefined && false) === undefined);
assert((undefined && true) === undefined);
assert((false && undefined) === false);
assert((true && undefined) === undefined);
assert((true || true) === true);
assert((false || false) === false);
assert((true || false) === true);
assert((false || true) === true);
assert((false || 1 === 2) === false);
assert((true || 1 === 2) === true);
assert(("" || "") === "");
assert(("" || false) === false);
assert(("" || true) === true);
assert((false || "") === "");
assert((true || "") === true);
assert(("foo" || "bar") === "foo");
assert(("foo" || false) === "foo");
assert(("foo" || true) === "foo");
assert((false || "bar") === "bar");
assert((true || "bar") === true);
assert((0 || false) === false);
assert((0 || true) === true);
assert((42 || false) === 42);
assert((42 || true) === 42);
assert((false || 0) === 0);
assert((true || 0) === true);
assert((false || 42) === 42);
assert((true || 42) === true);
assert(([] || false).length === 0);
assert(([] || true).length === 0);
assert((false || []).length === 0);
assert((true || []) === true);
assert((null || false) === false);
assert((null || true) === true);
assert((false || null) === null);
assert((true || null) === true);
assert((undefined || false) === false);
assert((undefined || true) === true);
assert((false || undefined) === undefined);
assert((true || undefined) === true);
assert((true ?? true) === true);
assert((false ?? false) === false);
assert((true ?? false) === true);
assert((false ?? true) === false);
assert((false ?? 1 === 2) === false);
assert((true ?? 1 === 2) === true);
assert(("" ?? "") === "");
assert(("" ?? false) === "");
assert(("" ?? true) === "");
assert((false ?? "") === false);
assert((true ?? "") === true);
assert(("foo" ?? "bar") === "foo");
assert(("foo" ?? false) === "foo");
assert(("foo" ?? true) === "foo");
assert((false ?? "bar") === false);
assert((true ?? "bar") === true);
assert((0 ?? false) === 0);
assert((0 ?? true) === 0);
assert((42 ?? false) === 42);
assert((42 ?? true) === 42);
assert((false ?? 0) === false);
assert((true ?? 0) === true);
assert((false ?? 42) === false);
assert((true ?? 42) === true);
assert(([] ?? false).length === 0);
assert(([] ?? true).length === 0);
assert((false ?? []) === false);
assert((true ?? []) === true);
assert((null ?? false) === false);
assert((null ?? true) === true);
assert((false ?? null) === false);
assert((true ?? null) === true);
assert((undefined ?? false) === false);
assert((undefined ?? true) === true);
assert((false ?? undefined) === false);
assert((true ?? undefined) === true);
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -1,15 +1,13 @@
load("test-common.js");
try {
test("basic functionality", () => {
let foo = 1;
false && (foo = 2);
assert(foo === 1);
expect(foo).toBe(1);
foo = 1;
true || (foo = 2);
assert(foo === 1);
expect(foo).toBe(1);
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}
foo = 1;
true ?? (foo = 2);
expect(foo).toBe(1);
});

View file

@ -0,0 +1,50 @@
test("booleans", () => {
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();
});
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();
});
test("objects", () => {
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();
});

View file

@ -0,0 +1,50 @@
test("booleans", () => {
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();
});
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();
});
test("objects", () => {
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();
});

View file

@ -1,22 +1,16 @@
load("test-common.js");
try {
assert(10 % 3 === 1);
assert(10.5 % 2.5 === 0.5);
assert(-0.99 % 0.99 === -0);
test("basic functionality", () => {
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
assert(12 % 5 === 2);
assert(-1 % 2 === -1);
assert(1 % -2 === 1);
assert(isNaN(NaN % 2));
assert(1 % 2 === 1);
assert(2 % 3 === 2);
assert(-4 % 2 === -0);
assert(5.5 % 2 === 1.5);
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}
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,21 +1,16 @@
load("test-common.js");
test("basic functionality", () => {
const x = 1;
try {
var 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);
});
assert(x === 1 ? true : false);
assert((x ? x : 0) === x);
assert(1 < 2 ? true : false);
assert((0 ? 1 : 1 ? 10 : 20) === 10);
assert((0 ? (1 ? 1 : 10) : 20) === 20);
var o = {};
test("object values", () => {
const o = {};
o.f = true;
assert(o.f ? true : false);
assert(1 ? o.f : null);
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}
expect(o.f ? true : false).toBeTrue();
expect(1 ? o.f : null).toBeTrue();
});

View file

@ -1,27 +1,27 @@
load("test-common.js");
try {
assert(typeof "foo" === "string");
assert(!(typeof "foo" !== "string"));
assert(typeof (1 + 2) === "number");
assert(typeof {} === "object");
assert(typeof null === "object");
assert(typeof undefined === "undefined");
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");
var iExist = 1;
assert(typeof iExist === "number");
assert(typeof iDontExist === "undefined");
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;
},
});
assert(typeof foo === "undefined");
assert(calls === 1);
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}
expect(typeof foo).toBe("number");
expect(calls).toBe(1);
});

View file

@ -1,20 +1,14 @@
load("test-common.js");
try {
assert(void "" === undefined);
assert(void "foo" === undefined);
assert(void 1 === undefined);
assert(void 42 === undefined);
assert(void true === undefined);
assert(void false === undefined);
assert(void null === undefined);
assert(void undefined === undefined);
assert(void function () {} === undefined);
assert(void (() => {}) === undefined);
assert(void (() => "hello friends")() === undefined);
assert((() => void "hello friends")() === undefined);
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}
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();
});