shim.js 3.1 KB

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