summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorRich Trott <rtrott@gmail.com>2017-05-02 23:12:14 -0700
committerAnna Henningsen <anna@addaleax.net>2017-05-05 13:44:39 +0200
commit6bcf65d4a788a73b3c3f27d75796609f948f7885 (patch)
tree4347baf91aa14ed9e09780cadd9ed0200501eca6 /test
parentfeb90d37ff542c58612c800bb89a4574bcfb25a9 (diff)
downloadandroid-node-v8-6bcf65d4a788a73b3c3f27d75796609f948f7885.tar.gz
android-node-v8-6bcf65d4a788a73b3c3f27d75796609f948f7885.tar.bz2
android-node-v8-6bcf65d4a788a73b3c3f27d75796609f948f7885.zip
lib,test: use regular expression literals
Replace RegExp constructors with regular expression literals where possible. PR-URL: https://github.com/nodejs/node/pull/12807 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>
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-buffer-alloc.js4
-rw-r--r--test/parallel/test-crypto-dh.js8
-rw-r--r--test/parallel/test-crypto-rsa-dsa.js4
-rw-r--r--test/parallel/test-dgram-send-address-types.js4
-rw-r--r--test/parallel/test-fs-write-stream-throw-type-error.js8
-rw-r--r--test/parallel/test-tls-env-bad-extra-ca.js7
-rw-r--r--test/parallel/test-tls-key-mismatch.js4
-rw-r--r--test/parallel/test-util-inherits.js3
-rw-r--r--test/parallel/test-whatwg-url-properties.js6
-rw-r--r--test/parallel/test-zlib-deflate-constructors.js3
-rw-r--r--test/parallel/test-zlib-not-string-or-buffer.js3
11 files changed, 23 insertions, 31 deletions
diff --git a/test/parallel/test-buffer-alloc.js b/test/parallel/test-buffer-alloc.js
index 7b868f783e..ca68a27a90 100644
--- a/test/parallel/test-buffer-alloc.js
+++ b/test/parallel/test-buffer-alloc.js
@@ -927,8 +927,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-crypto-dh.js b/test/parallel/test-crypto-dh.js
index 6ff22c83a5..fed392cd9f 100644
--- a/test/parallel/test-crypto-dh.js
+++ b/test/parallel/test-crypto-dh.js
@@ -23,9 +23,8 @@ assert.strictEqual(secret2.toString('base64'), secret1);
assert.strictEqual(dh1.verifyError, 0);
assert.strictEqual(dh2.verifyError, 0);
-const argumentsError = new RegExp('^TypeError: First argument should be ' +
- 'number, string, Buffer, TypedArray, or ' +
- 'DataView$');
+const argumentsError =
+ /^TypeError: First argument should be number, string, Buffer, TypedArray, or DataView$/;
assert.throws(() => {
crypto.createDiffieHellman([0x1, 0x2]);
@@ -61,8 +60,7 @@ const secret3 = dh3.computeSecret(key2, 'hex', 'base64');
assert.strictEqual(secret1, secret3);
const wrongBlockLength =
- new RegExp('^Error: error:0606506D:digital envelope' +
- ' routines:EVP_DecryptFinal_ex:wrong final block length$');
+ /^Error: error:0606506D:digital envelope routines:EVP_DecryptFinal_ex:wrong final block length$/;
// Run this one twice to make sure that the dh3 clears its error properly
{
diff --git a/test/parallel/test-crypto-rsa-dsa.js b/test/parallel/test-crypto-rsa-dsa.js
index bb529f2454..dabdac3433 100644
--- a/test/parallel/test-crypto-rsa-dsa.js
+++ b/test/parallel/test-crypto-rsa-dsa.js
@@ -26,8 +26,8 @@ const dsaKeyPem = fs.readFileSync(common.fixturesDir + '/test_dsa_privkey.pem',
const dsaKeyPemEncrypted = fs.readFileSync(
common.fixturesDir + '/test_dsa_privkey_encrypted.pem', 'ascii');
-const decryptError = new RegExp('^Error: error:06065064:digital envelope ' +
- 'routines:EVP_DecryptFinal_ex:bad decrypt$');
+const decryptError =
+ /^Error: error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt$/;
// Test RSA encryption/decryption
{
diff --git a/test/parallel/test-dgram-send-address-types.js b/test/parallel/test-dgram-send-address-types.js
index 1c36d0d60b..d064898aa9 100644
--- a/test/parallel/test-dgram-send-address-types.js
+++ b/test/parallel/test-dgram-send-address-types.js
@@ -30,8 +30,8 @@ client.send(buf, port, undefined, onMessage);
// valid address: not provided
client.send(buf, port, onMessage);
-const expectedError = new RegExp('^TypeError: Invalid arguments: address ' +
- 'must be a nonempty string or falsy$');
+const expectedError =
+ /^TypeError: Invalid arguments: address must be a nonempty string or falsy$/;
// invalid address: object
assert.throws(() => {
diff --git a/test/parallel/test-fs-write-stream-throw-type-error.js b/test/parallel/test-fs-write-stream-throw-type-error.js
index 3e1b0c0779..62627e1e32 100644
--- a/test/parallel/test-fs-write-stream-throw-type-error.js
+++ b/test/parallel/test-fs-write-stream-throw-type-error.js
@@ -4,11 +4,11 @@ const assert = require('assert');
const fs = require('fs');
const path = require('path');
-const numberError = new RegExp('^TypeError: "options" must be a string ' +
- 'or an object, got number instead\\.$');
+const numberError =
+ /^TypeError: "options" must be a string or an object, got number instead\.$/;
-const booleanError = new RegExp('^TypeError: "options" must be a string ' +
- 'or an object, got boolean instead\\.$');
+const booleanError =
+ /^TypeError: "options" must be a string or an object, got boolean instead\.$/;
const example = path.join(common.tmpDir, 'dummy');
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 8de8f7fd8d..f741732492 100644
--- a/test/parallel/test-tls-key-mismatch.js
+++ b/test/parallel/test-tls-key-mismatch.js
@@ -29,8 +29,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
diff --git a/test/parallel/test-whatwg-url-properties.js b/test/parallel/test-whatwg-url-properties.js
index c5d60229a9..747206a5e0 100644
--- a/test/parallel/test-whatwg-url-properties.js
+++ b/test/parallel/test-whatwg-url-properties.js
@@ -44,8 +44,7 @@ assert.strictEqual(url.searchParams, oldParams); // [SameObject]
// non-writable property should throw.
// Note: this error message is subject to change in V8 updates
assert.throws(() => url.origin = 'http://foo.bar.com:22',
- new RegExp('TypeError: Cannot set property origin of' +
- ' \\[object URL\\] which has only a getter'));
+ /TypeError: Cannot set property origin of \[object URL\] which has only a getter$/);
assert.strictEqual(url.origin, 'http://foo.bar.com:21');
assert.strictEqual(url.toString(),
'http://user:pass@foo.bar.com:21/aaa/zzz?l=25#test');
@@ -120,8 +119,7 @@ assert.strictEqual(url.hash, '#abcd');
// non-writable property should throw.
// Note: this error message is subject to change in V8 updates
assert.throws(() => url.searchParams = '?k=88',
- new RegExp('TypeError: Cannot set property searchParams of' +
- ' \\[object URL\\] which has only a getter'));
+ /^TypeError: Cannot set property searchParams of \[object URL\] which has only a getter$/);
assert.strictEqual(url.searchParams, oldParams);
assert.strictEqual(url.toString(),
'https://user2:pass2@foo.bar.org:23/aaa/bbb?k=99#abcd');
diff --git a/test/parallel/test-zlib-deflate-constructors.js b/test/parallel/test-zlib-deflate-constructors.js
index 49695fbaa5..d34bb869e3 100644
--- a/test/parallel/test-zlib-deflate-constructors.js
+++ b/test/parallel/test-zlib-deflate-constructors.js
@@ -107,6 +107,5 @@ assert.throws(
// Throws if opts.dictionary is not a Buffer
assert.throws(
() => { new zlib.Deflate({dictionary: 'not a buffer'}); },
- new RegExp('^TypeError: Invalid dictionary: it should be a Buffer, ' +
- 'TypedArray, or DataView$')
+ /^TypeError: Invalid dictionary: it should be a Buffer, TypedArray, or DataView$/
);
diff --git a/test/parallel/test-zlib-not-string-or-buffer.js b/test/parallel/test-zlib-not-string-or-buffer.js
index 43488f0075..9bbee01786 100644
--- a/test/parallel/test-zlib-not-string-or-buffer.js
+++ b/test/parallel/test-zlib-not-string-or-buffer.js
@@ -7,8 +7,7 @@ require('../common');
const assert = require('assert');
const zlib = require('zlib');
-const expected = new RegExp('^TypeError: "buffer" argument must be a string, ' +
- 'Buffer, TypedArray, or DataView$');
+const expected = /^TypeError: "buffer" argument must be a string, Buffer, TypedArray, or DataView$/;
assert.throws(() => { zlib.deflateSync(undefined); }, expected);
assert.throws(() => { zlib.deflateSync(null); }, expected);