if (file.name !== 'test-buffer-iterator.js') {
path = __dirname + '/../test/node/' + file.name
} else {
- path = __dirname + '/../test/es6/' + file.name
+ path = __dirname + '/../test/node-es6/' + file.name
}
hyperquest(file.download_url, httpOpts)
"test": "standard && node ./bin/test.js",
"test-browser": "zuul -- test/*.js test/node/*.js",
"test-browser-local": "zuul --local -- test/*.js test/node/*.js",
- "test-node": "tape test/*.js test/node/*.js test/es6/*.js && OBJECT_IMPL=true tape test/*.js test/node/*.js",
+ "test-node": "tape test/*.js test/node/*.js test/node-es6/*.js && OBJECT_IMPL=true tape test/*.js test/node/*.js",
"perf": "browserify --debug perf/bracket-notation.js > perf/bundle.js && open perf/index.html",
"perf-node": "node perf/bracket-notation.js && node perf/concat.js && node perf/copy-big.js && node perf/copy.js && node perf/new-big.js && node perf/new.js && node perf/readDoubleBE.js && node perf/readFloatBE.js && node perf/readUInt32LE.js && node perf/slice.js && node perf/writeFloatBE.js",
"size": "browserify -r ./ | uglifyjs -c -m | gzip | wc -c"
"standard": {
"ignore": [
"test/node/*.js",
- "test/es6/*.js",
+ "test/node-es6/*.js",
"test/_polyfill.js",
"perf/*.js"
]
+++ /dev/null
-io.js/node.js core buffer tests that require ES6 (for..of construct)
--- /dev/null
+node buffer tests that require ES6 (e.g. "for..of" construct)
-var Buffer = require('../../').Buffer
-if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false
+'use strict';
+var Buffer = require('../../').Buffer;
+if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false;
var common = {};
var assert = require('assert');
-var Buffer = require('../../').Buffer
-if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false
+'use strict';
+var Buffer = require('../../').Buffer;
+if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false;
var common = {};
var assert = require('assert');
-var Buffer = require('../../').Buffer
-if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false
+'use strict';
+var Buffer = require('../../').Buffer;
+if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false;
var common = {};
var assert = require('assert');
// The tests below should throw an error, not abort the process...
-assert.throws(function() { new Buffer(0x3fffffff + 1) }, RangeError);
-// assert.throws(function() { new Int8Array(0x3fffffff + 1) }, RangeError);
-// assert.throws(function() { new ArrayBuffer(0x3fffffff + 1) }, RangeError);
-// assert.throws(function() { new Float64Array(0x7ffffff + 1) }, RangeError);
+assert.throws(function() { new Buffer(0x3fffffff + 1); }, RangeError);
+// assert.throws(function() { new Int8Array(0x3fffffff + 1); }, RangeError);
+// assert.throws(function() { new ArrayBuffer(0x3fffffff + 1); }, RangeError);
+// assert.throws(function() { new Float64Array(0x7ffffff + 1); }, RangeError);
--- /dev/null
+'use strict';
+var Buffer = require('../../').Buffer;
+if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false;
+
+var common = {};
+var assert = require('assert');
+var Buffer = require('../../').Buffer;
+
+// coerce values to string
+assert.equal(Buffer.byteLength(32, 'raw'), 2);
+assert.equal(Buffer.byteLength(NaN, 'utf8'), 3);
+assert.equal(Buffer.byteLength({}, 'raws'), 15);
+assert.equal(Buffer.byteLength(), 9);
+
+// special case: zero length string
+assert.equal(Buffer.byteLength('', 'ascii'), 0);
+assert.equal(Buffer.byteLength('', 'HeX'), 0);
+
+// utf8
+assert.equal(Buffer.byteLength('∑éllö wørl∂!', 'utf-8'), 19);
+assert.equal(Buffer.byteLength('κλμνξο', 'utf8'), 12);
+assert.equal(Buffer.byteLength('挵挶挷挸挹', 'utf-8'), 15);
+assert.equal(Buffer.byteLength('𠝹𠱓𠱸', 'UTF8'), 12);
+// without an encoding, utf8 should be assumed
+assert.equal(Buffer.byteLength('hey there'), 9);
+assert.equal(Buffer.byteLength('𠱸挶νξ#xx :)'), 17);
+assert.equal(Buffer.byteLength('hello world', ''), 11);
+// it should also be assumed with unrecognized encoding
+assert.equal(Buffer.byteLength('hello world', 'abc'), 11);
+assert.equal(Buffer.byteLength('ßœ∑≈', 'unkn0wn enc0ding'), 10);
+
+// base64
+assert.equal(Buffer.byteLength('aGVsbG8gd29ybGQ=', 'base64'), 11);
+assert.equal(Buffer.byteLength('bm9kZS5qcyByb2NrcyE=', 'base64'), 14);
+assert.equal(Buffer.byteLength('aGkk', 'base64'), 3);
+assert.equal(Buffer.byteLength('bHNrZGZsa3NqZmtsc2xrZmFqc2RsZmtqcw==',
+ 'base64'), 25);
+// special padding
+assert.equal(Buffer.byteLength('aaa=', 'base64'), 2);
+assert.equal(Buffer.byteLength('aaaa==', 'base64'), 3);
+
+assert.equal(Buffer.byteLength('Il était tué'), 14);
+assert.equal(Buffer.byteLength('Il était tué', 'utf8'), 14);
+assert.equal(Buffer.byteLength('Il était tué', 'ascii'), 12);
+assert.equal(Buffer.byteLength('Il était tué', 'binary'), 12);
+['ucs2', 'ucs-2', 'utf16le', 'utf-16le'].forEach(function(encoding) {
+ assert.equal(24, Buffer.byteLength('Il était tué', encoding));
+});
+
-var Buffer = require('../../').Buffer
-if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false
+'use strict';
+var Buffer = require('../../').Buffer;
+if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false;
var common = {};
var assert = require('assert');
assert(flatZero.length === 0);
assert(flatOne.toString() === 'asdf');
assert(flatOne === one[0]);
-assert(flatLong.toString() === (new Array(10+1).join('asdf')));
-assert(flatLongLen.toString() === (new Array(10+1).join('asdf')));
+assert(flatLong.toString() === (new Array(10 + 1).join('asdf')));
+assert(flatLongLen.toString() === (new Array(10 + 1).join('asdf')));
-// console.log("ok");
+// console.log('ok');
--- /dev/null
+'use strict';
+var Buffer = require('../../').Buffer;
+if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false;
+
+var common = {};
+const assert = require('assert');
+var Buffer = require('../../').Buffer;
+const Bp = Buffer.prototype;
+
+function FakeBuffer() { }
+FakeBuffer.__proto__ = Buffer;
+FakeBuffer.prototype.__proto__ = Buffer.prototype;
+
+const fb = new FakeBuffer();
+
+assert.throws(function() {
+ new Buffer(fb);
+}, TypeError);
+
+assert.throws(function() {
+ +Buffer.prototype;
+}, TypeError);
+
+assert.throws(function() {
+ Buffer.compare(fb, new Buffer(0));
+}, TypeError);
+
+assert.throws(function() {
+ fb.write('foo');
+}, TypeError);
+
+assert.throws(function() {
+ Buffer.concat([fb, fb]);
+}, TypeError);
+
+assert.throws(function() {
+ fb.toString();
+}, TypeError);
+
+assert.throws(function() {
+ fb.equals(new Buffer(0));
+}, TypeError);
+
+assert.throws(function() {
+ fb.indexOf(5);
+}, TypeError);
+
+assert.throws(function() {
+ fb.readFloatLE(0);
+}, TypeError);
+
+assert.throws(function() {
+ fb.writeFloatLE(0);
+}, TypeError);
+
+assert.throws(function() {
+ fb.fill(0);
+}, TypeError);
+
-var Buffer = require('../../').Buffer
-if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false
+'use strict';
+var Buffer = require('../../').Buffer;
+if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false;
var common = {};
var assert = require('assert');
-var Buffer = require('../../').Buffer
-if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false
+'use strict';
+var Buffer = require('../../').Buffer;
+if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false;
var common = {};
var assert = require('assert');
assert.strictEqual(util.inspect(b), expected);
assert.strictEqual(util.inspect(s), expected);
});
+
-var Buffer = require('../../').Buffer
-if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false
+'use strict';
+var Buffer = require('../../').Buffer;
+if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false;
var common = {};
var assert = require('assert');
var slicedBuffer = buff.slice();
assert.equal(slicedBuffer.parent,
buff,
- "slicedBufffer should have its parent set to the original " +
- " buffer");
+ 'slicedBufffer should have its parent set to the original ' +
+ ' buffer');
-var Buffer = require('../../').Buffer
-if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false
+'use strict';
+var Buffer = require('../../').Buffer;
+if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false;
var common = {};
var assert = require('assert');
for (var i = 0; i < Math.floor(c.length / 2); i++) {
assert.strictEqual(b[b.length - Math.floor(c.length / 2) + i], c[i]);
}
-for (var i = Math.floor(c.length /2) + 1; i < c.length; i++) {
- assert.strictEqual(c[c.length-1], c[i]);
+for (var i = Math.floor(c.length / 2) + 1; i < c.length; i++) {
+ assert.strictEqual(c[c.length - 1], c[i]);
}
// try to copy 513 bytes, and check we don't overrun c
writeTest.write('j', 'ascii', 4);
assert.equal(writeTest.toString(), 'nodejs');
+// ASCII slice test
+
var asciiString = 'hello world';
var offset = 100;
-for (var j = 0; j < 500; j++) {
-
- for (var i = 0; i < asciiString.length; i++) {
- b[i] = asciiString.charCodeAt(i);
- }
- var asciiSlice = b.toString('ascii', 0, asciiString.length);
- assert.equal(asciiString, asciiSlice);
-
- var written = b.write(asciiString, offset, 'ascii');
- assert.equal(asciiString.length, written);
- var asciiSlice = b.toString('ascii', offset, offset + asciiString.length);
- assert.equal(asciiString, asciiSlice);
-
- var sliceA = b.slice(offset, offset + asciiString.length);
- var sliceB = b.slice(offset, offset + asciiString.length);
- for (var i = 0; i < asciiString.length; i++) {
- assert.equal(sliceA[i], sliceB[i]);
- }
- // TODO utf8 slice tests
+for (var i = 0; i < asciiString.length; i++) {
+ b[i] = asciiString.charCodeAt(i);
+}
+var asciiSlice = b.toString('ascii', 0, asciiString.length);
+assert.equal(asciiString, asciiSlice);
+
+var written = b.write(asciiString, offset, 'ascii');
+assert.equal(asciiString.length, written);
+var asciiSlice = b.toString('ascii', offset, offset + asciiString.length);
+assert.equal(asciiString, asciiSlice);
+
+var sliceA = b.slice(offset, offset + asciiString.length);
+var sliceB = b.slice(offset, offset + asciiString.length);
+for (var i = 0; i < asciiString.length; i++) {
+ assert.equal(sliceA[i], sliceB[i]);
}
+// UTF-8 slice test
-for (var j = 0; j < 100; j++) {
- var slice = b.slice(100, 150);
- assert.equal(50, slice.length);
- for (var i = 0; i < 50; i++) {
- assert.equal(b[100 + i], slice[i]);
- }
+var utf8String = '¡hέlló wôrld!';
+var offset = 100;
+
+b.write(utf8String, 0, Buffer.byteLength(utf8String), 'utf8');
+var utf8Slice = b.toString('utf8', 0, Buffer.byteLength(utf8String));
+assert.equal(utf8String, utf8Slice);
+
+var written = b.write(utf8String, offset, 'utf8');
+assert.equal(Buffer.byteLength(utf8String), written);
+utf8Slice = b.toString('utf8', offset, offset + Buffer.byteLength(utf8String));
+assert.equal(utf8String, utf8Slice);
+
+var sliceA = b.slice(offset, offset + Buffer.byteLength(utf8String));
+var sliceB = b.slice(offset, offset + Buffer.byteLength(utf8String));
+for (var i = 0; i < Buffer.byteLength(utf8String); i++) {
+ assert.equal(sliceA[i], sliceB[i]);
+}
+
+var slice = b.slice(100, 150);
+assert.equal(50, slice.length);
+for (var i = 0; i < 50; i++) {
+ assert.equal(b[100 + i], slice[i]);
}
assert.equal(b, d.parent);
-
// Bug regression test
var testValue = '\u00F6\u65E5\u672C\u8A9E'; // ö日本語
var buffer = new Buffer(32);
b = new Buffer('abcde');
assert.equal('bcde', b.slice(1).toString());
-// byte length
-assert.equal(14, Buffer.byteLength('Il était tué'));
-assert.equal(14, Buffer.byteLength('Il était tué', 'utf8'));
-['ucs2', 'ucs-2', 'utf16le', 'utf-16le'].forEach(function(encoding) {
- assert.equal(24, Buffer.byteLength('Il était tué', encoding));
-});
-assert.equal(12, Buffer.byteLength('Il était tué', 'ascii'));
-assert.equal(12, Buffer.byteLength('Il était tué', 'binary'));
-
// slice(0,0).length === 0
assert.equal(0, Buffer('hello').slice(0, 0).length);
// GH-5110
-(function () {
+(function() {
var buffer = new Buffer('test'),
string = JSON.stringify(buffer);
// see https://github.com/joyent/node/issues/5881
SlowBuffer(0).slice(0, 1);
// make sure a zero length slice doesn't set the .parent attribute
- assert.equal(Buffer(5).slice(0,0).parent, undefined);
+ assert.equal(Buffer(5).slice(0, 0).parent, undefined);
// and make sure a proper slice does have a parent
assert.ok(typeof Buffer(5).slice(0, 5).parent === 'object');
})();
-// Make sure byteLength properly checks for base64 padding
-assert.equal(Buffer.byteLength('aaa=', 'base64'), 2);
-assert.equal(Buffer.byteLength('aaaa==', 'base64'), 3);
-
// Regression test for #5482: should throw but not assert in C++ land.
assert.throws(function() {
Buffer('', 'buffer');
(function() {
var a = [0];
for (var i = 0; i < 7; ++i) a = a.concat(a);
- a = a.map(function(_, i) { return i });
+ a = a.map(function(_, i) { return i; });
var b = Buffer(a);
var c = Buffer(b);
assert.equal(b.length, a.length);
})();
-assert.throws(function () {
+assert.throws(function() {
new Buffer(smalloc.kMaxLength + 1);
}, RangeError);
-assert.throws(function () {
+assert.throws(function() {
new SlowBuffer(smalloc.kMaxLength + 1);
}, RangeError);
b.equals('abc');
});
-// Regression test for https://github.com/iojs/io.js/issues/649.
+// Regression test for https://github.com/nodejs/io.js/issues/649.
assert.throws(function() { Buffer(1422561062959).toString('utf8'); });
var ps = Buffer.poolSize;