Skip to content

Commit 0deabd1

Browse files
chungjussayfeross
authored andcommitted
test: update tests for iojs 3.0.0
1 parent 256b62a commit 0deabd1

File tree

6 files changed

+80
-43
lines changed

6 files changed

+80
-43
lines changed

bin/download-node-tests.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,20 +71,26 @@ function testfixer (filename) {
7171
firstline = false
7272
}
7373

74-
// comment out require('common')
75-
line = line.replace(/((var|const) common = require.*)/, 'var common = {};')
74+
// use `var` instead of `const`/`let`
75+
line = line.replace(/(const|let) /g, 'var ')
76+
77+
// make `require('common')` work
78+
line = line.replace(/(var common = require.*)/g, 'var common = {};')
79+
80+
// use `Buffer.isBuffer` instead of `instanceof Buffer`
81+
line = line.replace(/buf instanceof Buffer/g, 'Buffer.isBuffer(buf)')
7682

7783
// require browser buffer
78-
line = line.replace(/(.*)require\('buffer'\)(.*)/, '$1require(\'../../\')$2')
84+
line = line.replace(/(.*)require\('buffer'\)(.*)/g, '$1require(\'../../\')$2')
7985

8086
// smalloc is only used for kMaxLength
8187
line = line.replace(
82-
/require\('smalloc'\)/,
88+
/require\('smalloc'\)/g,
8389
'{ kMaxLength: process.env.OBJECT_IMPL ? 0x3fffffff : 0x7fffffff }'
8490
)
8591

8692
// comment out console logs
87-
line = line.replace(/(.*console\..*)/, '// $1')
93+
line = line.replace(/(.*console\..*)/g, '// $1')
8894

8995
// we can't reliably test typed array max-sizes in the browser
9096
if (filename === 'test-buffer-big.js') {

test/node/test-buffer-arraybuffer.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
'use strict';
2+
var Buffer = require('../../').Buffer;
3+
if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false;
4+
5+
var common = {};
6+
var assert = require('assert');
7+
8+
var Buffer = require('../../').Buffer;
9+
var LENGTH = 16;
10+
11+
var ab = new ArrayBuffer(LENGTH);
12+
var dv = new DataView(ab);
13+
var ui = new Uint8Array(ab);
14+
var buf = new Buffer(ab);
15+
16+
17+
assert.ok(Buffer.isBuffer(buf));
18+
// For backwards compatibility of old .parent property test that if buf is not
19+
// a slice then .parent should be undefined.
20+
assert.equal(buf.parent, undefined);
21+
assert.equal(buf.buffer, ab);
22+
assert.equal(buf.length, ab.byteLength);
23+
24+
25+
buf.fill(0xC);
26+
for (var i = 0; i < LENGTH; i++) {
27+
assert.equal(ui[i], 0xC);
28+
ui[i] = 0xF;
29+
assert.equal(buf[i], 0xF);
30+
}
31+
32+
buf.writeUInt32LE(0xF00, 0);
33+
buf.writeUInt32BE(0xB47, 4);
34+
buf.writeDoubleLE(3.1415, 8);
35+
36+
assert.equal(dv.getUint32(0, true), 0xF00);
37+
assert.equal(dv.getUint32(4), 0xB47);
38+
assert.equal(dv.getFloat64(8, true), 3.1415);
39+
40+
41+
// Now test protecting users from doing stupid things
42+
43+
assert.throws(function() {
44+
function AB() { }
45+
AB.__proto__ = ArrayBuffer;
46+
AB.prototype.__proto__ = ArrayBuffer.prototype;
47+
new Buffer(new AB());
48+
}, TypeError);
49+

test/node/test-buffer-big.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

test/node/test-buffer-concat.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,15 @@ var flatLongLen = Buffer.concat(long, 40);
1616

1717
assert(flatZero.length === 0);
1818
assert(flatOne.toString() === 'asdf');
19-
assert(flatOne === one[0]);
19+
// A special case where concat used to return the first item,
20+
// if the length is one. This check is to make sure that we don't do that.
21+
assert(flatOne !== one[0]);
2022
assert(flatLong.toString() === (new Array(10 + 1).join('asdf')));
2123
assert(flatLongLen.toString() === (new Array(10 + 1).join('asdf')));
2224

25+
assert.throws(function() {
26+
Buffer.concat([42]);
27+
}, TypeError);
28+
2329
// console.log('ok');
2430

test/node/test-buffer-slice.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

test/node/test-buffer.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ var assert = require('assert');
66

77
var Buffer = require('../../').Buffer;
88
var SlowBuffer = require('../../').SlowBuffer;
9-
var smalloc = { kMaxLength: process.env.OBJECT_IMPL ? 0x3fffffff : 0x7fffffff };
109

1110
// counter to ensure unique value is always copied
1211
var cntr = 0;
@@ -331,8 +330,6 @@ assert.equal(b.parent, d.parent);
331330
var b = new SlowBuffer(5);
332331
var c = b.slice(0, 4);
333332
var d = c.slice(0, 2);
334-
assert.equal(b, c.parent);
335-
assert.equal(b, d.parent);
336333

337334

338335
// Bug regression test
@@ -804,7 +801,9 @@ assert.equal(buf[4], 0);
804801

805802
// Check for fractional length args, junk length args, etc.
806803
// https://github.com/joyent/node/issues/1758
807-
Buffer(3.3).toString(); // throws bad argument error in commit 43cb4ec
804+
805+
// Call .fill() first, stops valgrind warning about uninitialized memory reads.
806+
Buffer(3.3).fill().toString(); // throws bad argument error in commit 43cb4ec
808807
assert.equal(Buffer(-1).length, 0);
809808
assert.equal(Buffer(NaN).length, 0);
810809
assert.equal(Buffer(3.3).length, 3);
@@ -1075,10 +1074,6 @@ assert.equal(buf.readInt8(0), -1);
10751074
// try to slice a zero length Buffer
10761075
// see https://github.com/joyent/node/issues/5881
10771076
SlowBuffer(0).slice(0, 1);
1078-
// make sure a zero length slice doesn't set the .parent attribute
1079-
assert.equal(Buffer(5).slice(0, 0).parent, undefined);
1080-
// and make sure a proper slice does have a parent
1081-
assert.ok(typeof Buffer(5).slice(0, 5).parent === 'object');
10821077
})();
10831078

10841079
// Regression test for #5482: should throw but not assert in C++ land.
@@ -1105,11 +1100,11 @@ assert.throws(function() {
11051100

11061101

11071102
assert.throws(function() {
1108-
new Buffer(smalloc.kMaxLength + 1);
1103+
new Buffer((-1 >>> 0) + 1);
11091104
}, RangeError);
11101105

11111106
assert.throws(function() {
1112-
new SlowBuffer(smalloc.kMaxLength + 1);
1107+
new SlowBuffer((-1 >>> 0) + 1);
11131108
}, RangeError);
11141109

11151110
if (common.hasCrypto) {
@@ -1189,3 +1184,11 @@ assert.throws(function() {
11891184
Buffer(10).copy();
11901185
});
11911186

1187+
assert.throws(function() {
1188+
new Buffer();
1189+
}, /must start with number, buffer, array or string/);
1190+
1191+
assert.throws(function() {
1192+
new Buffer(null);
1193+
}, /must start with number, buffer, array or string/);
1194+

0 commit comments

Comments
 (0)