Browse Source

lib,test: use regular expression literals

Replace RegExp constructors with regular expression literals where
possible.

PR-URL: https://github.com/nodejs/node/pull/12807
Backport-PR-URL: https://github.com/nodejs/node/pull/13776
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
v6.x
Rich Trott 8 years ago
committed by Myles Borins
parent
commit
ef133b36c5
No known key found for this signature in database GPG Key ID: 933B01F40B5CA946
  1. 4
      test/parallel/test-buffer-alloc.js
  2. 7
      test/parallel/test-tls-env-bad-extra-ca.js
  3. 4
      test/parallel/test-tls-key-mismatch.js
  4. 3
      test/parallel/test-util-inherits.js

4
test/parallel/test-buffer-alloc.js

@ -984,8 +984,8 @@ Buffer.poolSize = ps;
assert.throws(() => Buffer.allocUnsafe(10).copy(),
/TypeError: argument should be a Buffer/);
const regErrorMsg = new RegExp('First argument must be a string, Buffer, ' +
'ArrayBuffer, Array, or array-like object.');
const regErrorMsg =
/First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object\./;
assert.throws(() => Buffer.from(), regErrorMsg);
assert.throws(() => Buffer.from(null), regErrorMsg);

7
test/parallel/test-tls-env-bad-extra-ca.js

@ -33,10 +33,9 @@ fork(__filename, opts)
assert.strictEqual(status, 0, 'client did not succeed in connecting');
}))
.on('close', common.mustCall(function() {
assert(stderr.match(new RegExp(
'Warning: Ignoring extra certs from.*no-such-file-exists' +
'.* load failed:.*No such file or directory'
)), stderr);
assert(stderr.match(
/Warning: Ignoring extra certs from.*no-such-file-exists.* load failed:.*No such file or directory/
), stderr);
}))
.stderr.setEncoding('utf8').on('data', function(str) {
stderr += str;

4
test/parallel/test-tls-key-mismatch.js

@ -8,8 +8,8 @@ if (!common.hasCrypto) {
const assert = require('assert');
const tls = require('tls');
const fs = require('fs');
const errorMessageRegex = new RegExp('^Error: error:0B080074:x509 ' +
'certificate routines:X509_check_private_key:key values mismatch$');
const errorMessageRegex =
/^Error: error:0B080074:x509 certificate routines:X509_check_private_key:key values mismatch$/;
const options = {
key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),

3
test/parallel/test-util-inherits.js

@ -4,8 +4,7 @@ require('../common');
const assert = require('assert');
const inherits = require('util').inherits;
const errCheck =
new RegExp('^TypeError: The super constructor to "inherits" must not be ' +
'null or undefined$');
/^TypeError: The super constructor to "inherits" must not be null or undefined$/;
// super constructor

Loading…
Cancel
Save