1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 04:57:44 +00:00

LibJS: Disallow numerical separators in octal numbers and after '.'

This commit is contained in:
davidot 2021-11-26 18:30:42 +01:00 committed by Linus Groh
parent 32016d3924
commit afde1821b5
2 changed files with 34 additions and 4 deletions

View file

@ -0,0 +1,26 @@
describe("numeric separators", () => {
test("numeric separator works for 'normal' number", () => {
expect("1_2").toEvalTo(12);
expect("4_2.4_2").toEvalTo(42.42);
expect("1_2e0_2").toEvalTo(1200);
expect("1_2E+_1").not.toEval();
expect("1_2E+0_1").toEvalTo(120);
});
test("cannot use numeric separator after .", () => {
expect("4._3").not.toEval();
expect("0._3").not.toEval();
expect("1_.3._3").not.toEval();
// Actually a valid attempt to get property '_3' on 1.3 which fails but does parse.
expect("1.3._3").toEval();
});
test("cannot use numeric separator in octal escaped number", () => {
expect("00_1").not.toEval();
expect("01_1").not.toEval();
expect("07_3").not.toEval();
expect("00_1").not.toEval();
});
});