Browse Source

test: improve chained property readability

A new version of ESLint flags chained properties on multiple lines that
were not flagged by the previous version of ESLint. In preparation for
turning that feature on, adjust alignment to that expected by the
linter.

This change happened to be predominantly around assertions using
`assert()` and `assert.equal()`. These were changed to
`assert.strictEqual()` where possible.

PR-URL: https://github.com/nodejs/node/pull/7920
Reviewed-By: Michaël Zasso <mic.besace@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
v7.x
Rich Trott 9 years ago
parent
commit
b4258bba11
  1. 80
      test/parallel/test-buffer-includes.js
  2. 128
      test/parallel/test-buffer-indexof.js
  3. 20
      test/parallel/test-cluster-worker-forced-exit.js
  4. 24
      test/parallel/test-crypto-binary-default.js
  5. 24
      test/parallel/test-crypto-hmac.js
  6. 12
      test/parallel/test-net-server-max-connections-close-makes-more-available.js
  7. 24
      test/parallel/test-readline-interface.js

80
test/parallel/test-buffer-includes.js

@ -79,44 +79,64 @@ assert(!b.includes(Buffer.from('f'), 6));
assert(!Buffer.from('ff').includes(Buffer.from('f'), 1, 'ucs2')); assert(!Buffer.from('ff').includes(Buffer.from('f'), 1, 'ucs2'));
// test hex encoding // test hex encoding
assert( assert.strictEqual(
Buffer.from(b.toString('hex'), 'hex') Buffer.from(b.toString('hex'), 'hex')
.includes('64', 0, 'hex')); .includes('64', 0, 'hex'),
assert( true
Buffer.from(b.toString('hex'), 'hex') );
.includes(Buffer.from('64', 'hex'), 0, 'hex')); assert.strictEqual(
Buffer.from(b.toString('hex'), 'hex')
.includes(Buffer.from('64', 'hex'), 0, 'hex'),
true
);
// test base64 encoding // test base64 encoding
assert( assert.strictEqual(
Buffer.from(b.toString('base64'), 'base64') Buffer.from(b.toString('base64'), 'base64')
.includes('ZA==', 0, 'base64')); .includes('ZA==', 0, 'base64'),
assert( true
Buffer.from(b.toString('base64'), 'base64') );
.includes(Buffer.from('ZA==', 'base64'), 0, 'base64')); assert.strictEqual(
Buffer.from(b.toString('base64'), 'base64')
.includes(Buffer.from('ZA==', 'base64'), 0, 'base64'),
true
);
// test ascii encoding // test ascii encoding
assert( assert.strictEqual(
Buffer.from(b.toString('ascii'), 'ascii') Buffer.from(b.toString('ascii'), 'ascii')
.includes('d', 0, 'ascii')); .includes('d', 0, 'ascii'),
assert( true
Buffer.from(b.toString('ascii'), 'ascii') );
.includes(Buffer.from('d', 'ascii'), 0, 'ascii')); assert.strictEqual(
Buffer.from(b.toString('ascii'), 'ascii')
.includes(Buffer.from('d', 'ascii'), 0, 'ascii'),
true
);
// test latin1 encoding // test latin1 encoding
assert( assert.strictEqual(
Buffer.from(b.toString('latin1'), 'latin1') Buffer.from(b.toString('latin1'), 'latin1')
.includes('d', 0, 'latin1')); .includes('d', 0, 'latin1'),
assert( true
Buffer.from(b.toString('latin1'), 'latin1') );
.includes(Buffer.from('d', 'latin1'), 0, 'latin1')); assert.strictEqual(
Buffer.from(b.toString('latin1'), 'latin1')
.includes(Buffer.from('d', 'latin1'), 0, 'latin1'),
true
);
// test binary encoding // test binary encoding
assert( assert.strictEqual(
Buffer.from(b.toString('binary'), 'binary') Buffer.from(b.toString('binary'), 'binary')
.includes('d', 0, 'binary')); .includes('d', 0, 'binary'),
assert( true
Buffer.from(b.toString('binary'), 'binary') );
.includes(Buffer.from('d', 'binary'), 0, 'binary')); assert.strictEqual(
Buffer.from(b.toString('binary'), 'binary')
.includes(Buffer.from('d', 'binary'), 0, 'binary'),
true
);
// test usc2 encoding // test usc2 encoding

