Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: remove needless RegExp capturing
Use non-capturing grouping or remove capturing completely when:

* capturing is useless per se, e.g. in test() check;
* captured groups are not used afterward at all;
* some of the later captured groups are not used afterward.
  • Loading branch information
vsemozhetbyt committed Jun 18, 2017
commit aa006ffb524d77ee3c51753cfd2a0efa78f72e57
2 changes: 1 addition & 1 deletion test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ function leakedGlobals() {
leaked.push(val);

if (global.__coverage__) {
return leaked.filter((varname) => !/^(cov_|__cov)/.test(varname));
return leaked.filter((varname) => !/^(?:cov_|__cov)/.test(varname));
} else {
return leaked;
}
Expand Down
2 changes: 1 addition & 1 deletion test/debugger/helper-debugger-repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function startDebugger(scriptToDebug) {
child.stderr.pipe(process.stderr);

child.on('line', function(line) {
line = line.replace(/^(debug> *)+/, '');
line = line.replace(/^(?:debug> *)+/, '');
console.log(line);
assert.ok(expected.length > 0, `Got unexpected line: ${line}`);

Expand Down
4 changes: 2 additions & 2 deletions test/inspector/inspector-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -521,11 +521,11 @@ exports.startNodeForInspectorTest = function(callback,
clearTimeout(timeoutId);
console.log('[err]', text);
if (found) return;
const match = text.match(/Debugger listening on ws:\/\/(.+):(\d+)\/(.+)/);
const match = text.match(/Debugger listening on ws:\/\/.+:(\d+)\/.+/);
found = true;
child.stderr.removeListener('data', dataCallback);
assert.ok(match, text);
callback(new Harness(match[2], child));
callback(new Harness(match[1], child));
});

child.stderr.on('data', dataCallback);
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-buffer-prototype-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ const util = require('util');

{
const buf = Buffer.from('x'.repeat(51));
assert.ok(/^<Buffer (78 ){50}\.\.\. >$/.test(util.inspect(buf)));
assert.ok(/^<Buffer (?:78 ){50}\.\.\. >$/.test(util.inspect(buf)));
}
2 changes: 1 addition & 1 deletion test/parallel/test-net-connect-options-port.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ function canConnect(port) {

function asyncFailToConnect(port) {
const onError = () => common.mustCall(function(err) {
const regexp = /^Error: connect (E\w+)(.+)$/;
const regexp = /^Error: connect E\w+.+$/;
assert(regexp.test(String(err)), String(err));
});

Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-process-emitwarning.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const testType = 'CustomWarning';

process.on('warning', common.mustCall((warning) => {
assert(warning);
assert(/^(Warning|CustomWarning)/.test(warning.name));
assert(/^(?:Warning|CustomWarning)/.test(warning.name));
assert.strictEqual(warning.message, testMsg);
if (warning.code) assert.strictEqual(warning.code, testCode);
if (warning.detail) assert.strictEqual(warning.detail, testDetail);
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-process-setuid-setgid.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ if (process.getuid() !== 0) {

assert.throws(
() => { process.setgid('nobody'); },
/^Error: (EPERM, .+|setgid group id does not exist)$/
/^Error: (?:EPERM, .+|setgid group id does not exist)$/
);

assert.throws(
() => { process.setuid('nobody'); },
/^Error: (EPERM, .+|setuid user id does not exist)$/
/^Error: (?:EPERM, .+|setuid user id does not exist)$/
);
return;
}
Expand Down
12 changes: 6 additions & 6 deletions test/parallel/test-process-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ const actual_keys = Object.keys(process.versions).sort();

assert.deepStrictEqual(actual_keys, expected_keys);

assert(/^\d+\.\d+\.\d+(-.*)?$/.test(process.versions.ares));
assert(/^\d+\.\d+\.\d+(-.*)?$/.test(process.versions.http_parser));
assert(/^\d+\.\d+\.\d+(-.*)?$/.test(process.versions.node));
assert(/^\d+\.\d+\.\d+(-.*)?$/.test(process.versions.uv));
assert(/^\d+\.\d+\.\d+(-.*)?$/.test(process.versions.zlib));
assert(/^\d+\.\d+\.\d+(\.\d+)?( \(candidate\))?$/.test(process.versions.v8));
assert(/^\d+\.\d+\.\d+(?:-.*)?$/.test(process.versions.ares));
assert(/^\d+\.\d+\.\d+(?:-.*)?$/.test(process.versions.http_parser));
assert(/^\d+\.\d+\.\d+(?:-.*)?$/.test(process.versions.node));
assert(/^\d+\.\d+\.\d+(?:-.*)?$/.test(process.versions.uv));
assert(/^\d+\.\d+\.\d+(?:-.*)?$/.test(process.versions.zlib));
assert(/^\d+\.\d+\.\d+(?:\.\d+)?(?: \(candidate\))?$/.test(process.versions.v8));
assert(/^\d+$/.test(process.versions.modules));
2 changes: 1 addition & 1 deletion test/parallel/test-socket-address.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ server.listen(0, common.mustCall(function() {
return -1;
};
assert.throws(() => this.address(),
/^Error: address ([\w|\s-\d])+$/);
/^Error: address [\w|\s-\d]+$/);
server.close();
}));
2 changes: 1 addition & 1 deletion test/parallel/test-url-parse-invalid-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const url = require('url');
Symbol('foo')
].forEach((val) => {
assert.throws(() => { url.parse(val); },
/^TypeError: Parameter "url" must be a string, not (undefined|boolean|number|object|function|symbol)$/);
/^TypeError: Parameter "url" must be a string, not (?:undefined|boolean|number|object|function|symbol)$/);
});

assert.throws(() => { url.parse('http://%E0%A4%A@fail'); },
Expand Down