numeric-literals-basic.js 813 B

12345678910111213141516171819202122232425262728293031323334353637
  1. test("hex literals", () => {
  2. expect(0xff).toBe(255);
  3. expect(0xff).toBe(255);
  4. });
  5. test("octal literals", () => {
  6. expect(0o10).toBe(8);
  7. expect(0o10).toBe(8);
  8. });
  9. test("binary literals", () => {
  10. expect(0b10).toBe(2);
  11. expect(0b10).toBe(2);
  12. });
  13. test("exponential literals", () => {
  14. expect(1e3).toBe(1000);
  15. expect(1e3).toBe(1000);
  16. expect(1e-3).toBe(0.001);
  17. expect(1e1).toBe(10);
  18. expect(0.1e1).toBe(1);
  19. expect(0.1e1).toBe(1);
  20. expect(0.1e1).toBe(1);
  21. expect(0.1e1).toBe(1);
  22. });
  23. test("decimal numbers", () => {
  24. expect(1).toBe(1);
  25. expect(0.1).toBe(0.1);
  26. });
  27. test("accessing properties of decimal numbers", () => {
  28. Number.prototype.foo = "foo";
  29. expect((1).foo).toBe("foo");
  30. expect((1.1).foo).toBe("foo");
  31. expect((0.1).foo).toBe("foo");
  32. });