diff options
Diffstat (limited to 'Libraries/LibJS/Tests/builtins/BigInt/bigint-basic.js')
-rw-r--r-- | Libraries/LibJS/Tests/builtins/BigInt/bigint-basic.js | 134 |
1 files changed, 70 insertions, 64 deletions
diff --git a/Libraries/LibJS/Tests/builtins/BigInt/bigint-basic.js b/Libraries/LibJS/Tests/builtins/BigInt/bigint-basic.js index 841b60008f..c32681792f 100644 --- a/Libraries/LibJS/Tests/builtins/BigInt/bigint-basic.js +++ b/Libraries/LibJS/Tests/builtins/BigInt/bigint-basic.js @@ -1,74 +1,80 @@ -load("test-common.js"); +describe("correct behavior", () => { + test("typeof bigint", () => { + expect(typeof 1n).toBe("bigint"); + }); -try { - var bigint = 123n; + test("bigint string coersion", () => { + expect("" + 123n).toBe("123"); + }); - assert(typeof bigint === "bigint"); - assert(-bigint === -123n); - assert("" + bigint === "123"); + test("arithmetic operators", () => { + let bigint = 123n; + expect(-bigint).toBe(-123n); - assertThrowsError( - () => { - +bigint; - }, - { - error: TypeError, - message: "Cannot convert BigInt to number", - } - ); + expect(12n + 34n).toBe(46n); + expect(12n - 34n).toBe(-22n); + expect(8n * 12n).toBe(96n); + expect(123n / 10n).toBe(12n); + expect(2n ** 3n).toBe(8n); + expect(5n % 3n).toBe(2n); + expect( + 45977665298704210987n + + (714320987142450987412098743217984576n / 4598741987421098765327980n) * 987498743n + ).toBe(199365500239020623962n); + }); - assert(12n + 34n === 46n); - assert(12n - 34n === -22n); - assert(8n * 12n === 96n); - assert(123n / 10n === 12n); - assert(2n ** 3n === 8n); - assert(5n % 3n === 2n); - assert( - 45977665298704210987n + - (714320987142450987412098743217984576n / 4598741987421098765327980n) * 987498743n === - 199365500239020623962n - ); + test("bitwise operators", () => { + expect(12n & 5n).toBe(4n); + expect(1n | 2n).toBe(3n); + expect(5n ^ 3n).toBe(6n); + expect(~1n).toBe(-2n); + }); - assert((12n & 5n) === 4n); - assert((1n | 2n) === 3n); - assert((5n ^ 3n) === 6n); - assert(~1n === -2n); + test("increment operators", () => { + let bigint = 1n; + expect(bigint++).toBe(1n); + expect(bigint).toBe(2n); + expect(bigint--).toBe(2n); + expect(bigint).toBe(1n); + expect(++bigint).toBe(2n); + expect(bigint).toBe(2n); + expect(--bigint).toBe(1n); + expect(bigint).toBe(1n); + }); - bigint = 1n; - assert(bigint++ === 1n); - assert(bigint === 2n); - assert(bigint-- === 2n); - assert(bigint === 1n); - assert(++bigint === 2n); - assert(bigint === 2n); - assert(--bigint === 1n); - assert(bigint === 1n); + test("weak equality operators", () => { + expect(1n == 1n).toBeTrue(); + expect(1n == 1).toBeTrue(); + expect(1 == 1n).toBeTrue(); + expect(1n == 1.23).toBeFalse(); + expect(1.23 == 1n).toBeFalse(); - assert((1n == 1n) === true); - assert((1n == 1) === true); - assert((1 == 1n) === true); - assert((1n == 1.23) === false); - assert((1.23 == 1n) === false); + expect(1n != 1n).toBeFalse(); + expect(1n != 1).toBeFalse(); + expect(1 != 1n).toBeFalse(); + expect(1n != 1.23).toBeTrue(); + expect(1.23 != 1n).toBeTrue(); + }); - assert((1n != 1n) === false); - assert((1n != 1) === false); - assert((1 != 1n) === false); - assert((1n != 1.23) === true); - assert((1.23 != 1n) === true); + test("strong equality operators", () => { + expect(1n === 1n).toBeTrue(); + expect(1n === 1).toBeFalse(); + expect(1 === 1n).toBeFalse(); + expect(1n === 1.23).toBeFalse(); + expect(1.23 === 1n).toBeFalse(); - assert((1n === 1n) === true); - assert((1n === 1) == false); - assert((1 === 1n) === false); - assert((1n === 1.23) === false); - assert((1.23 === 1n) === false); + expect(1n !== 1n).toBeFalse(); + expect(1n !== 1).toBeTrue(); + expect(1 !== 1n).toBeTrue(); + expect(1n !== 1.23).toBeTrue(); + expect(1.23 !== 1n).toBeTrue(); + }); +}); - assert((1n !== 1n) === false); - assert((1n !== 1) === true); - assert((1 !== 1n) === true); - assert((1n !== 1.23) === true); - assert((1.23 !== 1n) === true); - - console.log("PASS"); -} catch (e) { - console.log("FAIL: " + e); -} +describe("errors", () => { + test("conversion to number", () => { + expect(() => { + +123n; + }).toThrowWithMessage(TypeError, "Cannot convert BigInt to number"); + }); +}); |