128
test/parallel/test-buffer-indexof.js

@ -79,62 +79,94 @@ assert.equal(b.indexOf(Buffer.from('f'), 6), -1);
assert.equal(Buffer.from('ff').indexOf(Buffer.from('f'), 1, 'ucs2'), -1); assert.equal(Buffer.from('ff').indexOf(Buffer.from('f'), 1, 'ucs2'), -1);
// test hex encoding // test hex encoding
assert.equal( assert.strictEqual(
Buffer.from(b.toString('hex'), 'hex') Buffer.from(b.toString('hex'), 'hex')
.indexOf('64', 0, 'hex'), 3); .indexOf('64', 0, 'hex'),
assert.equal( 3
Buffer.from(b.toString('hex'), 'hex') );
.indexOf(Buffer.from('64', 'hex'), 0, 'hex'), 3); assert.strictEqual(
Buffer.from(b.toString('hex'), 'hex')
.indexOf(Buffer.from('64', 'hex'), 0, 'hex'),
3
);
// test base64 encoding // test base64 encoding
assert.equal( assert.strictEqual(
Buffer.from(b.toString('base64'), 'base64') Buffer.from(b.toString('base64'), 'base64')
.indexOf('ZA==', 0, 'base64'), 3); .indexOf('ZA==', 0, 'base64'),
assert.equal( 3
Buffer.from(b.toString('base64'), 'base64') );
.indexOf(Buffer.from('ZA==', 'base64'), 0, 'base64'), 3); assert.strictEqual(
Buffer.from(b.toString('base64'), 'base64')
.indexOf(Buffer.from('ZA==', 'base64'), 0, 'base64'),
3
);
// test ascii encoding // test ascii encoding
assert.equal( assert.strictEqual(
Buffer.from(b.toString('ascii'), 'ascii') Buffer.from(b.toString('ascii'), 'ascii')
.indexOf('d', 0, 'ascii'), 3); .indexOf('d', 0, 'ascii'),
assert.equal( 3
Buffer.from(b.toString('ascii'), 'ascii') );
.indexOf(Buffer.from('d', 'ascii'), 0, 'ascii'), 3); assert.strictEqual(
Buffer.from(b.toString('ascii'), 'ascii')
.indexOf(Buffer.from('d', 'ascii'), 0, 'ascii'),
3
);
// test latin1 encoding // test latin1 encoding
assert.equal( assert.strictEqual(
Buffer.from(b.toString('latin1'), 'latin1') Buffer.from(b.toString('latin1'), 'latin1')
.indexOf('d', 0, 'latin1'), 3); .indexOf('d', 0, 'latin1'),
assert.equal( 3
Buffer.from(b.toString('latin1'), 'latin1') );
.indexOf(Buffer.from('d', 'latin1'), 0, 'latin1'), 3); assert.strictEqual(
assert.equal( Buffer.from(b.toString('latin1'), 'latin1')
Buffer.from('aa\u00e8aa', 'latin1') .indexOf(Buffer.from('d', 'latin1'), 0, 'latin1'),
.indexOf('\u00e8', 'latin1'), 2); 3
assert.equal( );
Buffer.from('\u00e8', 'latin1') assert.strictEqual(
.indexOf('\u00e8', 'latin1'), 0); Buffer.from('aa\u00e8aa', 'latin1')
assert.equal( .indexOf('\u00e8', 'latin1'),
Buffer.from('\u00e8', 'latin1') 2
.indexOf(Buffer.from('\u00e8', 'latin1'), 'latin1'), 0); );
assert.strictEqual(
Buffer.from('\u00e8', 'latin1')
.indexOf('\u00e8', 'latin1'),
0
);
assert.strictEqual(
Buffer.from('\u00e8', 'latin1')
.indexOf(Buffer.from('\u00e8', 'latin1'), 'latin1'),
0
);
// test binary encoding // test binary encoding
assert.equal( assert.strictEqual(
Buffer.from(b.toString('binary'), 'binary') Buffer.from(b.toString('binary'), 'binary')
.indexOf('d', 0, 'binary'), 3); .indexOf('d', 0, 'binary'),
assert.equal( 3
Buffer.from(b.toString('binary'), 'binary') );
.indexOf(Buffer.from('d', 'binary'), 0, 'binary'), 3); assert.strictEqual(
assert.equal( Buffer.from(b.toString('binary'), 'binary')
Buffer.from('aa\u00e8aa', 'binary') .indexOf(Buffer.from('d', 'binary'), 0, 'binary'),
.indexOf('\u00e8', 'binary'), 2); 3
assert.equal( );
Buffer.from('\u00e8', 'binary') assert.strictEqual(
.indexOf('\u00e8', 'binary'), 0); Buffer.from('aa\u00e8aa', 'binary')
assert.equal( .indexOf('\u00e8', 'binary'),
Buffer.from('\u00e8', 'binary') 2
.indexOf(Buffer.from('\u00e8', 'binary'), 'binary'), 0); );
assert.strictEqual(
Buffer.from('\u00e8', 'binary')
.indexOf('\u00e8', 'binary'),
0
);
assert.strictEqual(
Buffer.from('\u00e8', 'binary')
.indexOf(Buffer.from('\u00e8', 'binary'), 'binary'),
0
);
// test optional offset with passed encoding // test optional offset with passed encoding

