aboutsummaryrefslogtreecommitdiff
path: root/node_modules/lazystream/test
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2016-10-10 03:43:44 +0200
committerFlorian Dold <florian.dold@gmail.com>2016-10-10 03:43:44 +0200
commitabd94a7f5a50f43c797a11b53549ae48fff667c3 (patch)
treeab8ed457f65cdd72e13e0571d2975729428f1551 /node_modules/lazystream/test
parenta0247c6a3fd6a09a41a7e35a3441324c4dcb58be (diff)
add node_modules to address #4364
Diffstat (limited to 'node_modules/lazystream/test')
-rw-r--r--node_modules/lazystream/test/data.md13
-rw-r--r--node_modules/lazystream/test/fs_test.js69
-rw-r--r--node_modules/lazystream/test/helper.js39
-rw-r--r--node_modules/lazystream/test/pipe_test.js36
-rw-r--r--node_modules/lazystream/test/readable_test.js90
-rw-r--r--node_modules/lazystream/test/writable_test.js59
6 files changed, 306 insertions, 0 deletions
diff --git a/node_modules/lazystream/test/data.md b/node_modules/lazystream/test/data.md
new file mode 100644
index 000000000..fc4822201
--- /dev/null
+++ b/node_modules/lazystream/test/data.md
@@ -0,0 +1,13 @@
+> Never mind, hey, this is really exciting, so much to find out about, so much to
+> look forward to, I'm quite dizzy with anticipation . . . Or is it the wind?
+>
+> There really is a lot of that now, isn't there? And wow! Hey! What's this thing
+> suddenly coming toward me very fast? Very, very fast. So big and flat and round,
+> it needs a big wide-sounding name like . . . ow . . . ound . . . round . . .
+> ground! That's it! That's a good name- ground!
+>
+> I wonder if it will be friends with me?
+>
+> Hello Ground!
+
+And the rest, after a sudden wet thud, was silence.
diff --git a/node_modules/lazystream/test/fs_test.js b/node_modules/lazystream/test/fs_test.js
new file mode 100644
index 000000000..149b1c4a0
--- /dev/null
+++ b/node_modules/lazystream/test/fs_test.js
@@ -0,0 +1,69 @@
+
+var stream = require('../lib/lazystream');
+var fs = require('fs');
+var tmpDir = 'test/tmp/';
+var readFile = 'test/data.md';
+var writeFile = tmpDir + 'data.md';
+
+exports.fs = {
+ readwrite: function(test) {
+ var readfd, writefd;
+
+ var readable = new stream.Readable(function() {
+ return fs.createReadStream(readFile)
+ .on('open', function(fd) {
+ readfd = fd;
+ })
+ .on('close', function() {
+ readfd = undefined;
+ step();
+ });
+ });
+
+ var writable = new stream.Writable(function() {
+ return fs.createWriteStream(writeFile)
+ .on('open', function(fd) {
+ writefd = fd;
+ })
+ .on('close', function() {
+ writefd = undefined;
+ step();
+ });
+ });
+
+ test.expect(3);
+
+ test.equal(readfd, undefined, 'Input file should not be opened until read');
+ test.equal(writefd, undefined, 'Output file should not be opened until write');
+
+ if (!fs.existsSync(tmpDir)) {
+ fs.mkdirSync(tmpDir);
+ }
+ if (fs.existsSync(writeFile)) {
+ fs.unlinkSync(writeFile);
+ }
+
+ readable.on('end', function() { step(); });
+ writable.on('end', function() { step(); });
+
+ var steps = 0;
+ function step() {
+ steps += 1;
+ if (steps == 4) {
+ var input = fs.readFileSync(readFile);
+ var output = fs.readFileSync(writeFile);
+
+ test.ok(input >= output && input <= output, 'Should be equal');
+
+ fs.unlinkSync(writeFile);
+ fs.rmdirSync(tmpDir);
+
+ test.done();
+ }
+ };
+
+ readable.pipe(writable);
+ }
+};
+
+
diff --git a/node_modules/lazystream/test/helper.js b/node_modules/lazystream/test/helper.js
new file mode 100644
index 000000000..9d41191da
--- /dev/null
+++ b/node_modules/lazystream/test/helper.js
@@ -0,0 +1,39 @@
+
+var _Readable = require('readable-stream/readable');
+var _Writable = require('readable-stream/writable');
+var util = require('util');
+
+module.exports = {
+ DummyReadable: DummyReadable,
+ DummyWritable: DummyWritable
+};
+
+function DummyReadable(strings) {
+ _Readable.call(this);
+ this.strings = strings;
+ this.emit('readable');
+}
+
+util.inherits(DummyReadable, _Readable);
+
+DummyReadable.prototype._read = function _read(n) {
+ if (this.strings.length) {
+ this.push(new Buffer(this.strings.shift()));
+ } else {
+ this.push(null);
+ }
+};
+
+function DummyWritable(strings) {
+ _Writable.call(this);
+ this.strings = strings;
+ this.emit('writable');
+}
+
+util.inherits(DummyWritable, _Writable);
+
+DummyWritable.prototype._write = function _write(chunk, encoding, callback) {
+ this.strings.push(chunk.toString());
+ if (callback) callback();
+};
+
diff --git a/node_modules/lazystream/test/pipe_test.js b/node_modules/lazystream/test/pipe_test.js
new file mode 100644
index 000000000..7129e3591
--- /dev/null
+++ b/node_modules/lazystream/test/pipe_test.js
@@ -0,0 +1,36 @@
+
+var stream = require('../lib/lazystream');
+var helper = require('./helper');
+
+exports.pipe = {
+ readwrite: function(test) {
+ var expected = [ 'line1\n', 'line2\n' ];
+ var actual = [];
+ var readableInstantiated = false;
+ var writableInstantiated = false;
+
+ test.expect(3);
+
+ var readable = new stream.Readable(function() {
+ readableInstantiated = true;
+ return new helper.DummyReadable([].concat(expected));
+ });
+
+ var writable = new stream.Writable(function() {
+ writableInstantiated = true;
+ return new helper.DummyWritable(actual);
+ });
+
+ test.equal(readableInstantiated, false, 'DummyReadable should only be instantiated when it is needed');
+ test.equal(writableInstantiated, false, 'DummyWritable should only be instantiated when it is needed');
+
+ writable.on('end', function() {
+ test.equal(actual.join(''), expected.join(''), 'Piping on demand streams should keep data intact');
+ test.done();
+ });
+
+ readable.pipe(writable);
+ }
+};
+
+
diff --git a/node_modules/lazystream/test/readable_test.js b/node_modules/lazystream/test/readable_test.js
new file mode 100644
index 000000000..9ae06368d
--- /dev/null
+++ b/node_modules/lazystream/test/readable_test.js
@@ -0,0 +1,90 @@
+
+var Readable = require('../lib/lazystream').Readable;
+var DummyReadable = require('./helper').DummyReadable;
+
+exports.readable = {
+ dummy: function(test) {
+ var expected = [ 'line1\n', 'line2\n' ];
+ var actual = [];
+
+ test.expect(1);
+
+ new DummyReadable([].concat(expected))
+ .on('data', function(chunk) {
+ actual.push(chunk.toString());
+ })
+ .on('end', function() {
+ test.equal(actual.join(''), expected.join(''), 'DummyReadable should produce the data it was created with');
+ test.done();
+ });
+ },
+ options: function(test) {
+ test.expect(3);
+
+ var readable = new Readable(function(options) {
+ test.ok(this instanceof Readable, "Readable should bind itself to callback's this");
+ test.equal(options.encoding, "utf-8", "Readable should make options accessible to callback");
+ this.ok = true;
+ return new DummyReadable(["test"]);
+ }, {encoding: "utf-8"});
+
+ readable.read(4);
+
+ test.ok(readable.ok);
+
+ test.done();
+ },
+ streams2: function(test) {
+ var expected = [ 'line1\n', 'line2\n' ];
+ var actual = [];
+ var instantiated = false;
+
+ test.expect(2);
+
+ var readable = new Readable(function() {
+ instantiated = true;
+ return new DummyReadable([].concat(expected));
+ });
+
+ test.equal(instantiated, false, 'DummyReadable should only be instantiated when it is needed');
+
+ readable.on('readable', function() {
+ var chunk;
+ while ((chunk = readable.read())) {
+ actual.push(chunk.toString());
+ }
+ });
+ readable.on('end', function() {
+ test.equal(actual.join(''), expected.join(''), 'Readable should not change the data of the underlying stream');
+ test.done();
+ });
+
+ readable.read(0);
+ },
+ resume: function(test) {
+ var expected = [ 'line1\n', 'line2\n' ];
+ var actual = [];
+ var instantiated = false;
+
+ test.expect(2);
+
+ var readable = new Readable(function() {
+ instantiated = true;
+ return new DummyReadable([].concat(expected));
+ });
+
+ readable.pause();
+
+ readable.on('data', function(chunk) {
+ actual.push(chunk.toString());
+ });
+ readable.on('end', function() {
+ test.equal(actual.join(''), expected.join(''), 'Readable should not change the data of the underlying stream');
+ test.done();
+ });
+
+ test.equal(instantiated, false, 'DummyReadable should only be instantiated when it is needed');
+
+ readable.resume();
+ }
+};
diff --git a/node_modules/lazystream/test/writable_test.js b/node_modules/lazystream/test/writable_test.js
new file mode 100644
index 000000000..a66384564
--- /dev/null
+++ b/node_modules/lazystream/test/writable_test.js
@@ -0,0 +1,59 @@
+
+var Writable = require('../lib/lazystream').Writable;
+var DummyWritable = require('./helper').DummyWritable;
+
+exports.writable = {
+ options: function(test) {
+ test.expect(3);
+
+ var writable = new Writable(function(options) {
+ test.ok(this instanceof Writable, "Writable should bind itself to callback's this");
+ test.equal(options.encoding, "utf-8", "Writable should make options accessible to callback");
+ this.ok = true;
+ return new DummyWritable([]);
+ }, {encoding: "utf-8"});
+
+ writable.write("test");
+
+ test.ok(writable.ok);
+
+ test.done();
+ },
+ dummy: function(test) {
+ var expected = [ 'line1\n', 'line2\n' ];
+ var actual = [];
+
+ test.expect(0);
+
+ var dummy = new DummyWritable(actual);
+
+ expected.forEach(function(item) {
+ dummy.write(new Buffer(item));
+ });
+ test.done();
+ },
+ streams2: function(test) {
+ var expected = [ 'line1\n', 'line2\n' ];
+ var actual = [];
+ var instantiated = false;
+
+ test.expect(2);
+
+ var writable = new Writable(function() {
+ instantiated = true;
+ return new DummyWritable(actual);
+ });
+
+ test.equal(instantiated, false, 'DummyWritable should only be instantiated when it is needed');
+
+ writable.on('end', function() {
+ test.equal(actual.join(''), expected.join(''), 'Writable should not change the data of the underlying stream');
+ test.done();
+ });
+
+ expected.forEach(function(item) {
+ writable.write(new Buffer(item));
+ });
+ writable.end();
+ }
+};