shim.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Taken from: https://github.com/mathiasbynens/String.prototype.codePointAt
  2. // /blob/master/tests/tests.js
  3. 'use strict';
  4. module.exports = function (t, a) {
  5. a(t.length, 1, "Length");
  6. // String that starts with a BMP symbol
  7. a(t.call('abc\uD834\uDF06def', ''), 0x61);
  8. a(t.call('abc\uD834\uDF06def', '_'), 0x61);
  9. a(t.call('abc\uD834\uDF06def'), 0x61);
  10. a(t.call('abc\uD834\uDF06def', -Infinity), undefined);
  11. a(t.call('abc\uD834\uDF06def', -1), undefined);
  12. a(t.call('abc\uD834\uDF06def', -0), 0x61);
  13. a(t.call('abc\uD834\uDF06def', 0), 0x61);
  14. a(t.call('abc\uD834\uDF06def', 3), 0x1D306);
  15. a(t.call('abc\uD834\uDF06def', 4), 0xDF06);
  16. a(t.call('abc\uD834\uDF06def', 5), 0x64);
  17. a(t.call('abc\uD834\uDF06def', 42), undefined);
  18. a(t.call('abc\uD834\uDF06def', Infinity), undefined);
  19. a(t.call('abc\uD834\uDF06def', Infinity), undefined);
  20. a(t.call('abc\uD834\uDF06def', NaN), 0x61);
  21. a(t.call('abc\uD834\uDF06def', false), 0x61);
  22. a(t.call('abc\uD834\uDF06def', null), 0x61);
  23. a(t.call('abc\uD834\uDF06def', undefined), 0x61);
  24. // String that starts with an astral symbol
  25. a(t.call('\uD834\uDF06def', ''), 0x1D306);
  26. a(t.call('\uD834\uDF06def', '1'), 0xDF06);
  27. a(t.call('\uD834\uDF06def', '_'), 0x1D306);
  28. a(t.call('\uD834\uDF06def'), 0x1D306);
  29. a(t.call('\uD834\uDF06def', -1), undefined);
  30. a(t.call('\uD834\uDF06def', -0), 0x1D306);
  31. a(t.call('\uD834\uDF06def', 0), 0x1D306);
  32. a(t.call('\uD834\uDF06def', 1), 0xDF06);
  33. a(t.call('\uD834\uDF06def', 42), undefined);
  34. a(t.call('\uD834\uDF06def', false), 0x1D306);
  35. a(t.call('\uD834\uDF06def', null), 0x1D306);
  36. a(t.call('\uD834\uDF06def', undefined), 0x1D306);
  37. // Lone high surrogates
  38. a(t.call('\uD834abc', ''), 0xD834);
  39. a(t.call('\uD834abc', '_'), 0xD834);
  40. a(t.call('\uD834abc'), 0xD834);
  41. a(t.call('\uD834abc', -1), undefined);
  42. a(t.call('\uD834abc', -0), 0xD834);
  43. a(t.call('\uD834abc', 0), 0xD834);
  44. a(t.call('\uD834abc', false), 0xD834);
  45. a(t.call('\uD834abc', NaN), 0xD834);
  46. a(t.call('\uD834abc', null), 0xD834);
  47. a(t.call('\uD834abc', undefined), 0xD834);
  48. // Lone low surrogates
  49. a(t.call('\uDF06abc', ''), 0xDF06);
  50. a(t.call('\uDF06abc', '_'), 0xDF06);
  51. a(t.call('\uDF06abc'), 0xDF06);
  52. a(t.call('\uDF06abc', -1), undefined);
  53. a(t.call('\uDF06abc', -0), 0xDF06);
  54. a(t.call('\uDF06abc', 0), 0xDF06);
  55. a(t.call('\uDF06abc', false), 0xDF06);
  56. a(t.call('\uDF06abc', NaN), 0xDF06);
  57. a(t.call('\uDF06abc', null), 0xDF06);
  58. a(t.call('\uDF06abc', undefined), 0xDF06);
  59. a.throws(function () { t.call(undefined); }, TypeError);
  60. a.throws(function () { t.call(undefined, 4); }, TypeError);
  61. a.throws(function () { t.call(null); }, TypeError);
  62. a.throws(function () { t.call(null, 4); }, TypeError);
  63. a(t.call(42, 0), 0x34);
  64. a(t.call(42, 1), 0x32);
  65. a(t.call({ toString: function () { return 'abc'; } }, 2), 0x63);
  66. a.throws(function () { t.apply(undefined); }, TypeError);
  67. a.throws(function () { t.apply(undefined, [4]); }, TypeError);
  68. a.throws(function () { t.apply(null); }, TypeError);
  69. a.throws(function () { t.apply(null, [4]); }, TypeError);
  70. a(t.apply(42, [0]), 0x34);
  71. a(t.apply(42, [1]), 0x32);
  72. a(t.apply({ toString: function () { return 'abc'; } }, [2]), 0x63);
  73. };