numeric-literals-basic.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // FIXME: Some of the test cases below are duplicated, presumably to test
  2. // uppercase as well which then got lowercased by Prettier at some point.
  3. test("hex literals", () => {
  4. expect(0xff).toBe(255);
  5. expect(0xff).toBe(255);
  6. });
  7. test("octal literals", () => {
  8. expect(0o10).toBe(8);
  9. expect(0o10).toBe(8);
  10. expect(010).toBe(8);
  11. expect(089).toBe(89);
  12. });
  13. test("binary literals", () => {
  14. expect(0b10).toBe(2);
  15. expect(0b10).toBe(2);
  16. });
  17. test("exponential literals", () => {
  18. expect(1e3).toBe(1000);
  19. expect(1e3).toBe(1000);
  20. expect(1e-3).toBe(0.001);
  21. expect(1e1).toBe(10);
  22. expect(0.1e1).toBe(1);
  23. expect(0.1e1).toBe(1);
  24. expect(0.1e1).toBe(1);
  25. expect(0.1e1).toBe(1);
  26. });
  27. test("decimal numbers", () => {
  28. expect(1).toBe(1);
  29. expect(0.1).toBe(0.1);
  30. });
  31. test("accessing properties of decimal numbers", () => {
  32. Number.prototype.foo = "foo";
  33. expect((1).foo).toBe("foo");
  34. expect((1.1).foo).toBe("foo");
  35. expect((0.1).foo).toBe("foo");
  36. });
  37. test("invalid numeric literals", () => {
  38. expect("1e").not.toEval();
  39. expect("0x").not.toEval();
  40. expect("0b").not.toEval();
  41. expect("0o").not.toEval();
  42. expect("'use strict'; 0755").not.toEval();
  43. expect("1in[]").not.toEval();
  44. expect("2instanceof foo").not.toEval();
  45. });