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(+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. };