1
0

at.js 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // See tests at https://github.com/mathiasbynens/String.prototype.at
  2. 'use strict';
  3. module.exports = function (t, a) {
  4. a(t.length, 1, "Length");
  5. a.h1("BMP");
  6. a(t.call('abc\uD834\uDF06def', -Infinity), '', "-Infinity");
  7. a(t.call('abc\uD834\uDF06def', -1), '', "-1");
  8. a(t.call('abc\uD834\uDF06def', -0), 'a', "-0");
  9. a(t.call('abc\uD834\uDF06def', +0), 'a', "+0");
  10. a(t.call('abc\uD834\uDF06def', 1), 'b', "1");
  11. a(t.call('abc\uD834\uDF06def', 3), '\uD834\uDF06', "3");
  12. a(t.call('abc\uD834\uDF06def', 4), '\uDF06', "4");
  13. a(t.call('abc\uD834\uDF06def', 5), 'd', "5");
  14. a(t.call('abc\uD834\uDF06def', 42), '', "42");
  15. a(t.call('abc\uD834\uDF06def', +Infinity), '', "+Infinity");
  16. a(t.call('abc\uD834\uDF06def', null), 'a', "null");
  17. a(t.call('abc\uD834\uDF06def', undefined), 'a', "undefined");
  18. a(t.call('abc\uD834\uDF06def'), 'a', "No argument");
  19. a(t.call('abc\uD834\uDF06def', false), 'a', "false");
  20. a(t.call('abc\uD834\uDF06def', NaN), 'a', "NaN");
  21. a(t.call('abc\uD834\uDF06def', ''), 'a', "Empty string");
  22. a(t.call('abc\uD834\uDF06def', '_'), 'a', "_");
  23. a(t.call('abc\uD834\uDF06def', '1'), 'b', "'1'");
  24. a(t.call('abc\uD834\uDF06def', []), 'a', "[]");
  25. a(t.call('abc\uD834\uDF06def', {}), 'a', "{}");
  26. a(t.call('abc\uD834\uDF06def', -0.9), 'a', "-0.9");
  27. a(t.call('abc\uD834\uDF06def', 1.9), 'b', "1.9");
  28. a(t.call('abc\uD834\uDF06def', 7.9), 'f', "7.9");
  29. a(t.call('abc\uD834\uDF06def', Math.pow(2, 32)), '', "Big number");
  30. a.h1("Astral symbol");
  31. a(t.call('\uD834\uDF06def', -Infinity), '', "-Infinity");
  32. a(t.call('\uD834\uDF06def', -1), '', "-1");
  33. a(t.call('\uD834\uDF06def', -0), '\uD834\uDF06', "-0");
  34. a(t.call('\uD834\uDF06def', +0), '\uD834\uDF06', "+0");
  35. a(t.call('\uD834\uDF06def', 1), '\uDF06', "1");
  36. a(t.call('\uD834\uDF06def', 2), 'd', "2");
  37. a(t.call('\uD834\uDF06def', 3), 'e', "3");
  38. a(t.call('\uD834\uDF06def', 4), 'f', "4");
  39. a(t.call('\uD834\uDF06def', 42), '', "42");
  40. a(t.call('\uD834\uDF06def', +Infinity), '', "+Infinity");
  41. a(t.call('\uD834\uDF06def', null), '\uD834\uDF06', "null");
  42. a(t.call('\uD834\uDF06def', undefined), '\uD834\uDF06', "undefined");
  43. a(t.call('\uD834\uDF06def'), '\uD834\uDF06', "No arguments");
  44. a(t.call('\uD834\uDF06def', false), '\uD834\uDF06', "false");
  45. a(t.call('\uD834\uDF06def', NaN), '\uD834\uDF06', "NaN");
  46. a(t.call('\uD834\uDF06def', ''), '\uD834\uDF06', "Empty string");
  47. a(t.call('\uD834\uDF06def', '_'), '\uD834\uDF06', "_");
  48. a(t.call('\uD834\uDF06def', '1'), '\uDF06', "'1'");
  49. a.h1("Lone high surrogates");
  50. a(t.call('\uD834abc', -Infinity), '', "-Infinity");
  51. a(t.call('\uD834abc', -1), '', "-1");
  52. a(t.call('\uD834abc', -0), '\uD834', "-0");
  53. a(t.call('\uD834abc', +0), '\uD834', "+0");
  54. a(t.call('\uD834abc', 1), 'a', "1");
  55. a(t.call('\uD834abc', 42), '', "42");
  56. a(t.call('\uD834abc', +Infinity), '', "Infinity");
  57. a(t.call('\uD834abc', null), '\uD834', "null");
  58. a(t.call('\uD834abc', undefined), '\uD834', "undefined");
  59. a(t.call('\uD834abc'), '\uD834', "No arguments");
  60. a(t.call('\uD834abc', false), '\uD834', "false");
  61. a(t.call('\uD834abc', NaN), '\uD834', "NaN");
  62. a(t.call('\uD834abc', ''), '\uD834', "Empty string");
  63. a(t.call('\uD834abc', '_'), '\uD834', "_");
  64. a(t.call('\uD834abc', '1'), 'a', "'a'");
  65. a.h1("Lone low surrogates");
  66. a(t.call('\uDF06abc', -Infinity), '', "-Infinity");
  67. a(t.call('\uDF06abc', -1), '', "-1");
  68. a(t.call('\uDF06abc', -0), '\uDF06', "-0");
  69. a(t.call('\uDF06abc', +0), '\uDF06', "+0");
  70. a(t.call('\uDF06abc', 1), 'a', "1");
  71. a(t.call('\uDF06abc', 42), '', "42");
  72. a(t.call('\uDF06abc', +Infinity), '', "+Infinity");
  73. a(t.call('\uDF06abc', null), '\uDF06', "null");
  74. a(t.call('\uDF06abc', undefined), '\uDF06', "undefined");
  75. a(t.call('\uDF06abc'), '\uDF06', "No arguments");
  76. a(t.call('\uDF06abc', false), '\uDF06', "false");
  77. a(t.call('\uDF06abc', NaN), '\uDF06', "NaN");
  78. a(t.call('\uDF06abc', ''), '\uDF06', "Empty string");
  79. a(t.call('\uDF06abc', '_'), '\uDF06', "_");
  80. a(t.call('\uDF06abc', '1'), 'a', "'1'");
  81. a.h1("Context");
  82. a.throws(function () { t.call(undefined); }, TypeError, "Undefined");
  83. a.throws(function () { t.call(undefined, 4); }, TypeError,
  84. "Undefined + argument");
  85. a.throws(function () { t.call(null); }, TypeError, "Null");
  86. a.throws(function () { t.call(null, 4); }, TypeError, "Null + argument");
  87. a(t.call(42, 0), '4', "Number #1");
  88. a(t.call(42, 1), '2', "Number #2");
  89. a(t.call({ toString: function () { return 'abc'; } }, 2), 'c', "Object");
  90. };