From ef133b36c5bf8a2920c10bbd5280a02e2d156ac3 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Tue, 2 May 2017 23:12:14 -0700 Subject: [PATCH] lib,test: use regular expression literals MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-By: Vse Mozhet Byt Reviewed-By: Refael Ackermann Reviewed-By: Yuta Hiroto Reviewed-By: Сковорода Никита Андреевич Reviewed-By: James M Snell Reviewed-By: Anna Henningsen --- test/parallel/test-buffer-alloc.js | 4 ++-- test/parallel/test-tls-env-bad-extra-ca.js | 7 +++---- test/parallel/test-tls-key-mismatch.js | 4 ++-- test/parallel/test-util-inherits.js | 3 +-- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/test/parallel/test-buffer-alloc.js b/test/parallel/test-buffer-alloc.js index 7f91080791..7ebe34b21e 100644 --- a/test/parallel/test-buffer-alloc.js +++ b/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); diff --git a/test/parallel/test-tls-env-bad-extra-ca.js b/test/parallel/test-tls-env-bad-extra-ca.js index 9b42bbbbd5..c472789659 100644 --- a/test/parallel/test-tls-env-bad-extra-ca.js +++ b/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; diff --git a/test/parallel/test-tls-key-mismatch.js b/test/parallel/test-tls-key-mismatch.js index 93c7e70d8c..742282c91e 100644 --- a/test/parallel/test-tls-key-mismatch.js +++ b/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'), diff --git a/test/parallel/test-util-inherits.js b/test/parallel/test-util-inherits.js index 4ddf9ad35d..13094ef695 100644 --- a/test/parallel/test-util-inherits.js +++ b/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