numeric-literals-basic.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. });
  12. test("binary literals", () => {
  13. expect(0b10).toBe(2);
  14. expect(0b10).toBe(2);
  15. });
  16. test("exponential literals", () => {
  17. expect(1e3).toBe(1000);
  18. expect(1e3).toBe(1000);
  19. expect(1e-3).toBe(0.001);
  20. expect(1e1).toBe(10);
  21. expect(0.1e1).toBe(1);
  22. expect(0.1e1).toBe(1);
  23. expect(0.1e1).toBe(1);
  24. expect(0.1e1).toBe(1);
  25. });
  26. test("decimal numbers", () => {
  27. expect(1).toBe(1);
  28. expect(0.1).toBe(0.1);
  29. });
  30. test("accessing properties of decimal numbers", () => {
  31. Number.prototype.foo = "foo";
  32. expect((1).foo).toBe("foo");
  33. expect((1.1).foo).toBe("foo");
  34. expect((0.1).foo).toBe("foo");
  35. });
  36. test("invalid numeric literals", () => {
  37. expect("1e").not.toEval();
  38. expect("0x").not.toEval();
  39. expect("0b").not.toEval();
  40. expect("0o").not.toEval();
  41. expect("'use strict'; 0755").not.toEval();
  42. });