diff options
author | Andreas Kling <kling@serenityos.org> | 2021-01-12 12:17:30 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-01-12 12:17:46 +0100 |
commit | 13d7c09125f8eec703d0a43a9a87fc8aa08f7319 (patch) | |
tree | 70fd643c429cea5c1f9362c2674511d17a53f3b5 /Userland/Libraries/LibJS/Tests/numeric-literals-basic.js | |
parent | dc28c07fa526841e05e16161c74a6c23984f1dd5 (diff) | |
download | serenity-13d7c09125f8eec703d0a43a9a87fc8aa08f7319.zip |
Libraries: Move to Userland/Libraries/
Diffstat (limited to 'Userland/Libraries/LibJS/Tests/numeric-literals-basic.js')
-rw-r--r-- | Userland/Libraries/LibJS/Tests/numeric-literals-basic.js | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Tests/numeric-literals-basic.js b/Userland/Libraries/LibJS/Tests/numeric-literals-basic.js new file mode 100644 index 0000000000..b4b9f75181 --- /dev/null +++ b/Userland/Libraries/LibJS/Tests/numeric-literals-basic.js @@ -0,0 +1,52 @@ +// FIXME: Some of the test cases below are duplicated, presumably to test +// uppercase as well which then got lowercased by Prettier at some point. + +test("hex literals", () => { + expect(0xff).toBe(255); + expect(0xff).toBe(255); +}); + +test("octal literals", () => { + expect(0o10).toBe(8); + expect(0o10).toBe(8); + expect(010).toBe(8); + expect(089).toBe(89); +}); + +test("binary literals", () => { + expect(0b10).toBe(2); + expect(0b10).toBe(2); +}); + +test("exponential literals", () => { + expect(1e3).toBe(1000); + expect(1e3).toBe(1000); + expect(1e-3).toBe(0.001); + expect(1e1).toBe(10); + expect(0.1e1).toBe(1); + expect(0.1e1).toBe(1); + expect(0.1e1).toBe(1); + expect(0.1e1).toBe(1); +}); + +test("decimal numbers", () => { + expect(1).toBe(1); + expect(0.1).toBe(0.1); +}); + +test("accessing properties of decimal numbers", () => { + Number.prototype.foo = "foo"; + expect((1).foo).toBe("foo"); + expect((1.1).foo).toBe("foo"); + expect((0.1).foo).toBe("foo"); +}); + +test("invalid numeric literals", () => { + expect("1e").not.toEval(); + expect("0x").not.toEval(); + expect("0b").not.toEval(); + expect("0o").not.toEval(); + expect("'use strict'; 0755").not.toEval(); + expect("1in[]").not.toEval(); + expect("2instanceof foo").not.toEval(); +}); |