test: replace indexOf with includes and startsWith
PR-URL: https://github.com/nodejs/node/pull/13852 Refs: https://github.com/nodejs/node/issues/12586 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
This commit is contained in:
parent
ea927b3711
commit
20b00f3a36
@ -54,7 +54,7 @@ dInput._read = function _read(size) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
dOutput._write = function _write(chunk, encoding, cb) {
|
dOutput._write = function _write(chunk, encoding, cb) {
|
||||||
if (chunk.toString().indexOf('cb_ran') === 0)
|
if (chunk.toString().startsWith('cb_ran'))
|
||||||
cb_ran = true;
|
cb_ran = true;
|
||||||
cb();
|
cb();
|
||||||
};
|
};
|
||||||
|
@ -93,7 +93,7 @@ pipeReadStream.on('data', function(data) {
|
|||||||
var rd = JSON.parse(d);
|
var rd = JSON.parse(d);
|
||||||
|
|
||||||
assert.strictEqual(rd.pid, cpp);
|
assert.strictEqual(rd.pid, cpp);
|
||||||
assert.strictEqual(seenOrdinals.indexOf(rd.ord), -1);
|
assert.strictEqual(seenOrdinals.includes(rd.ord), false)
|
||||||
|
|
||||||
seenOrdinals.unshift(rd.ord);
|
seenOrdinals.unshift(rd.ord);
|
||||||
});
|
});
|
||||||
|
@ -117,15 +117,15 @@ testData.forEach((item) => {
|
|||||||
const actual = output.replace(spaces, '');
|
const actual = output.replace(spaces, '');
|
||||||
// Assert that the input stripped of all whitespace contains the
|
// Assert that the input stripped of all whitespace contains the
|
||||||
// expected list
|
// expected list
|
||||||
assert.notStrictEqual(actual.indexOf(expected), -1);
|
assert(actual.includes(expected));
|
||||||
|
|
||||||
// Testing the insertion of Google Analytics script when
|
// Testing the insertion of Google Analytics script when
|
||||||
// an analytics id is provided. Should not be present by default
|
// an analytics id is provided. Should not be present by default
|
||||||
if (includeAnalytics) {
|
if (includeAnalytics) {
|
||||||
assert.notStrictEqual(actual.indexOf('google-analytics.com'), -1,
|
assert(actual.includes('google-analytics.com'),
|
||||||
'Google Analytics script was not present');
|
'Google Analytics script was not present');
|
||||||
} else {
|
} else {
|
||||||
assert.strictEqual(actual.indexOf('google-analytics.com'), -1,
|
assert.strictEqual(actual.includes('google-analytics.com'), false,
|
||||||
'Google Analytics script was present');
|
'Google Analytics script was present');
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
@ -60,7 +60,7 @@ const checkers = {
|
|||||||
assert.ok(Array.isArray(r.entries));
|
assert.ok(Array.isArray(r.entries));
|
||||||
assert.ok(r.entries.length > 0);
|
assert.ok(r.entries.length > 0);
|
||||||
r.entries.forEach((txt) => {
|
r.entries.forEach((txt) => {
|
||||||
assert.strictEqual(txt.indexOf('v=spf1'), 0);
|
assert(txt.startsWith('v=spf1'));
|
||||||
});
|
});
|
||||||
assert.strictEqual(r.type, 'TXT');
|
assert.strictEqual(r.type, 'TXT');
|
||||||
},
|
},
|
||||||
|
@ -366,7 +366,7 @@ TEST(function test_resolveTxt(done) {
|
|||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.strictEqual(records.length, 1);
|
assert.strictEqual(records.length, 1);
|
||||||
assert.ok(util.isArray(records[0]));
|
assert.ok(util.isArray(records[0]));
|
||||||
assert.strictEqual(records[0][0].indexOf('v=spf1'), 0);
|
assert(records[0][0].startsWith('v=spf1'));
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ encodings
|
|||||||
const len = Buffer.byteLength('foo', encoding);
|
const len = Buffer.byteLength('foo', encoding);
|
||||||
assert.strictEqual(buf.write('foo', 0, len, encoding), len);
|
assert.strictEqual(buf.write('foo', 0, len, encoding), len);
|
||||||
|
|
||||||
if (encoding.indexOf('-') !== -1)
|
if (encoding.includes('-'))
|
||||||
encoding = encoding.replace('-', '');
|
encoding = encoding.replace('-', '');
|
||||||
|
|
||||||
assert.deepStrictEqual(buf, resultMap.get(encoding.toLowerCase()));
|
assert.deepStrictEqual(buf, resultMap.get(encoding.toLowerCase()));
|
||||||
|
@ -36,5 +36,5 @@ if (common.isWindows) {
|
|||||||
|
|
||||||
exec(pwdcommand, {cwd: dir}, common.mustCall(function(err, stdout, stderr) {
|
exec(pwdcommand, {cwd: dir}, common.mustCall(function(err, stdout, stderr) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.strictEqual(stdout.indexOf(dir), 0);
|
assert(stdout.startsWith(dir));
|
||||||
}));
|
}));
|
||||||
|
@ -137,7 +137,7 @@ assert.strictEqual("{ foo: 'bar', inspect: [Function: inspect] }\n",
|
|||||||
assert.strictEqual("{ foo: 'bar', inspect: [Function: inspect] }\n",
|
assert.strictEqual("{ foo: 'bar', inspect: [Function: inspect] }\n",
|
||||||
strings.shift());
|
strings.shift());
|
||||||
assert.ok(strings.shift().includes('foo: [Object]'));
|
assert.ok(strings.shift().includes('foo: [Object]'));
|
||||||
assert.strictEqual(-1, strings.shift().indexOf('baz'));
|
assert.strictEqual(strings.shift().includes('baz'), false);
|
||||||
assert.ok(/^label: \d+\.\d{3}ms$/.test(strings.shift().trim()));
|
assert.ok(/^label: \d+\.\d{3}ms$/.test(strings.shift().trim()));
|
||||||
assert.ok(/^__proto__: \d+\.\d{3}ms$/.test(strings.shift().trim()));
|
assert.ok(/^__proto__: \d+\.\d{3}ms$/.test(strings.shift().trim()));
|
||||||
assert.ok(/^constructor: \d+\.\d{3}ms$/.test(strings.shift().trim()));
|
assert.ok(/^constructor: \d+\.\d{3}ms$/.test(strings.shift().trim()));
|
||||||
|
@ -47,7 +47,7 @@ socket_ipv6.on('listening', common.mustNotCall());
|
|||||||
socket_ipv6.on('error', common.mustCall(function(e) {
|
socket_ipv6.on('error', common.mustCall(function(e) {
|
||||||
// EAFNOSUPPORT or EPROTONOSUPPORT means IPv6 is disabled on this system.
|
// EAFNOSUPPORT or EPROTONOSUPPORT means IPv6 is disabled on this system.
|
||||||
const allowed = ['EADDRNOTAVAIL', 'EAFNOSUPPORT', 'EPROTONOSUPPORT'];
|
const allowed = ['EADDRNOTAVAIL', 'EAFNOSUPPORT', 'EPROTONOSUPPORT'];
|
||||||
assert.notStrictEqual(allowed.indexOf(e.code), -1);
|
assert(allowed.includes(e.code));
|
||||||
assert.strictEqual(e.port, undefined);
|
assert.strictEqual(e.port, undefined);
|
||||||
assert.strictEqual(e.message, `bind ${e.code} 111::1`);
|
assert.strictEqual(e.message, `bind ${e.code} 111::1`);
|
||||||
assert.strictEqual(e.address, '111::1');
|
assert.strictEqual(e.address, '111::1');
|
||||||
|
@ -37,11 +37,8 @@ if (process.argv[2] === 'child') {
|
|||||||
});
|
});
|
||||||
|
|
||||||
child.on('close', function onChildClosed() {
|
child.on('close', function onChildClosed() {
|
||||||
assert.notStrictEqual(
|
assert(stderrOutput.includes(domainErrHandlerExMessage));
|
||||||
stderrOutput.indexOf(domainErrHandlerExMessage),
|
assert.strictEqual(stderrOutput.includes(internalExMessage), false);
|
||||||
-1
|
|
||||||
);
|
|
||||||
assert.strictEqual(stderrOutput.indexOf(internalExMessage), -1);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
child.on('exit', function onChildExited(exitCode, signal) {
|
child.on('exit', function onChildExited(exitCode, signal) {
|
||||||
|
@ -191,7 +191,7 @@ if (process.argv[2] === 'child') {
|
|||||||
|
|
||||||
if (test.messagesReceived) {
|
if (test.messagesReceived) {
|
||||||
test.messagesReceived.forEach(function(receivedMessage) {
|
test.messagesReceived.forEach(function(receivedMessage) {
|
||||||
if (test.expectedMessages.indexOf(receivedMessage) === -1) {
|
if (!test.expectedMessages.includes(receivedMessage)) {
|
||||||
assert.fail(`test ${test.fn.name} should not have sent message: ${
|
assert.fail(`test ${test.fn.name} should not have sent message: ${
|
||||||
receivedMessage} but did`);
|
receivedMessage} but did`);
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ const http = require('http');
|
|||||||
|
|
||||||
const serverSockets = [];
|
const serverSockets = [];
|
||||||
const server = http.createServer(function(req, res) {
|
const server = http.createServer(function(req, res) {
|
||||||
if (serverSockets.indexOf(req.socket) === -1) {
|
if (!serverSockets.includes(req.socket)) {
|
||||||
serverSockets.push(req.socket);
|
serverSockets.push(req.socket);
|
||||||
}
|
}
|
||||||
res.end(req.url);
|
res.end(req.url);
|
||||||
|
@ -27,7 +27,7 @@ const util = require('util');
|
|||||||
|
|
||||||
assert(Array.isArray(http.METHODS));
|
assert(Array.isArray(http.METHODS));
|
||||||
assert(http.METHODS.length > 0);
|
assert(http.METHODS.length > 0);
|
||||||
assert.notStrictEqual(http.METHODS.indexOf('GET'), -1);
|
assert(http.METHODS.includes('GET'));
|
||||||
assert.notStrictEqual(http.METHODS.indexOf('HEAD'), -1);
|
assert(http.METHODS.includes('HEAD'));
|
||||||
assert.notStrictEqual(http.METHODS.indexOf('POST'), -1);
|
assert(http.METHODS.includes('POST'));
|
||||||
assert.deepStrictEqual(util._extend([], http.METHODS), http.METHODS.sort());
|
assert.deepStrictEqual(util._extend([], http.METHODS), http.METHODS.sort());
|
||||||
|
@ -72,7 +72,7 @@ function runTest() {
|
|||||||
http.get({ port: this.address().port }, common.mustCall((response) => {
|
http.get({ port: this.address().port }, common.mustCall((response) => {
|
||||||
response.on('end', common.mustCall(() => {
|
response.on('end', common.mustCall(() => {
|
||||||
assert.strictEqual(response.headers['test'], '2');
|
assert.strictEqual(response.headers['test'], '2');
|
||||||
assert.notStrictEqual(response.rawHeaders.indexOf('Test'), -1);
|
assert(response.rawHeaders.includes('Test'));
|
||||||
s.close();
|
s.close();
|
||||||
}));
|
}));
|
||||||
response.resume();
|
response.resume();
|
||||||
|
@ -34,6 +34,6 @@ common.expectWarning('DeprecationWarning', expectedWarning);
|
|||||||
|
|
||||||
// test that server.connections property is no longer enumerable now that it
|
// test that server.connections property is no longer enumerable now that it
|
||||||
// has been marked as deprecated
|
// has been marked as deprecated
|
||||||
assert.strictEqual(Object.keys(server).indexOf('connections'), -1);
|
assert.strictEqual(Object.keys(server).includes('connections'), false);
|
||||||
|
|
||||||
assert.strictEqual(server.connections, 0);
|
assert.strictEqual(server.connections, 0);
|
||||||
|
@ -157,7 +157,7 @@ trailingTests.forEach(function(test) {
|
|||||||
if (!failed) {
|
if (!failed) {
|
||||||
for (let i = 0; i < actualKeys.length; ++i) {
|
for (let i = 0; i < actualKeys.length; ++i) {
|
||||||
const key = actualKeys[i];
|
const key = actualKeys[i];
|
||||||
if (expectedKeys.indexOf(key) === -1 || actual[key] !== expected[key]) {
|
if (!expectedKeys.includes(key) || actual[key] !== expected[key]) {
|
||||||
failed = true;
|
failed = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ if (typeof process.getgroups === 'function') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function check(a, b) {
|
function check(a, b) {
|
||||||
for (let i = 0; i < a.length; ++i) assert.notStrictEqual(b.indexOf(a[i]), -1);
|
for (let i = 0; i < a.length; ++i) assert(b.includes(a[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
function unique(groups) {
|
function unique(groups) {
|
||||||
|
@ -207,7 +207,7 @@ putIn.run(['.clear']);
|
|||||||
testMe.complete('require(\'', common.mustCall(function(error, data) {
|
testMe.complete('require(\'', common.mustCall(function(error, data) {
|
||||||
assert.strictEqual(error, null);
|
assert.strictEqual(error, null);
|
||||||
repl._builtinLibs.forEach(function(lib) {
|
repl._builtinLibs.forEach(function(lib) {
|
||||||
assert.notStrictEqual(data[0].indexOf(lib), -1, `${lib} not found`);
|
assert(data[0].includes(lib), `${lib} not found`);
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@ -215,7 +215,7 @@ testMe.complete('require(\'n', common.mustCall(function(error, data) {
|
|||||||
assert.strictEqual(error, null);
|
assert.strictEqual(error, null);
|
||||||
assert.strictEqual(data.length, 2);
|
assert.strictEqual(data.length, 2);
|
||||||
assert.strictEqual(data[1], 'n');
|
assert.strictEqual(data[1], 'n');
|
||||||
assert.notStrictEqual(data[0].indexOf('net'), -1);
|
assert(data[0].includes('net'));
|
||||||
// It's possible to pick up non-core modules too
|
// It's possible to pick up non-core modules too
|
||||||
data[0].forEach(function(completion) {
|
data[0].forEach(function(completion) {
|
||||||
if (completion)
|
if (completion)
|
||||||
@ -260,9 +260,9 @@ putIn.run(['.clear']);
|
|||||||
|
|
||||||
putIn.run(['var ary = [1,2,3];']);
|
putIn.run(['var ary = [1,2,3];']);
|
||||||
testMe.complete('ary.', common.mustCall(function(error, data) {
|
testMe.complete('ary.', common.mustCall(function(error, data) {
|
||||||
assert.strictEqual(data[0].indexOf('ary.0'), -1);
|
assert.strictEqual(data[0].includes('ary.0'), false);
|
||||||
assert.strictEqual(data[0].indexOf('ary.1'), -1);
|
assert.strictEqual(data[0].includes('ary.1'), false);
|
||||||
assert.strictEqual(data[0].indexOf('ary.2'), -1);
|
assert.strictEqual(data[0].includes('ary.2'), false);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Make sure tab completion does not include integer keys in an object
|
// Make sure tab completion does not include integer keys in an object
|
||||||
@ -270,9 +270,9 @@ putIn.run(['.clear']);
|
|||||||
putIn.run(['var obj = {1:"a","1a":"b",a:"b"};']);
|
putIn.run(['var obj = {1:"a","1a":"b",a:"b"};']);
|
||||||
|
|
||||||
testMe.complete('obj.', common.mustCall(function(error, data) {
|
testMe.complete('obj.', common.mustCall(function(error, data) {
|
||||||
assert.strictEqual(data[0].indexOf('obj.1'), -1);
|
assert.strictEqual(data[0].includes('obj.1'), false);
|
||||||
assert.strictEqual(data[0].indexOf('obj.1a'), -1);
|
assert.strictEqual(data[0].includes('obj.1a'), false);
|
||||||
assert.notStrictEqual(data[0].indexOf('obj.a'), -1);
|
assert(data[0].includes('obj.a'));
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Don't try to complete results of non-simple expressions
|
// Don't try to complete results of non-simple expressions
|
||||||
@ -286,9 +286,9 @@ putIn.run(['.clear']);
|
|||||||
putIn.run(['var obj = {1:"a","1a":"b",a:"b"};']);
|
putIn.run(['var obj = {1:"a","1a":"b",a:"b"};']);
|
||||||
|
|
||||||
testMe.complete(' obj.', common.mustCall((error, data) => {
|
testMe.complete(' obj.', common.mustCall((error, data) => {
|
||||||
assert.strictEqual(data[0].indexOf('obj.1'), -1);
|
assert.strictEqual(data[0].includes('obj.1'), false);
|
||||||
assert.strictEqual(data[0].indexOf('obj.1a'), -1);
|
assert.strictEqual(data[0].includes('obj.1a'), false);
|
||||||
assert.notStrictEqual(data[0].indexOf('obj.a'), -1);
|
assert(data[0].includes('obj.a'));
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Works inside assignments
|
// Works inside assignments
|
||||||
|
@ -59,7 +59,7 @@ const server = tls.createServer(options, function(c) {
|
|||||||
|
|
||||||
data = data.toString();
|
data = data.toString();
|
||||||
while (data.length !== 0) {
|
while (data.length !== 0) {
|
||||||
assert.strictEqual(data.indexOf(writes[receivedWrites]), 0);
|
assert(data.startsWith(writes[receivedWrites]));
|
||||||
data = data.slice(writes[receivedWrites].length);
|
data = data.slice(writes[receivedWrites].length);
|
||||||
|
|
||||||
if (++receivedWrites === writes.length) {
|
if (++receivedWrites === writes.length) {
|
||||||
|
@ -86,14 +86,14 @@ dtrace.on('exit', function(code) {
|
|||||||
for (let i = 0; i < lines.length; i++) {
|
for (let i = 0; i < lines.length; i++) {
|
||||||
const line = lines[i];
|
const line = lines[i];
|
||||||
|
|
||||||
if (line.indexOf(sentinel) === -1 || frames.length === 0)
|
if (!line.includes(sentinel) || frames.length === 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const frame = line.substr(line.indexOf(sentinel) + sentinel.length);
|
const frame = line.substr(line.indexOf(sentinel) + sentinel.length);
|
||||||
const top = frames.shift();
|
const top = frames.shift();
|
||||||
|
|
||||||
assert.strictEqual(frame.indexOf(top), 0,
|
assert(frame.startsWith(top),
|
||||||
`unexpected frame where ${top} was expected`);
|
`unexpected frame where ${top} was expected`);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.strictEqual(frames.length, 0,
|
assert.strictEqual(frames.length, 0,
|
||||||
|
@ -51,7 +51,7 @@ const tail = require('child_process').spawn('tail', ['-f', testFileName]);
|
|||||||
tail.stdout.on('data', tailCB);
|
tail.stdout.on('data', tailCB);
|
||||||
|
|
||||||
function tailCB(data) {
|
function tailCB(data) {
|
||||||
PASS = data.toString().indexOf('.') < 0;
|
PASS = !data.toString().includes('.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ const tailProc = require('child_process').spawn('tail', ['-f', testFileName]);
|
|||||||
tailProc.stdout.on('data', tailCB);
|
tailProc.stdout.on('data', tailCB);
|
||||||
|
|
||||||
function tailCB(data) {
|
function tailCB(data) {
|
||||||
PASS = data.toString().indexOf('.') < 0;
|
PASS = !data.toString().includes('.');
|
||||||
|
|
||||||
if (PASS) {
|
if (PASS) {
|
||||||
//console.error('i');
|
//console.error('i');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user