| @@ -701,8 +701,8 @@ | ||
|
|
||
| var nativeModule = new NativeModule(id); | ||
|
|
||
| nativeModule.cache(); | ||
| nativeModule.compile(); | ||
|
|
||
| return nativeModule.exports; | ||
| }; | ||
| @@ -0,0 +1,51 @@ | ||
| // 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. | ||
|
|
||
| // Hints: | ||
| // This .d defines compiled in probes | ||
| // probes are handles (untyped pointers) | ||
| // v8 forward declared objs (dtrace_connection_t) are defined | ||
| // in node_dtrace.cc which builds an InitDtrace object which | ||
| // gets populated with the probes | ||
| // The probes gather the following: | ||
| // PROBE_REQUEST(req, fd, remote, port, buffered) | ||
| // PROBE_OTHER(fd, remote, port, buffered) | ||
| // other notes: | ||
| // using any PROBE_ENABLED() macros in dtrace.cc sdt broke it | ||
| // can only pass strings/ints/primitives not dtrace_connection_t | ||
| // conn or other structs | ||
| // verify probe existence by using | ||
| // $ stap -l 'process("out/Release/node").mark("*")' | ||
| // TODO: write .stp scripts (node.stp, node_v8ustack.stp + ???) | ||
|
|
||
|
|
||
| provider node { | ||
| probe http__client__request(string, int, string, int, int); | ||
| probe http__client__response(int, string, int, int); | ||
| probe http__server__request(string, int, string, int, int); | ||
| probe http__server__response(int, string, int, int); | ||
| probe net__server__connection(int, string, int, int); | ||
| probe net__socket__read(int, string, int, int); | ||
| probe net__socket__write(int, string, int, int); | ||
| probe net__stream__end(int, string, int, int); | ||
| probe gc__done(); | ||
| probe gc__start(); | ||
| }; |
| @@ -0,0 +1 @@ | ||
| xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
| @@ -0,0 +1,89 @@ | ||
| // 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. | ||
|
|
||
| /* | ||
| * Tests to verify slice functionality of ArrayBuffer. | ||
| * (http://www.khronos.org/registry/typedarray/specs/latest/#5) | ||
| */ | ||
|
|
||
| var common = require('../common'); | ||
| var assert = require('assert'); | ||
|
|
||
| var buffer = new ArrayBuffer(8); | ||
| var sub; | ||
| var i; | ||
|
|
||
| for (var i = 0; i < 8; i++) { | ||
| buffer[i] = i; | ||
| } | ||
|
|
||
| // slice a copy of buffer | ||
| sub = buffer.slice(2, 6); | ||
|
|
||
| // make sure it copied correctly | ||
| assert.ok(sub instanceof ArrayBuffer); | ||
| assert.equal(sub.byteLength, 4); | ||
|
|
||
| for (i = 0; i < 4; i++) { | ||
| assert.equal(sub[i], i+2); | ||
| } | ||
|
|
||
| // modifications to the new slice shouldn't affect the original | ||
| sub[0] = 999; | ||
|
|
||
| for (i = 0; i < 8; i++) { | ||
| assert.equal(buffer[i], i); | ||
| } | ||
|
|
||
| // test optional end param | ||
| sub = buffer.slice(5); | ||
|
|
||
| assert.ok(sub instanceof ArrayBuffer); | ||
| assert.equal(sub.byteLength, 3); | ||
| for (i = 0; i < 3; i++) { | ||
| assert.equal(sub[i], i+5); | ||
| } | ||
|
|
||
| // test clamping | ||
| sub = buffer.slice(-3, -1); | ||
|
|
||
| assert.ok(sub instanceof ArrayBuffer); | ||
| assert.equal(sub.byteLength, 2); | ||
| for (i = 0; i < 2; i++) { | ||
| assert.equal(sub[i], i+5); | ||
| } | ||
|
|
||
| // test invalid clamping range | ||
| sub = buffer.slice(-1, -3); | ||
|
|
||
| assert.ok(sub instanceof ArrayBuffer); | ||
| assert.equal(sub.byteLength, 0); | ||
|
|
||
| // test wrong number of arguments | ||
| var gotError = false; | ||
|
|
||
| try { | ||
| sub = buffer.slice(); | ||
| } catch (e) { | ||
| gotError = true; | ||
| } | ||
|
|
||
| assert.ok(gotError); |
| @@ -31,6 +31,8 @@ if (process.argv[2] === 'child') { | ||
|
|
||
| server.on('connection', function(socket) { | ||
|
|
||
| socket.resume(); | ||
|
|
||
| process.on('disconnect', function() { | ||
| socket.end((process.connected).toString()); | ||
| }); | ||
| @@ -125,6 +125,7 @@ function startClient() { | ||
| }); | ||
| req.write(buffer); | ||
| req.end(); | ||
| console.error('ended request', req); | ||
| } | ||
|
|
||
| process.on('exit', function() { | ||
| @@ -0,0 +1,312 @@ | ||
| // 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.js'); | ||
| var R = require('_stream_readable'); | ||
| var assert = require('assert'); | ||
|
|
||
| var util = require('util'); | ||
| var EE = require('events').EventEmitter; | ||
|
|
||
| function TestReader(n) { | ||
| R.apply(this); | ||
| this._buffer = new Buffer(n || 100); | ||
| this._buffer.fill('x'); | ||
| this._pos = 0; | ||
| this._bufs = 10; | ||
| } | ||
|
|
||
| util.inherits(TestReader, R); | ||
|
|
||
| TestReader.prototype.read = function(n) { | ||
| var max = this._buffer.length - this._pos; | ||
| n = n || max; | ||
| n = Math.max(n, 0); | ||
| var toRead = Math.min(n, max); | ||
| if (toRead === 0) { | ||
| // simulate the read buffer filling up with some more bytes some time | ||
| // in the future. | ||
| setTimeout(function() { | ||
| this._pos = 0; | ||
| this._bufs -= 1; | ||
| if (this._bufs <= 0) { | ||
| // read them all! | ||
| if (!this.ended) { | ||
| this.emit('end'); | ||
| this.ended = true; | ||
| } | ||
| } else { | ||
| this.emit('readable'); | ||
| } | ||
| }.bind(this), 10); | ||
| return null; | ||
| } | ||
|
|
||
| var ret = this._buffer.slice(this._pos, this._pos + toRead); | ||
| this._pos += toRead; | ||
| return ret; | ||
| }; | ||
|
|
||
| ///// | ||
|
|
||
| function TestWriter() { | ||
| EE.apply(this); | ||
| this.received = []; | ||
| this.flush = false; | ||
| } | ||
|
|
||
| util.inherits(TestWriter, EE); | ||
|
|
||
| TestWriter.prototype.write = function(c) { | ||
| this.received.push(c.toString()); | ||
| this.emit('write', c); | ||
| return true; | ||
|
|
||
| // flip back and forth between immediate acceptance and not. | ||
| this.flush = !this.flush; | ||
| if (!this.flush) setTimeout(this.emit.bind(this, 'drain'), 10); | ||
| return this.flush; | ||
| }; | ||
|
|
||
| TestWriter.prototype.end = function(c) { | ||
| if (c) this.write(c); | ||
| this.emit('end', this.received); | ||
| }; | ||
|
|
||
| //////// | ||
|
|
||
| // tiny node-tap lookalike. | ||
| var tests = []; | ||
| function test(name, fn) { | ||
| tests.push([name, fn]); | ||
| } | ||
|
|
||
| function run() { | ||
| var next = tests.shift(); | ||
| if (!next) | ||
| return console.error('ok'); | ||
|
|
||
| var name = next[0]; | ||
| var fn = next[1]; | ||
| console.log('# %s', name); | ||
| fn({ | ||
| same: assert.deepEqual, | ||
| equal: assert.equal, | ||
| end: run | ||
| }); | ||
| } | ||
|
|
||
| process.nextTick(run); | ||
|
|
||
|
|
||
| test('a most basic test', function(t) { | ||
| var r = new TestReader(20); | ||
|
|
||
| var reads = []; | ||
| var expect = [ 'x', | ||
| 'xx', | ||
| 'xxx', | ||
| 'xxxx', | ||
| 'xxxxx', | ||
| 'xxxxx', | ||
| 'xxxxxxxx', | ||
| 'xxxxxxxxx', | ||
| 'xxx', | ||
| 'xxxxxxxxxxxx', | ||
| 'xxxxxxxx', | ||
| 'xxxxxxxxxxxxxxx', | ||
| 'xxxxx', | ||
| 'xxxxxxxxxxxxxxxxxx', | ||
| 'xx', | ||
| 'xxxxxxxxxxxxxxxxxxxx', | ||
| 'xxxxxxxxxxxxxxxxxxxx', | ||
| 'xxxxxxxxxxxxxxxxxxxx', | ||
| 'xxxxxxxxxxxxxxxxxxxx', | ||
| 'xxxxxxxxxxxxxxxxxxxx' ]; | ||
|
|
||
| r.on('end', function() { | ||
| t.same(reads, expect); | ||
| t.end(); | ||
| }); | ||
|
|
||
| var readSize = 1; | ||
| function flow() { | ||
| var res; | ||
| while (null !== (res = r.read(readSize++))) { | ||
| reads.push(res.toString()); | ||
| } | ||
| r.once('readable', flow); | ||
| } | ||
|
|
||
| flow(); | ||
| }); | ||
|
|
||
| test('pipe', function(t) { | ||
| var r = new TestReader(5); | ||
|
|
||
| var expect = [ 'xxxxx', | ||
| 'xxxxx', | ||
| 'xxxxx', | ||
| 'xxxxx', | ||
| 'xxxxx', | ||
| 'xxxxx', | ||
| 'xxxxx', | ||
| 'xxxxx', | ||
| 'xxxxx', | ||
| 'xxxxx' ] | ||
|
|
||
| var w = new TestWriter; | ||
| var flush = true; | ||
| w.on('end', function(received) { | ||
| t.same(received, expect); | ||
| t.end(); | ||
| }); | ||
|
|
||
| r.pipe(w); | ||
| }); | ||
|
|
||
|
|
||
|
|
||
| [1,2,3,4,5,6,7,8,9].forEach(function(SPLIT) { | ||
| test('unpipe', function(t) { | ||
| var r = new TestReader(5); | ||
|
|
||
| // unpipe after 3 writes, then write to another stream instead. | ||
| var expect = [ 'xxxxx', | ||
| 'xxxxx', | ||
| 'xxxxx', | ||
| 'xxxxx', | ||
| 'xxxxx', | ||
| 'xxxxx', | ||
| 'xxxxx', | ||
| 'xxxxx', | ||
| 'xxxxx', | ||
| 'xxxxx' ]; | ||
| expect = [ expect.slice(0, SPLIT), expect.slice(SPLIT) ]; | ||
|
|
||
| var w = [ new TestWriter(), new TestWriter() ]; | ||
|
|
||
| var writes = SPLIT; | ||
| w[0].on('write', function() { | ||
| if (--writes === 0) { | ||
| r.unpipe(); | ||
| w[0].end(); | ||
| r.pipe(w[1]); | ||
| } | ||
| }); | ||
|
|
||
| var ended = 0; | ||
|
|
||
| w[0].on('end', function(results) { | ||
| ended++; | ||
| t.same(results, expect[0]); | ||
| }); | ||
|
|
||
| w[1].on('end', function(results) { | ||
| ended++; | ||
| t.equal(ended, 2); | ||
| t.same(results, expect[1]); | ||
| t.end(); | ||
| }); | ||
|
|
||
| r.pipe(w[0]); | ||
| }); | ||
| }); | ||
|
|
||
|
|
||
| // both writers should get the same exact data. | ||
| test('multipipe', function(t) { | ||
| var r = new TestReader(5); | ||
| var w = [ new TestWriter, new TestWriter ]; | ||
|
|
||
| var expect = [ 'xxxxx', | ||
| 'xxxxx', | ||
| 'xxxxx', | ||
| 'xxxxx', | ||
| 'xxxxx', | ||
| 'xxxxx', | ||
| 'xxxxx', | ||
| 'xxxxx', | ||
| 'xxxxx', | ||
| 'xxxxx' ]; | ||
|
|
||
| var c = 2; | ||
| w[0].on('end', function(received) { | ||
| t.same(received, expect, 'first'); | ||
| if (--c === 0) t.end(); | ||
| }); | ||
| w[1].on('end', function(received) { | ||
| t.same(received, expect, 'second'); | ||
| if (--c === 0) t.end(); | ||
| }); | ||
|
|
||
| r.pipe(w[0]); | ||
| r.pipe(w[1]); | ||
| }); | ||
|
|
||
|
|
||
| [1,2,3,4,5,6,7,8,9].forEach(function(SPLIT) { | ||
| test('multi-unpipe', function(t) { | ||
| var r = new TestReader(5); | ||
|
|
||
| // unpipe after 3 writes, then write to another stream instead. | ||
| var expect = [ 'xxxxx', | ||
| 'xxxxx', | ||
| 'xxxxx', | ||
| 'xxxxx', | ||
| 'xxxxx', | ||
| 'xxxxx', | ||
| 'xxxxx', | ||
| 'xxxxx', | ||
| 'xxxxx', | ||
| 'xxxxx' ]; | ||
| expect = [ expect.slice(0, SPLIT), expect.slice(SPLIT) ]; | ||
|
|
||
| var w = [ new TestWriter(), new TestWriter(), new TestWriter() ]; | ||
|
|
||
| var writes = SPLIT; | ||
| w[0].on('write', function() { | ||
| if (--writes === 0) { | ||
| r.unpipe(); | ||
| w[0].end(); | ||
| r.pipe(w[1]); | ||
| } | ||
| }); | ||
|
|
||
| var ended = 0; | ||
|
|
||
| w[0].on('end', function(results) { | ||
| ended++; | ||
| t.same(results, expect[0]); | ||
| }); | ||
|
|
||
| w[1].on('end', function(results) { | ||
| ended++; | ||
| t.equal(ended, 2); | ||
| t.same(results, expect[1]); | ||
| t.end(); | ||
| }); | ||
|
|
||
| r.pipe(w[0]); | ||
| r.pipe(w[2]); | ||
| }); | ||
| }); |
| @@ -0,0 +1,76 @@ | ||
| // 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.js'); | ||
| var R = require('_stream_readable'); | ||
| var assert = require('assert'); | ||
|
|
||
| var fs = require('fs'); | ||
| var FSReadable = fs.ReadStream; | ||
|
|
||
| var path = require('path'); | ||
| var file = path.resolve(common.fixturesDir, 'x1024.txt'); | ||
|
|
||
| var size = fs.statSync(file).size; | ||
|
|
||
| // expect to see chunks no more than 10 bytes each. | ||
| var expectLengths = []; | ||
| for (var i = size; i > 0; i -= 10) { | ||
| expectLengths.push(Math.min(i, 10)); | ||
| } | ||
|
|
||
| var util = require('util'); | ||
| var Stream = require('stream'); | ||
|
|
||
| util.inherits(TestWriter, Stream); | ||
|
|
||
| function TestWriter() { | ||
| Stream.apply(this); | ||
| this.buffer = []; | ||
| this.length = 0; | ||
| } | ||
|
|
||
| TestWriter.prototype.write = function(c) { | ||
| this.buffer.push(c.toString()); | ||
| this.length += c.length; | ||
| return true; | ||
| }; | ||
|
|
||
| TestWriter.prototype.end = function(c) { | ||
| if (c) this.buffer.push(c.toString()); | ||
| this.emit('results', this.buffer); | ||
| } | ||
|
|
||
| var r = new FSReadable(file, { bufferSize: 10 }); | ||
| var w = new TestWriter(); | ||
|
|
||
| w.on('results', function(res) { | ||
| console.error(res, w.length); | ||
| assert.equal(w.length, size); | ||
| var l = 0; | ||
| assert.deepEqual(res.map(function (c) { | ||
| return c.length; | ||
| }), expectLengths); | ||
| console.log('ok'); | ||
| }); | ||
|
|
||
| r.pipe(w, { chunkSize: 10 }); |
| @@ -0,0 +1,109 @@ | ||
| // 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 assert = require('assert'); | ||
| var common = require('../common.js'); | ||
| var fromList = require('_stream_readable')._fromList; | ||
|
|
||
| // tiny node-tap lookalike. | ||
| var tests = []; | ||
| function test(name, fn) { | ||
| tests.push([name, fn]); | ||
| } | ||
|
|
||
| function run() { | ||
| var next = tests.shift(); | ||
| if (!next) | ||
| return console.error('ok'); | ||
|
|
||
| var name = next[0]; | ||
| var fn = next[1]; | ||
| console.log('# %s', name); | ||
| fn({ | ||
| same: assert.deepEqual, | ||
| equal: assert.equal, | ||
| end: run | ||
| }); | ||
| } | ||
|
|
||
| process.nextTick(run); | ||
|
|
||
|
|
||
|
|
||
| test('buffers', function(t) { | ||
| // have a length | ||
| var len = 16; | ||
| var list = [ new Buffer('foog'), | ||
| new Buffer('bark'), | ||
| new Buffer('bazy'), | ||
| new Buffer('kuel') ]; | ||
|
|
||
| // read more than the first element. | ||
| var ret = fromList(6, list, 16); | ||
| t.equal(ret.toString(), 'foogba'); | ||
|
|
||
| // read exactly the first element. | ||
| ret = fromList(2, list, 10); | ||
| t.equal(ret.toString(), 'rk'); | ||
|
|
||
| // read less than the first element. | ||
| ret = fromList(2, list, 8); | ||
| t.equal(ret.toString(), 'ba'); | ||
|
|
||
| // read more than we have. | ||
| ret = fromList(100, list, 6); | ||
| t.equal(ret.toString(), 'zykuel'); | ||
|
|
||
| // all consumed. | ||
| t.same(list, []); | ||
|
|
||
| t.end(); | ||
| }); | ||
|
|
||
| test('strings', function(t) { | ||
| // have a length | ||
| var len = 16; | ||
| var list = [ 'foog', | ||
| 'bark', | ||
| 'bazy', | ||
| 'kuel' ]; | ||
|
|
||
| // read more than the first element. | ||
| var ret = fromList(6, list, 16, true); | ||
| t.equal(ret, 'foogba'); | ||
|
|
||
| // read exactly the first element. | ||
| ret = fromList(2, list, 10, true); | ||
| t.equal(ret, 'rk'); | ||
|
|
||
| // read less than the first element. | ||
| ret = fromList(2, list, 8, true); | ||
| t.equal(ret, 'ba'); | ||
|
|
||
| // read more than we have. | ||
| ret = fromList(100, list, 6, true); | ||
| t.equal(ret, 'zykuel'); | ||
|
|
||
| // all consumed. | ||
| t.same(list, []); | ||
|
|
||
| t.end(); | ||
| }); |