unify.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. 'use strict';
  2. var ee = require('../');
  3. module.exports = function (t) {
  4. return {
  5. "": function (a) {
  6. var x = {}, y = {}, z = {}, count, count2, count3;
  7. ee(x);
  8. ee(y);
  9. ee(z);
  10. count = 0;
  11. count2 = 0;
  12. count3 = 0;
  13. x.on('foo', function () { ++count; });
  14. y.on('foo', function () { ++count2; });
  15. z.on('foo', function () { ++count3; });
  16. x.emit('foo');
  17. a(count, 1, "Pre unify, x");
  18. a(count2, 0, "Pre unify, y");
  19. a(count3, 0, "Pre unify, z");
  20. t(x, y);
  21. a(x.__ee__, y.__ee__, "Post unify y");
  22. x.emit('foo');
  23. a(count, 2, "Post unify, x");
  24. a(count2, 1, "Post unify, y");
  25. a(count3, 0, "Post unify, z");
  26. y.emit('foo');
  27. a(count, 3, "Post unify, on y, x");
  28. a(count2, 2, "Post unify, on y, y");
  29. a(count3, 0, "Post unify, on y, z");
  30. t(x, z);
  31. a(x.__ee__, x.__ee__, "Post unify z");
  32. x.emit('foo');
  33. a(count, 4, "Post unify z, x");
  34. a(count2, 3, "Post unify z, y");
  35. a(count3, 1, "Post unify z, z");
  36. },
  37. "On empty": function (a) {
  38. var x = {}, y = {}, z = {}, count, count2, count3;
  39. ee(x);
  40. ee(y);
  41. ee(z);
  42. count = 0;
  43. count2 = 0;
  44. count3 = 0;
  45. y.on('foo', function () { ++count2; });
  46. x.emit('foo');
  47. a(count, 0, "Pre unify, x");
  48. a(count2, 0, "Pre unify, y");
  49. a(count3, 0, "Pre unify, z");
  50. t(x, y);
  51. a(x.__ee__, y.__ee__, "Post unify y");
  52. x.on('foo', function () { ++count; });
  53. x.emit('foo');
  54. a(count, 1, "Post unify, x");
  55. a(count2, 1, "Post unify, y");
  56. a(count3, 0, "Post unify, z");
  57. y.emit('foo');
  58. a(count, 2, "Post unify, on y, x");
  59. a(count2, 2, "Post unify, on y, y");
  60. a(count3, 0, "Post unify, on y, z");
  61. t(x, z);
  62. a(x.__ee__, z.__ee__, "Post unify z");
  63. z.on('foo', function () { ++count3; });
  64. x.emit('foo');
  65. a(count, 3, "Post unify z, x");
  66. a(count2, 3, "Post unify z, y");
  67. a(count3, 1, "Post unify z, z");
  68. },
  69. Many: function (a) {
  70. var x = {}, y = {}, z = {}, count, count2, count3;
  71. ee(x);
  72. ee(y);
  73. ee(z);
  74. count = 0;
  75. count2 = 0;
  76. count3 = 0;
  77. x.on('foo', function () { ++count; });
  78. y.on('foo', function () { ++count2; });
  79. y.on('foo', function () { ++count2; });
  80. z.on('foo', function () { ++count3; });
  81. x.emit('foo');
  82. a(count, 1, "Pre unify, x");
  83. a(count2, 0, "Pre unify, y");
  84. a(count3, 0, "Pre unify, z");
  85. t(x, y);
  86. a(x.__ee__, y.__ee__, "Post unify y");
  87. x.emit('foo');
  88. a(count, 2, "Post unify, x");
  89. a(count2, 2, "Post unify, y");
  90. a(count3, 0, "Post unify, z");
  91. y.emit('foo');
  92. a(count, 3, "Post unify, on y, x");
  93. a(count2, 4, "Post unify, on y, y");
  94. a(count3, 0, "Post unify, on y, z");
  95. t(x, z);
  96. a(x.__ee__, x.__ee__, "Post unify z");
  97. x.emit('foo');
  98. a(count, 4, "Post unify z, x");
  99. a(count2, 6, "Post unify z, y");
  100. a(count3, 1, "Post unify z, z");
  101. }
  102. };
  103. };