test: use String.prototype.repeat() for clarity
authorRich Trott <rtrott@gmail.com>
Thu, 18 Feb 2016 23:01:12 +0000 (15:01 -0800)
committerMyles Borins <mborins@us.ibm.com>
Wed, 2 Mar 2016 22:01:11 +0000 (14:01 -0800)
There are a few places where tests repeatedly concatenate strings to
themselves in order to make them very long. Using `.repeat()` makes the
code clearer.

For example, before:

    for (var i = 0; i < 8; ++i) lots_of_headers += lots_of_headers;

After:

    lots_of_headers = lots_of_headers.repeat(256);

Using `.repeat()` makes it clear that the string will be repeated 256
times rather than 8 times. ("What?! That first one doesn't repeat 256
times! It only repeats 8... Oh, wait. Yes, I see your point now.")

PR-URL: https://github.com/nodejs/node/pull/5311
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaƫl Zasso <mic.besace@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
test/parallel/test-crypto-from-binary.js
test/parallel/test-http-dns-error.js
test/parallel/test-http-parser.js
test/parallel/test-net-dns-error.js

index 78e3b456779c9b60e579e7f48eec9d2648170142..b2782e04f28ff0f05aab8c3da0cb84c6e124cc93 100644 (file)
@@ -19,7 +19,7 @@ var ucs2_control = 'a\u0000';
 
 // grow the strings to proper length
 while (ucs2_control.length <= EXTERN_APEX) {
-  ucs2_control += ucs2_control;
+  ucs2_control = ucs2_control.repeat(2);
 }
 
 
index ad360f5b4db4c4ac7f14c85890eeb0a7df8b9ef5..37e9fca62e01e42bfbc7d1ec31332474bfbb9f57 100644 (file)
@@ -10,12 +10,7 @@ if (common.hasCrypto) {
   console.log('1..0 # Skipped: missing crypto');
 }
 
-var host = '********';
-host += host;
-host += host;
-host += host;
-host += host;
-host += host;
+var host = '*'.repeat(256);
 
 function do_not_call() {
   throw new Error('This function should not have been called.');
index 2354871f8042484b3a6b90e3ea82ae0e53024f8e..ca7afff3aac757467415b71b544be41d5c127e67 100644 (file)
@@ -245,7 +245,7 @@ function expectBody(expected) {
 (function() {
   // 256 X-Filler headers
   var lots_of_headers = 'X-Filler: 42' + CRLF;
-  for (var i = 0; i < 8; ++i) lots_of_headers += lots_of_headers;
+  lots_of_headers = lots_of_headers.repeat(256);
 
   var request = Buffer(
       'GET /foo/bar/baz?quux=42#1337 HTTP/1.0' + CRLF +
index fc27eb1b9b07518dc3dd9d7349d9667e4ca6386e..eed59cddebb851e39a1a8e6013aaa626d876762a 100644 (file)
@@ -7,12 +7,7 @@ var net = require('net');
 var expected_bad_connections = 1;
 var actual_bad_connections = 0;
 
-var host = '********';
-host += host;
-host += host;
-host += host;
-host += host;
-host += host;
+var host = '*'.repeat(256);
 
 function do_not_call() {
   throw new Error('This function should not have been called.');