shim.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 () { t("_"); }, RangeError, "_");
  19. a.throws(function () { t(Infinity); }, RangeError, "Infinity");
  20. a.throws(function () { t(-Infinity); }, RangeError, "-Infinity");
  21. a.throws(function () { t(-1); }, RangeError, "-1");
  22. a.throws(function () { t(0x10ffff + 1); }, RangeError, "Range error #1");
  23. a.throws(function () { t(3.14); }, RangeError, "Range error #2");
  24. a.throws(function () { t(3e-2); }, RangeError, "Range error #3");
  25. a.throws(function () { t(-Infinity); }, RangeError, "Range error #4");
  26. a.throws(function () { t(Number(Infinity)); }, RangeError, "Range error #5");
  27. a.throws(function () { t(NaN); }, RangeError, "Range error #6");
  28. a.throws(function () { t(undefined); }, RangeError, "Range error #7");
  29. a.throws(function () { t({}); }, RangeError, "Range error #8");
  30. a.throws(function () { t(/re/); }, RangeError, "Range error #9");
  31. counter = (pow(2, 15) * 3) / 2;
  32. result = [];
  33. while (--counter >= 0) result.push(0); // One code unit per symbol
  34. t.apply(null, result); // Must not throw
  35. counter = (pow(2, 15) * 3) / 2;
  36. result = [];
  37. while (--counter >= 0) result.push(0xffff + 1); // Two code units per symbol
  38. t.apply(null, result); // Must not throw
  39. };