1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 16:54:57 +00:00
serenity/Libraries/LibJS/Tests/numeric-literals-basic.js
Stephan Unverwerth 2c888b3c6e LibJS: Fix parsing of invalid numeric literals
i.e. "1e" "0x" "0b" "0o" used to be parsed as valid literals.
They now produce invalid tokens. Fixes #3716
2020-10-18 15:38:57 +02:00

44 lines
983 B
JavaScript

test("hex literals", () => {
expect(0xff).toBe(255);
expect(0xff).toBe(255);
});
test("octal literals", () => {
expect(0o10).toBe(8);
expect(0o10).toBe(8);
});
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();
});