Skip to content

Commit

Permalink
test updates
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdickinson committed Jan 15, 2015
1 parent 14e8828 commit 2bb6a6a
Show file tree
Hide file tree
Showing 62 changed files with 728 additions and 2,125 deletions.
Original file line number Diff line number Diff line change
@@ -1,24 +1,3 @@
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

var common = require('../common');
var assert = require('assert');
var util = require('util');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,3 @@
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

var common = require('../common');
var assert = require('assert');
var stream = require('../../');
Expand Down
31 changes: 31 additions & 0 deletions test/parallel/test-stream-duplex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
var common = require('../common');
var assert = require('assert');

var Duplex = require('../../').Transform;

var stream = new Duplex({ objectMode: true });

assert(stream._readableState.objectMode);
assert(stream._writableState.objectMode);

var written;
var read;

stream._write = function (obj, _, cb) {
written = obj;
cb();
};

stream._read = function () {};

stream.on('data', function (obj) {
read = obj;
});

stream.push({ val: 1 });
stream.end({ val: 2 });

process.on('exit', function () {
assert(read.val === 1);
assert(written.val === 2);
});
32 changes: 32 additions & 0 deletions test/parallel/test-stream-end-paused.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
var common = require('../common');
var assert = require('assert');
var gotEnd = false;

// Make sure we don't miss the end event for paused 0-length streams

var Readable = require('../../').Readable;
var stream = new Readable();
var calledRead = false;
stream._read = function() {
assert(!calledRead);
calledRead = true;
this.push(null);
};

stream.on('data', function() {
throw new Error('should not ever get data');
});
stream.pause();

setTimeout(function() {
stream.on('end', function() {
gotEnd = true;
});
stream.resume();
});

process.on('exit', function() {
assert(gotEnd);
assert(calledRead);
console.log('ok');
});
23 changes: 23 additions & 0 deletions test/parallel/test-stream-ispaused.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
var assert = require('assert');
var common = require('../common');

var stream = require('../../');

var readable = new stream.Readable;

// _read is a noop, here.
readable._read = Function();

// default state of a stream is not "paused"
assert.ok(!readable.isPaused());

// make the stream start flowing...
readable.on('data', Function());

// still not paused.
assert.ok(!readable.isPaused());

readable.pause();
assert.ok(readable.isPaused());
readable.resume();
assert.ok(!readable.isPaused());
Original file line number Diff line number Diff line change
@@ -1,24 +1,3 @@
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

var common = require('../common');
var assert = require('assert');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,3 @@
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

// This test asserts that Stream.prototype.pipe does not leave listeners
// hanging on the source or dest.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,3 @@
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

var common = require('../common');
var assert = require('assert');
var Stream = require('stream').Stream;
Expand Down
28 changes: 28 additions & 0 deletions test/parallel/test-stream-pipe-event.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
var common = require('../common');
var stream = require('../../');
var assert = require('assert');
var util = require('util');

function Writable() {
this.writable = true;
require('stream').Stream.call(this);
}
util.inherits(Writable, require('stream').Stream);

function Readable() {
this.readable = true;
require('stream').Stream.call(this);
}
util.inherits(Readable, require('stream').Stream);

var passed = false;

var w = new Writable();
w.on('pipe', function(src) {
passed = true;
});

var r = new Readable();
r.pipe(w);

assert.ok(passed);
31 changes: 31 additions & 0 deletions test/parallel/test-stream-push-order.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
var common = require('../common.js');
var Readable = require('../../').Readable;
var assert = require('assert');

var s = new Readable({
highWaterMark: 20,
encoding: 'ascii'
});

var list = ['1', '2', '3', '4', '5', '6'];

s._read = function (n) {
var one = list.shift();
if (!one) {
s.push(null);
} else {
var two = list.shift();
s.push(one);
s.push(two);
}
};

var v = s.read(0);

// ACTUALLY [1, 3, 5, 6, 4, 2]

process.on("exit", function () {
assert.deepEqual(s._readableState.buffer,
['1', '2', '3', '4', '5', '6']);
console.log("ok");
});
45 changes: 45 additions & 0 deletions test/parallel/test-stream-push-strings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
var common = require('../common');
var assert = require('assert');

var Readable = require('../../').Readable;
var util = require('util');

util.inherits(MyStream, Readable);
function MyStream(options) {
Readable.call(this, options);
this._chunks = 3;
}

MyStream.prototype._read = function(n) {
switch (this._chunks--) {
case 0:
return this.push(null);
case 1:
return setTimeout(function() {
this.push('last chunk');
}.bind(this), 100);
case 2:
return this.push('second to last chunk');
case 3:
return process.nextTick(function() {
this.push('first chunk');
}.bind(this));
default:
throw new Error('?');
}
};

var ms = new MyStream();
var results = [];
ms.on('readable', function() {
var chunk;
while (null !== (chunk = ms.read()))
results.push(chunk + '');
});

var expect = [ 'first chunksecond to last chunk', 'last chunk' ];
process.on('exit', function() {
assert.equal(ms._chunks, -1);
assert.deepEqual(results, expect);
console.log('ok');
});
Original file line number Diff line number Diff line change
@@ -1,24 +1,3 @@
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

var common = require('../common');
var assert = require('assert');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,3 @@
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

var common = require('../common');
var assert = require('assert');

Expand Down
Loading

0 comments on commit 2bb6a6a

Please sign in to comment.