1
0

index.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. 'use strict';
  2. var ee = require('event-emitter')
  3. , iteratorSymbol = require('es6-symbol').iterator;
  4. module.exports = function (T) {
  5. return {
  6. "": function (a) {
  7. var x = ['raz', 'dwa', 'trzy', 'cztery', 'pięć'], it, y, z;
  8. it = new T(x);
  9. a(it[iteratorSymbol](), it, "@@iterator");
  10. y = it.next();
  11. a.deep(y, { done: false, value: 'raz' }, "#1");
  12. z = it.next();
  13. a.not(y, z, "Recreate result");
  14. a.deep(z, { done: false, value: 'dwa' }, "#2");
  15. a.deep(it.next(), { done: false, value: 'trzy' }, "#3");
  16. a.deep(it.next(), { done: false, value: 'cztery' }, "#4");
  17. a.deep(it.next(), { done: false, value: 'pięć' }, "#5");
  18. a.deep(y = it.next(), { done: true, value: undefined }, "End");
  19. a.not(y, it.next(), "Recreate result on dead");
  20. },
  21. Emited: function (a) {
  22. var x = ['raz', 'dwa', 'trzy', 'cztery', 'pięć'], y, it;
  23. y = ee();
  24. it = new T(x, y);
  25. a.deep(it.next(), { done: false, value: 'raz' }, "#1");
  26. a.deep(it.next(), { done: false, value: 'dwa' }, "#2");
  27. y.emit('_add', x.push('sześć') - 1);
  28. a.deep(it.next(), { done: false, value: 'trzy' }, "#3");
  29. x.splice(1, 0, 'półtora');
  30. y.emit('_add', 1);
  31. a.deep(it.next(), { done: false, value: 'półtora' }, "Insert");
  32. x.splice(5, 1);
  33. y.emit('_delete', 5);
  34. a.deep(it.next(), { done: false, value: 'cztery' }, "#4");
  35. a.deep(it.next(), { done: false, value: 'sześć' }, "#5");
  36. a.deep(it.next(), { done: true, value: undefined }, "End");
  37. },
  38. "Emited #2": function (a) {
  39. var x = ['raz', 'dwa', 'trzy', 'cztery', 'pięć', 'sześć'], y, it;
  40. y = ee();
  41. it = new T(x, y);
  42. a.deep(it.next(), { done: false, value: 'raz' }, "#1");
  43. a.deep(it.next(), { done: false, value: 'dwa' }, "#2");
  44. x.splice(1, 0, 'półtora');
  45. y.emit('_add', 1);
  46. x.splice(1, 0, '1.25');
  47. y.emit('_add', 1);
  48. x.splice(0, 1);
  49. y.emit('_delete', 0);
  50. a.deep(it.next(), { done: false, value: 'półtora' }, "Insert");
  51. a.deep(it.next(), { done: false, value: '1.25' }, "Insert #2");
  52. a.deep(it.next(), { done: false, value: 'trzy' }, "#3");
  53. a.deep(it.next(), { done: false, value: 'cztery' }, "#4");
  54. x.splice(5, 1);
  55. y.emit('_delete', 5);
  56. a.deep(it.next(), { done: false, value: 'sześć' }, "#5");
  57. a.deep(it.next(), { done: true, value: undefined }, "End");
  58. },
  59. "Emited: Clear #1": function (a) {
  60. var x = ['raz', 'dwa', 'trzy', 'cztery', 'pięć', 'sześć'], y, it;
  61. y = ee();
  62. it = new T(x, y);
  63. a.deep(it.next(), { done: false, value: 'raz' }, "#1");
  64. a.deep(it.next(), { done: false, value: 'dwa' }, "#2");
  65. x.length = 0;
  66. y.emit('_clear');
  67. a.deep(it.next(), { done: true, value: undefined }, "End");
  68. },
  69. "Emited: Clear #2": function (a) {
  70. var x = ['raz', 'dwa', 'trzy', 'cztery', 'pięć', 'sześć'], y, it;
  71. y = ee();
  72. it = new T(x, y);
  73. a.deep(it.next(), { done: false, value: 'raz' }, "#1");
  74. a.deep(it.next(), { done: false, value: 'dwa' }, "#2");
  75. x.length = 0;
  76. y.emit('_clear');
  77. x.push('foo');
  78. x.push('bar');
  79. a.deep(it.next(), { done: false, value: 'foo' }, "#3");
  80. a.deep(it.next(), { done: false, value: 'bar' }, "#4");
  81. x.splice(1, 0, 'półtora');
  82. y.emit('_add', 1);
  83. x.splice(1, 0, '1.25');
  84. y.emit('_add', 1);
  85. x.splice(0, 1);
  86. y.emit('_delete', 0);
  87. a.deep(it.next(), { done: false, value: 'półtora' }, "Insert");
  88. a.deep(it.next(), { done: false, value: '1.25' }, "Insert #2");
  89. a.deep(it.next(), { done: true, value: undefined }, "End");
  90. }
  91. };
  92. };