diff options
author | Andreas Kling <kling@serenityos.org> | 2021-02-05 09:11:58 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-02-05 09:38:45 +0100 |
commit | 16a0e7a66db7305313366359bdf4334b7b6ed6f8 (patch) | |
tree | f12d9d404ec60174878a14bfcd332f92f13cb41a /Userland/Libraries/LibJS/Tests/operators | |
parent | 6622ad88952cf27f432cd4bf51b1e815afcd986e (diff) | |
download | serenity-16a0e7a66db7305313366359bdf4334b7b6ed6f8.zip |
LibJS: Improve correctness of rounding and bitwise operations
Patch from Anonymous
Diffstat (limited to 'Userland/Libraries/LibJS/Tests/operators')
6 files changed, 23 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Tests/operators/binary-bitwise-and.js b/Userland/Libraries/LibJS/Tests/operators/binary-bitwise-and.js index 5eb4f19cc3..a60a69e7fc 100644 --- a/Userland/Libraries/LibJS/Tests/operators/binary-bitwise-and.js +++ b/Userland/Libraries/LibJS/Tests/operators/binary-bitwise-and.js @@ -40,6 +40,9 @@ test("basic numeric and", () => { expect(5 & 3).toBe(1); expect(5 & 4).toBe(4); expect(5 & 5).toBe(5); + + expect(0xffffffff & 0).toBe(0); + expect(0xffffffff & 0xffffffff).toBe(-1); }); test("and with non-numeric values", () => { diff --git a/Userland/Libraries/LibJS/Tests/operators/binary-bitwise-left-shift.js b/Userland/Libraries/LibJS/Tests/operators/binary-bitwise-left-shift.js index d0c9d8d5f9..07c5c9028e 100644 --- a/Userland/Libraries/LibJS/Tests/operators/binary-bitwise-left-shift.js +++ b/Userland/Libraries/LibJS/Tests/operators/binary-bitwise-left-shift.js @@ -40,6 +40,11 @@ test("basic numeric shifting", () => { expect(5 << 3).toBe(40); expect(5 << 4).toBe(80); expect(5 << 5).toBe(160); + + expect(0xffffffff << 0).toBe(-1); + expect(0xffffffff << 16).toBe(-65536); + expect(0xffff0000 << 16).toBe(0); + expect(0xffff0000 << 15).toBe(-2147483648); }); test("shifting with non-numeric values", () => { diff --git a/Userland/Libraries/LibJS/Tests/operators/binary-bitwise-or.js b/Userland/Libraries/LibJS/Tests/operators/binary-bitwise-or.js index 485d1226d2..28ef3d12a7 100644 --- a/Userland/Libraries/LibJS/Tests/operators/binary-bitwise-or.js +++ b/Userland/Libraries/LibJS/Tests/operators/binary-bitwise-or.js @@ -40,6 +40,10 @@ test("basic numeric or", () => { expect(5 | 3).toBe(7); expect(5 | 4).toBe(5); expect(5 | 5).toBe(5); + + expect(0xffffffff | 0).toBe(-1); + expect(0xffffffff | 0xffffffff).toBe(-1); + expect(2147483648 | 0).toBe(-2147483648); }); test("or with non-numeric values", () => { diff --git a/Userland/Libraries/LibJS/Tests/operators/binary-bitwise-right-shift.js b/Userland/Libraries/LibJS/Tests/operators/binary-bitwise-right-shift.js index f071c5da92..efdc4b79f1 100644 --- a/Userland/Libraries/LibJS/Tests/operators/binary-bitwise-right-shift.js +++ b/Userland/Libraries/LibJS/Tests/operators/binary-bitwise-right-shift.js @@ -26,6 +26,10 @@ test("basic numeric shifting", () => { expect(42 >> 3).toBe(5); expect(42 >> 4).toBe(2); expect(42 >> 5).toBe(1); + + expect(0xffffffff >> 0).toBe(-1); + expect(0xffffffff >> 16).toBe(-1); + expect((0xf0000000 * 2) >> 16).toBe(-8192); }); test("numeric shifting with negative lhs values", () => { diff --git a/Userland/Libraries/LibJS/Tests/operators/binary-bitwise-unsigned-right-shift.js b/Userland/Libraries/LibJS/Tests/operators/binary-bitwise-unsigned-right-shift.js index 4a950e18ef..62283631b3 100644 --- a/Userland/Libraries/LibJS/Tests/operators/binary-bitwise-unsigned-right-shift.js +++ b/Userland/Libraries/LibJS/Tests/operators/binary-bitwise-unsigned-right-shift.js @@ -26,6 +26,10 @@ test("basic numeric shifting", () => { expect(42 >>> 3).toBe(5); expect(42 >>> 4).toBe(2); expect(42 >>> 5).toBe(1); + + expect(0xffffffff >>> 0).toBe(4294967295); + expect(0xffffffff >>> 16).toBe(65535); + expect((0xf0000000 * 2) >>> 16).toBe(57344); }); test("numeric shifting with negative lhs values", () => { diff --git a/Userland/Libraries/LibJS/Tests/operators/binary-bitwise-xor.js b/Userland/Libraries/LibJS/Tests/operators/binary-bitwise-xor.js index 356ad01ca4..452b27088f 100644 --- a/Userland/Libraries/LibJS/Tests/operators/binary-bitwise-xor.js +++ b/Userland/Libraries/LibJS/Tests/operators/binary-bitwise-xor.js @@ -40,6 +40,9 @@ test("basic numeric xor", () => { expect(5 ^ 3).toBe(6); expect(5 ^ 4).toBe(1); expect(5 ^ 5).toBe(0); + + expect(0xffffffff ^ 0).toBe(-1); + expect(0xffffffff ^ 0xffffffff).toBe(0); }); test("xor with non-numeric values", () => { |