get.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. var pipeline = require('../');
  2. var through = require('through2');
  3. var test = require('tape');
  4. test('get', function (t) {
  5. var a = through.obj();
  6. var b = through.obj();
  7. var c = through.obj();
  8. var pipe = pipeline([ a, b, c ]);
  9. t.equal(pipe.get(0), a, '0');
  10. t.equal(pipe.get(1), b, '1');
  11. t.equal(pipe.get(2), c, '2');
  12. t.equal(pipe.get(3), undefined, '3');
  13. t.equal(pipe.get(4), undefined, '4');
  14. t.equal(pipe.get(5), undefined, '5');
  15. t.equal(pipe.get(-1), c, '-1');
  16. t.equal(pipe.get(-1), c, '-1');
  17. t.equal(pipe.get(-2), b, '-2');
  18. t.equal(pipe.get(-3), a, '-3');
  19. t.equal(pipe.get(-4), undefined, '-4');
  20. t.equal(pipe.get(-5), undefined, '-5');
  21. t.end();
  22. });
  23. test('nested get', function (t) {
  24. var a = through.obj();
  25. var b = through.obj();
  26. var c = through.obj();
  27. var d = through.obj();
  28. var e = through.obj();
  29. var f = through.obj();
  30. var g = through.obj();
  31. var pipe = pipeline([ a, [ b, c, [ d, [ e ], f ] ], g ]);
  32. t.equal(pipe.get(0), a);
  33. t.equal(pipe.get(1, -1, 1, 0), e);
  34. t.equal(pipe.get(1, 3), undefined);
  35. t.equal(pipe.get(4, 3), undefined);
  36. t.end();
  37. });