shim.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Taken from: https://github.com/mathiasbynens/String.fromCodePoint/blob/master
  2. // /tests/tests.js
  3. "use strict";
  4. var pow = Math.pow;
  5. module.exports = function (t, a) {
  6. var counter, result;
  7. a(t.length, 1, "Length");
  8. a(String.propertyIsEnumerable("fromCodePoint"), false, "Not enumerable");
  9. a(t(""), "\0", "Empty string");
  10. a(t(), "", "No arguments");
  11. a(t(-0), "\0", "-0");
  12. a(t(0), "\0", "0");
  13. a(t(0x1D306), "\uD834\uDF06", "Unicode");
  14. a(t(0x1D306, 0x61, 0x1D307), "\uD834\uDF06a\uD834\uDF07", "Complex unicode");
  15. a(t(0x61, 0x62, 0x1D307), "ab\uD834\uDF07", "Complex");
  16. a(t(false), "\0", "false");
  17. a(t(null), "\0", "null");
  18. a.throws(function () {
  19. t("_");
  20. }, RangeError, "_");
  21. a.throws(function () {
  22. t(Infinity);
  23. }, RangeError, "Infinity");
  24. a.throws(function () {
  25. t(-Infinity);
  26. }, RangeError, "-Infinity");
  27. a.throws(function () {
  28. t(-1);
  29. }, RangeError, "-1");
  30. a.throws(function () {
  31. t(0x10FFFF + 1);
  32. }, RangeError, "Range error #1");
  33. a.throws(function () {
  34. t(3.14);
  35. }, RangeError, "Range error #2");
  36. a.throws(function () {
  37. t(3e-2);
  38. }, RangeError, "Range error #3");
  39. a.throws(function () {
  40. t(-Infinity);
  41. }, RangeError, "Range error #4");
  42. a.throws(function () {
  43. t(Number(Infinity));
  44. }, RangeError, "Range error #5");
  45. a.throws(function () {
  46. t(NaN);
  47. }, RangeError, "Range error #6");
  48. a.throws(function () {
  49. t(undefined);
  50. }, RangeError, "Range error #7");
  51. a.throws(function () {
  52. t({});
  53. }, RangeError, "Range error #8");
  54. a.throws(function () {
  55. t(/re/);
  56. }, RangeError, "Range error #9");
  57. counter = pow(2, 15) * 3 / 2;
  58. result = [];
  59. while (--counter >= 0) result.push(0); // One code unit per symbol
  60. t.apply(null, result); // Must not throw
  61. counter = pow(2, 15) * 3 / 2;
  62. result = [];
  63. while (--counter >= 0) result.push(0xFFFF + 1); // Two code units per symbol
  64. t.apply(null, result); // Must not throw
  65. };