From 21f472ed88b090dbb5ca28e1d497c872684eab80 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Mon, 9 Mar 2015 14:35:55 -0700 Subject: [PATCH] test: pull in latest iojs tests --- bin/download-node-tests.js | 2 +- test/es6/test-buffer-iterator.js | 4 +- test/node/test-buffer-ascii.js | 3 +- test/node/test-buffer-big.js | 2 +- test/node/test-buffer-concat.js | 2 +- test/node/test-buffer-indexof.js | 78 ++++++++++++++++++++++++++++++++ test/node/test-buffer-inspect.js | 2 +- test/node/test-buffer-slice.js | 2 +- test/node/test-buffer.js | 27 +++++++---- 9 files changed, 105 insertions(+), 17 deletions(-) create mode 100644 test/node/test-buffer-indexof.js diff --git a/bin/download-node-tests.js b/bin/download-node-tests.js index bae2386..24fe48d 100755 --- a/bin/download-node-tests.js +++ b/bin/download-node-tests.js @@ -61,7 +61,7 @@ function testfixer (filename) { } // comment out require('common') - line = line.replace(/(var common = require.*)/, '// $1') + line = line.replace(/(var common = require.*)/, 'var common = {};') // require browser buffer line = line.replace(/(.*)require\('buffer'\)(.*)/, '$1require(\'../../\')$2') diff --git a/test/es6/test-buffer-iterator.js b/test/es6/test-buffer-iterator.js index 1bbe1c7..0dae63b 100644 --- a/test/es6/test-buffer-iterator.js +++ b/test/es6/test-buffer-iterator.js @@ -1,6 +1,6 @@ var Buffer = require('../../').Buffer -if (process.env.OBJECT_IMPL) return -// var common = require('../common'); +if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false +var common = {}; var assert = require('assert'); var buffer = new Buffer([1, 2, 3, 4, 5]); diff --git a/test/node/test-buffer-ascii.js b/test/node/test-buffer-ascii.js index 16572b3..9e22a1f 100644 --- a/test/node/test-buffer-ascii.js +++ b/test/node/test-buffer-ascii.js @@ -1,6 +1,6 @@ var Buffer = require('../../').Buffer if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false -// var common = require('../common'); +var common = {}; var assert = require('assert'); // ASCII conversion in node.js simply masks off the high bits, @@ -24,3 +24,4 @@ for (var i = 0; i < expected.length; ++i) { if (input.charCodeAt(i) > 65535) ++i; if (input.charCodeAt(i) > 127) ++i; } + diff --git a/test/node/test-buffer-big.js b/test/node/test-buffer-big.js index d704cf9..858ca3f 100644 --- a/test/node/test-buffer-big.js +++ b/test/node/test-buffer-big.js @@ -1,6 +1,6 @@ var Buffer = require('../../').Buffer if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false -// var common = require('../common'); +var common = {}; var assert = require('assert'); // The tests below should throw an error, not abort the process... diff --git a/test/node/test-buffer-concat.js b/test/node/test-buffer-concat.js index c703c14..5e6636f 100644 --- a/test/node/test-buffer-concat.js +++ b/test/node/test-buffer-concat.js @@ -1,6 +1,6 @@ var Buffer = require('../../').Buffer if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false -// var common = require('../common'); +var common = {}; var assert = require('assert'); var zero = []; diff --git a/test/node/test-buffer-indexof.js b/test/node/test-buffer-indexof.js new file mode 100644 index 0000000..39d731d --- /dev/null +++ b/test/node/test-buffer-indexof.js @@ -0,0 +1,78 @@ +var Buffer = require('../../').Buffer +if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false +var common = {}; +var assert = require('assert'); + +var Buffer = require('../../').Buffer; + +var b = new Buffer('abcdef'); +var buf_a = new Buffer('a'); +var buf_bc = new Buffer('bc'); +var buf_f = new Buffer('f'); +var buf_z = new Buffer('z'); +var buf_empty = new Buffer(''); + +assert.equal(b.indexOf('a'), 0); +assert.equal(b.indexOf('a', 1), -1); +assert.equal(b.indexOf('a', -1), -1); +assert.equal(b.indexOf('a', -4), -1); +assert.equal(b.indexOf('a', -b.length), 0); +assert.equal(b.indexOf('a', NaN), 0); +assert.equal(b.indexOf('a', -Infinity), 0); +assert.equal(b.indexOf('a', Infinity), -1); +assert.equal(b.indexOf('bc'), 1); +assert.equal(b.indexOf('bc', 2), -1); +assert.equal(b.indexOf('bc', -1), -1); +assert.equal(b.indexOf('bc', -3), -1); +assert.equal(b.indexOf('bc', -5), 1); +assert.equal(b.indexOf('bc', NaN), 1); +assert.equal(b.indexOf('bc', -Infinity), 1); +assert.equal(b.indexOf('bc', Infinity), -1); +assert.equal(b.indexOf('f'), b.length - 1); +assert.equal(b.indexOf('z'), -1); +assert.equal(b.indexOf(''), -1); +assert.equal(b.indexOf('', 1), -1); +assert.equal(b.indexOf('', b.length + 1), -1); +assert.equal(b.indexOf('', Infinity), -1); +assert.equal(b.indexOf(buf_a), 0); +assert.equal(b.indexOf(buf_a, 1), -1); +assert.equal(b.indexOf(buf_a, -1), -1); +assert.equal(b.indexOf(buf_a, -4), -1); +assert.equal(b.indexOf(buf_a, -b.length), 0); +assert.equal(b.indexOf(buf_a, NaN), 0); +assert.equal(b.indexOf(buf_a, -Infinity), 0); +assert.equal(b.indexOf(buf_a, Infinity), -1); +assert.equal(b.indexOf(buf_bc), 1); +assert.equal(b.indexOf(buf_bc, 2), -1); +assert.equal(b.indexOf(buf_bc, -1), -1); +assert.equal(b.indexOf(buf_bc, -3), -1); +assert.equal(b.indexOf(buf_bc, -5), 1); +assert.equal(b.indexOf(buf_bc, NaN), 1); +assert.equal(b.indexOf(buf_bc, -Infinity), 1); +assert.equal(b.indexOf(buf_bc, Infinity), -1); +assert.equal(b.indexOf(buf_f), b.length - 1); +assert.equal(b.indexOf(buf_z), -1); +assert.equal(b.indexOf(buf_empty), -1); +assert.equal(b.indexOf(buf_empty, 1), -1); +assert.equal(b.indexOf(buf_empty, b.length + 1), -1); +assert.equal(b.indexOf(buf_empty, Infinity), -1); +assert.equal(b.indexOf(0x61), 0); +assert.equal(b.indexOf(0x61, 1), -1); +assert.equal(b.indexOf(0x61, -1), -1); +assert.equal(b.indexOf(0x61, -4), -1); +assert.equal(b.indexOf(0x61, -b.length), 0); +assert.equal(b.indexOf(0x61, NaN), 0); +assert.equal(b.indexOf(0x61, -Infinity), 0); +assert.equal(b.indexOf(0x61, Infinity), -1); +assert.equal(b.indexOf(0x0), -1); + +assert.throws(function() { + b.indexOf(function() { }); +}); +assert.throws(function() { + b.indexOf({}); +}); +assert.throws(function() { + b.indexOf([]); +}); + diff --git a/test/node/test-buffer-inspect.js b/test/node/test-buffer-inspect.js index d8263a8..08415a9 100644 --- a/test/node/test-buffer-inspect.js +++ b/test/node/test-buffer-inspect.js @@ -1,6 +1,6 @@ var Buffer = require('../../').Buffer if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false -// var common = require('../common'); +var common = {}; var assert = require('assert'); var util = require('util'); diff --git a/test/node/test-buffer-slice.js b/test/node/test-buffer-slice.js index 6e58812..36cb3a3 100644 --- a/test/node/test-buffer-slice.js +++ b/test/node/test-buffer-slice.js @@ -1,6 +1,6 @@ var Buffer = require('../../').Buffer if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false -// var common = require('../common'); +var common = {}; var assert = require('assert'); var Buffer = require('../../').Buffer; diff --git a/test/node/test-buffer.js b/test/node/test-buffer.js index 1a6a09d..9bb56e4 100644 --- a/test/node/test-buffer.js +++ b/test/node/test-buffer.js @@ -1,6 +1,6 @@ var Buffer = require('../../').Buffer if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false -// var common = require('../common'); +var common = {}; var assert = require('assert'); var Buffer = require('../../').Buffer; @@ -1110,16 +1110,20 @@ assert.throws(function () { new SlowBuffer(smalloc.kMaxLength + 1); }, RangeError); -// Test truncation after decode -// var crypto = require('crypto'); +if (common.hasCrypto) { + // Test truncation after decode + var crypto = require('crypto'); -var b1 = new Buffer('YW55=======', 'base64'); -var b2 = new Buffer('YW55', 'base64'); + var b1 = new Buffer('YW55=======', 'base64'); + var b2 = new Buffer('YW55', 'base64'); -assert.equal( - 1 /*crypto.createHash('sha1').update(b1).digest('hex')*/, - 1 /*crypto.createHash('sha1').update(b2).digest('hex')*/ -); + assert.equal( + 1 /*crypto.createHash('sha1').update(b1).digest('hex')*/, + 1 /*crypto.createHash('sha1').update(b2).digest('hex')*/ + ); +} else { +// console.log('1..0 # Skipped: missing crypto'); +} // Test Compare var b = new Buffer(1).fill('a'); @@ -1173,3 +1177,8 @@ assert.throws(function() { // Regression test for https://github.com/iojs/io.js/issues/649. assert.throws(function() { Buffer(1422561062959).toString('utf8'); }); +var ps = Buffer.poolSize; +Buffer.poolSize = 0; +assert.equal(Buffer(1).parent, undefined); +Buffer.poolSize = ps; + -- 2.34.1