Skip to content

Commit 2081ab7

Browse files
TrottMyles Borins
authored and
Myles Borins
committed
test: use String.prototype.repeat() for clarity
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: #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>
1 parent d4d1446 commit 2081ab7

4 files changed

+4
-14
lines changed

test/parallel/test-crypto-from-binary.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var ucs2_control = 'a\u0000';
1919

2020
// grow the strings to proper length
2121
while (ucs2_control.length <= EXTERN_APEX) {
22-
ucs2_control += ucs2_control;
22+
ucs2_control = ucs2_control.repeat(2);
2323
}
2424

2525

test/parallel/test-http-dns-error.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,7 @@ if (common.hasCrypto) {
1010
console.log('1..0 # Skipped: missing crypto');
1111
}
1212

13-
var host = '********';
14-
host += host;
15-
host += host;
16-
host += host;
17-
host += host;
18-
host += host;
13+
var host = '*'.repeat(256);
1914

2015
function do_not_call() {
2116
throw new Error('This function should not have been called.');

test/parallel/test-http-parser.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ function expectBody(expected) {
245245
(function() {
246246
// 256 X-Filler headers
247247
var lots_of_headers = 'X-Filler: 42' + CRLF;
248-
for (var i = 0; i < 8; ++i) lots_of_headers += lots_of_headers;
248+
lots_of_headers = lots_of_headers.repeat(256);
249249

250250
var request = Buffer(
251251
'GET /foo/bar/baz?quux=42#1337 HTTP/1.0' + CRLF +

test/parallel/test-net-dns-error.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,7 @@ var net = require('net');
77
var expected_bad_connections = 1;
88
var actual_bad_connections = 0;
99

10-
var host = '********';
11-
host += host;
12-
host += host;
13-
host += host;
14-
host += host;
15-
host += host;
10+
var host = '*'.repeat(256);
1611

1712
function do_not_call() {
1813
throw new Error('This function should not have been called.');

0 commit comments

Comments
 (0)