39f5fe4a9741e7e657a51dfd0d1cb559b985a9ea9f6e166f651baf3b2ca75c07ece6efb3c022176502f818743d1c81783b78f22265606c97567311ad361bee 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. 'use strict';
  2. var inspect = require('object-inspect');
  3. // var IsDetachedBuffer = require('es-abstract/2023/IsDetachedBuffer');
  4. var forEach = require('for-each');
  5. var availableTypedArrays = require('available-typed-arrays')();
  6. var v = require('es-value-fixtures');
  7. module.exports = function runTests(slice, t) {
  8. forEach(v.primitives.concat(v.objects), function (nonTA) {
  9. t['throws'](
  10. function () { slice(nonTA); },
  11. TypeError,
  12. inspect(nonTA) + ' is not a Typed Array'
  13. );
  14. });
  15. t.test('Typed Arrays', { skip: availableTypedArrays.length === 0 }, function (st) {
  16. forEach(availableTypedArrays, function (name) {
  17. st.test(name, function (s2t) {
  18. var TA = global[name];
  19. var isBigInt = name.slice(0, 3) === 'Big';
  20. var ta = new TA(isBigInt ? [BigInt(1), BigInt(2), BigInt(3)] : [1, 2, 3]);
  21. var copy = slice(ta);
  22. s2t.notEqual(copy, ta, 'returns a new instance when sliced with no args');
  23. s2t.ok(copy instanceof TA, 'returns an instance of the same type when sliced with no args');
  24. s2t.deepEqual(copy, ta, 'returns a new instance with the same values when sliced with no args');
  25. s2t.notEqual(copy.buffer, ta.buffer, 'the new instance has a different buffer than the original when sliced with no args');
  26. var subset = slice(ta, 1);
  27. s2t.notEqual(subset, ta, 'returns a new instance when sliced with a start index');
  28. s2t.ok(copy instanceof TA, 'returns an instance of the same type when sliced with a start index');
  29. s2t.deepEqual(
  30. subset,
  31. new TA(isBigInt ? [BigInt(2), BigInt(3)] : [2, 3]),
  32. 'returns a new instance with the expected subset of values when sliced with a start index'
  33. );
  34. s2t.notEqual(copy.buffer, ta.buffer, 'the new instance has a different buffer than the original when sliced with a start index');
  35. s2t.end();
  36. });
  37. });
  38. return st.end();
  39. });
  40. };