shimmed.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. 'use strict';
  2. require('../auto');
  3. var test = require('tape');
  4. var forEach = require('for-each');
  5. var shims = require('../');
  6. forEach(shims, function (shim) {
  7. var shimTests;
  8. try {
  9. shimTests = require('./' + shim); // eslint-disable-line global-require
  10. } catch (e) {
  11. test(shim + ': shimmed', { todo: true });
  12. }
  13. if (shimTests) {
  14. shimTests.shimmed();
  15. }
  16. });
  17. test('integration', function (t) {
  18. var seenMapEveryMap = [];
  19. var seenMapEveryEvery = [];
  20. var mapEveryResult = Iterator.from([1, 2, 3, 4, 5]).map(function (x) {
  21. seenMapEveryMap.push(x);
  22. return x * x;
  23. }).every(function (x) {
  24. seenMapEveryEvery.push(x);
  25. return x < 10;
  26. });
  27. t.equal(mapEveryResult, false, 'map + every: every predicate returned false nonzero times');
  28. t.deepEqual(seenMapEveryMap, [1, 2, 3, 4], 'map + every, map: all values are seen until after the first one that is > 10 when squared');
  29. t.deepEqual(seenMapEveryEvery, [1, 4, 9, 16], 'map + every, every: all values are seen until after the first one that is > 10 when squared');
  30. var seenMapSomeMap = [];
  31. var seenMapSomeSome = [];
  32. var mapSomeResult = Iterator.from([1, 2, 3, 4, 5]).map(function (x) {
  33. seenMapSomeMap.push(x);
  34. return x * x;
  35. }).some(function (x) {
  36. seenMapSomeSome.push(x);
  37. return x > 10;
  38. });
  39. t.equal(mapSomeResult, true, 'map + some: some predicate returned true nonzero times');
  40. t.deepEqual(seenMapSomeMap, [1, 2, 3, 4], 'map + some, map: all values are seen until after the first one that is > 10 when squared');
  41. t.deepEqual(seenMapSomeSome, [1, 4, 9, 16], 'map + some, some: all values are seen until after the first one that is > 10 when squared');
  42. var seenMapFind = [];
  43. var mapFindResult = Iterator.from([1, 2, 3, 4, 5]).map(function (x) {
  44. seenMapFind.push(x);
  45. return x * x;
  46. }).find(function (x) {
  47. return x > 10;
  48. });
  49. t.equal(mapFindResult, 16, 'map + find: find found the first mapped value over 10');
  50. t.deepEqual(seenMapFind, [1, 2, 3, 4], 'map + find: all values are seen until after the first one that is > 10 when squared');
  51. var seenFilterEvery = [];
  52. var filterEveryResult = Iterator.from([1, 2, 3, 4, 5]).filter(function (x) {
  53. seenFilterEvery.push(x);
  54. return x;
  55. }).every(function (x) {
  56. return x <= 3;
  57. });
  58. t.equal(filterEveryResult, false, 'filter + every: every predicate returned false nonzero times');
  59. t.deepEqual(seenMapFind, [1, 2, 3, 4], 'filter + every: all values are seen until after the first one that is > 10 when squared');
  60. t.end();
  61. });