20
test/parallel/test-cluster-worker-forced-exit.js

@ -29,20 +29,16 @@ checkForced();
function checkUnforced() { function checkUnforced() {
cluster.fork() cluster.fork()
.on('online', function() { .on('online', function() { this.disconnect(); })
this.disconnect(); .on('exit', common.mustCall(function(status) {
}) assert.strictEqual(status, SENTINEL);
.on('exit', common.mustCall(function(status) { }));
assert.equal(status, SENTINEL);
}));
} }
function checkForced() { function checkForced() {
cluster.fork() cluster.fork()
.on('online', function() { .on('online', function() { this.process.disconnect(); })
this.process.disconnect(); .on('exit', common.mustCall(function(status) {
}) assert.strictEqual(status, 0);
.on('exit', common.mustCall(function(status) { }));
assert.equal(status, 0);
}));
} }

24
test/parallel/test-crypto-binary-default.js

@ -324,19 +324,23 @@ var rfc2202_sha1 = [
for (let i = 0, l = rfc2202_md5.length; i < l; i++) { for (let i = 0, l = rfc2202_md5.length; i < l; i++) {
if (!common.hasFipsCrypto) { if (!common.hasFipsCrypto) {
assert.equal(rfc2202_md5[i]['hmac'], assert.strictEqual(
crypto.createHmac('md5', rfc2202_md5[i]['key']) rfc2202_md5[i]['hmac'],
.update(rfc2202_md5[i]['data']) crypto.createHmac('md5', rfc2202_md5[i]['key'])
.digest('hex'), .update(rfc2202_md5[i]['data'])
'Test HMAC-MD5 : Test case ' + (i + 1) + ' rfc 2202'); .digest('hex'),
'Test HMAC-MD5 : Test case ' + (i + 1) + ' rfc 2202'
);
} }
} }
for (let i = 0, l = rfc2202_sha1.length; i < l; i++) { for (let i = 0, l = rfc2202_sha1.length; i < l; i++) {
assert.equal(rfc2202_sha1[i]['hmac'], assert.strictEqual(
crypto.createHmac('sha1', rfc2202_sha1[i]['key']) rfc2202_sha1[i]['hmac'],
.update(rfc2202_sha1[i]['data']) crypto.createHmac('sha1', rfc2202_sha1[i]['key'])
.digest('hex'), .update(rfc2202_sha1[i]['data'])
'Test HMAC-SHA1 : Test case ' + (i + 1) + ' rfc 2202'); .digest('hex'),
'Test HMAC-SHA1 : Test case ' + (i + 1) + ' rfc 2202'
);
} }
// Test hashing // Test hashing

24
test/parallel/test-crypto-hmac.js

@ -351,17 +351,21 @@ var rfc2202_sha1 = [
if (!common.hasFipsCrypto) { if (!common.hasFipsCrypto) {
for (let i = 0, l = rfc2202_md5.length; i < l; i++) { for (let i = 0, l = rfc2202_md5.length; i < l; i++) {
assert.equal(rfc2202_md5[i]['hmac'], assert.strictEqual(
crypto.createHmac('md5', rfc2202_md5[i]['key']) rfc2202_md5[i]['hmac'],
.update(rfc2202_md5[i]['data']) crypto.createHmac('md5', rfc2202_md5[i]['key'])
.digest('hex'), .update(rfc2202_md5[i]['data'])
'Test HMAC-MD5 : Test case ' + (i + 1) + ' rfc 2202'); .digest('hex'),
'Test HMAC-MD5 : Test case ' + (i + 1) + ' rfc 2202'
);
} }
} }
for (let i = 0, l = rfc2202_sha1.length; i < l; i++) { for (let i = 0, l = rfc2202_sha1.length; i < l; i++) {
assert.equal(rfc2202_sha1[i]['hmac'], assert.strictEqual(
crypto.createHmac('sha1', rfc2202_sha1[i]['key']) rfc2202_sha1[i]['hmac'],
.update(rfc2202_sha1[i]['data']) crypto.createHmac('sha1', rfc2202_sha1[i]['key'])
.digest('hex'), .update(rfc2202_sha1[i]['data'])
'Test HMAC-SHA1 : Test case ' + (i + 1) + ' rfc 2202'); .digest('hex'),
'Test HMAC-SHA1 : Test case ' + (i + 1) + ' rfc 2202'
);
} }

12
test/parallel/test-net-server-max-connections-close-makes-more-available.js

@ -69,12 +69,12 @@ server.maxConnections = 1;
server.listen(0, function() { server.listen(0, function() {
createConnection(0) createConnection(0)
.then(createConnection.bind(null, 1)) .then(createConnection.bind(null, 1))
.then(closeConnection.bind(null, 0)) .then(closeConnection.bind(null, 0))
.then(createConnection.bind(null, 2)) .then(createConnection.bind(null, 2))
.then(createConnection.bind(null, 3)) .then(createConnection.bind(null, 3))
.then(server.close.bind(server)) .then(server.close.bind(server))
.then(closeConnection.bind(null, 2)); .then(closeConnection.bind(null, 2));
}); });
process.on('exit', function() { process.on('exit', function() {

24
test/parallel/test-readline-interface.js

@ -346,14 +346,22 @@ function isWarned(emitter) {
assert.equal(internalReadline.getStringWidth('A\ud83c\ude00BC'), 5); assert.equal(internalReadline.getStringWidth('A\ud83c\ude00BC'), 5);
// check if vt control chars are stripped // check if vt control chars are stripped
assert.equal(internalReadline assert.strictEqual(
.stripVTControlCharacters('\u001b[31m> \u001b[39m'), '> '); internalReadline.stripVTControlCharacters('\u001b[31m> \u001b[39m'),
assert.equal(internalReadline '> '
.stripVTControlCharacters('\u001b[31m> \u001b[39m> '), '> > '); );
assert.equal(internalReadline assert.strictEqual(
.stripVTControlCharacters('\u001b[31m\u001b[39m'), ''); internalReadline.stripVTControlCharacters('\u001b[31m> \u001b[39m> '),
assert.equal(internalReadline '> > '
.stripVTControlCharacters('> '), '> '); );
assert.strictEqual(
internalReadline.stripVTControlCharacters('\u001b[31m\u001b[39m'),
''
);
assert.strictEqual(
internalReadline.stripVTControlCharacters('> '),
'> '
);
assert.equal(internalReadline.getStringWidth('\u001b[31m> \u001b[39m'), 2); assert.equal(internalReadline.getStringWidth('\u001b[31m> \u001b[39m'), 2);
assert.equal(internalReadline.getStringWidth('\u001b[31m> \u001b[39m> '), 4); assert.equal(internalReadline.getStringWidth('\u001b[31m> \u001b[39m> '), 4);
assert.equal(internalReadline.getStringWidth('\u001b[31m\u001b[39m'), 0); assert.equal(internalReadline.getStringWidth('\u001b[31m\u001b[39m'), 0);

Loading…
Cancel
Save