test_transducers.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. 'use strict';
  2. const unit = require('heya-unit');
  3. const Chain = require('../index');
  4. const {streamToArray} = require('./helpers');
  5. const {fromIterable} = require('../utils/FromIterable');
  6. unit.add(module, [
  7. function test_transducers(t) {
  8. const async = t.startAsync('test_transducers');
  9. const output = [],
  10. chain = new Chain([fromIterable([1, 2, 3]), [x => x * x, x => 2 * x + 1], streamToArray(output)]);
  11. chain.on('end', () => {
  12. eval(t.TEST('t.unify(output, [3, 9, 19])'));
  13. async.done();
  14. });
  15. },
  16. function test_transducersFinal(t) {
  17. const async = t.startAsync('test_transducersFinal');
  18. const output = [],
  19. chain = new Chain([
  20. fromIterable([1, 2, 3]),
  21. [x => x * x, x => Chain.final(x), x => 2 * x + 1],
  22. streamToArray(output)
  23. ]);
  24. chain.on('end', () => {
  25. eval(t.TEST('t.unify(output, [1, 4, 9])'));
  26. async.done();
  27. });
  28. },
  29. function test_transducersNothing(t) {
  30. const async = t.startAsync('test_transducersNothing');
  31. const output = [],
  32. chain = new Chain([
  33. fromIterable([1, 2, 3]),
  34. [x => x * x, () => Chain.none, x => 2 * x + 1],
  35. streamToArray(output)
  36. ]);
  37. chain.on('end', () => {
  38. eval(t.TEST('t.unify(output, [])'));
  39. async.done();
  40. });
  41. },
  42. function test_transducersEmpty(t) {
  43. const async = t.startAsync('test_transducersEmpty');
  44. const output = [],
  45. chain = new Chain([fromIterable([1, 2, 3]), x => x * x, [], streamToArray(output)]);
  46. chain.on('end', () => {
  47. eval(t.TEST('t.unify(output, [1, 4, 9])'));
  48. async.done();
  49. });
  50. },
  51. function test_transducersOne(t) {
  52. const async = t.startAsync('test_transducersOne');
  53. const output = [],
  54. chain = new Chain([fromIterable([1, 2, 3]), x => x * x, [x => 2 * x + 1], streamToArray(output)]);
  55. chain.on('end', () => {
  56. eval(t.TEST('t.unify(output, [3, 9, 19])'));
  57. async.done();
  58. });
  59. }
  60. ]);