shim.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 () {
  61. t.call(undefined);
  62. }, TypeError);
  63. a.throws(function () {
  64. t.call(undefined, 4);
  65. }, TypeError);
  66. a.throws(function () {
  67. t.call(null);
  68. }, TypeError);
  69. a.throws(function () {
  70. t.call(null, 4);
  71. }, TypeError);
  72. a(t.call(42, 0), 0x34);
  73. a(t.call(42, 1), 0x32);
  74. a(
  75. t.call(
  76. {
  77. toString: function () {
  78. return "abc";
  79. }
  80. },
  81. 2
  82. ),
  83. 0x63
  84. );
  85. a.throws(function () {
  86. t.apply(undefined);
  87. }, TypeError);
  88. a.throws(function () {
  89. t.apply(undefined, [4]);
  90. }, TypeError);
  91. a.throws(function () {
  92. t.apply(null);
  93. }, TypeError);
  94. a.throws(function () {
  95. t.apply(null, [4]);
  96. }, TypeError);
  97. a(t.apply(42, [0]), 0x34);
  98. a(t.apply(42, [1]), 0x32);
  99. a(
  100. t.apply(
  101. {
  102. toString: function () {
  103. return "abc";
  104. }
  105. },
  106. [2]
  107. ),
  108. 0x63
  109. );
  110. };