[Pkg-javascript-commits] [node-stream-splicer] 19/71: passing unshift()
Bastien Roucariès
rouca at moszumanska.debian.org
Fri Dec 15 09:55:48 UTC 2017
This is an automated email from the git hooks/post-receive script.
rouca pushed a commit to branch master
in repository node-stream-splicer.
commit ef466d73528ae0a515bc917740778a5e3a09f2c3
Author: James Halliday <mail at substack.net>
Date: Sun Jun 8 14:30:58 2014 -0700
passing unshift()
---
index.js | 5 +++++
test/unshift.js | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 55 insertions(+)
diff --git a/index.js b/index.js
index 4aa8339..013397e 100644
--- a/index.js
+++ b/index.js
@@ -90,6 +90,11 @@ Pipeline.prototype.shift = function () {
return s;
};
+Pipeline.prototype.unshift = function () {
+ this.splice.apply(this, [0,0].concat([].slice.call(arguments)));
+ return this._streams.length;
+};
+
Pipeline.prototype.splice = function (start, removeLen) {
var self = this;
var len = this._streams.length;
diff --git a/test/unshift.js b/test/unshift.js
new file mode 100644
index 0000000..905779c
--- /dev/null
+++ b/test/unshift.js
@@ -0,0 +1,50 @@
+var pipeline = require('../');
+var through = require('through2');
+var split = require('split');
+var concat = require('concat-stream');
+var test = require('tape');
+
+test('unshift', function (t) {
+ var expected = {};
+ expected.a = [ 5, 6 ];
+ expected.b = [ 3, 4, 500, 600 ];
+ expected.c = [ 13, 14, 510, 610 ];
+ expected.output = [ 13/2, 7, 255, 305 ];
+
+ t.plan(Object.keys(expected).reduce(function (sum, key) {
+ return sum + expected[key].length;
+ }, 0));
+
+ var a = through.obj(function (x, enc, next) {
+ var ex = expected.a.shift();
+ t.equal(x, ex, 'a');
+ this.push(x * 100);
+ next();
+ });
+ var b = through.obj(function (x, enc, next) {
+ var ex = expected.b.shift();
+ t.equal(x, ex, 'b');
+ if (expected.b.length === 2) p.unshift(a)
+ this.push(x + 10);
+ next();
+ });
+ var c = through.obj(function (x, enc, next) {
+ var ex = expected.c.shift();
+ t.equal(x, ex, 'c');
+ this.push(x / 2);
+ next();
+ });
+
+ var p = pipeline.obj([ b, c ]);
+ p.pipe(through.obj(function (x, enc, next) {
+ var ex = expected.output.shift();
+ t.equal(x, ex);
+ next();
+ }));
+
+ p.write(3);
+ p.write(4);
+ p.write(5);
+ p.write(6);
+ p.end();
+});
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-stream-splicer.git
More information about the Pkg-javascript-commits
mailing list