Skip to content

Commit

Permalink
test: use repeat() instead of new Array().join()
Browse files Browse the repository at this point in the history
The usage of `new Array(length + 1).join(str)` is strange.
Change to `str.repeat(length)` is more clearly.

PR-URL: #11071
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Evan Lucas <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Yuta Hiroto <[email protected]>
Reviewed-By: Italo A. Casas <[email protected]>
  • Loading branch information
JacksonTian authored and italoacasas committed Feb 14, 2017
1 parent ea5bef5 commit e2d9c23
Show file tree
Hide file tree
Showing 10 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion test/parallel/test-buffer-concat.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const flatLongLen = Buffer.concat(long, 40);
assert.strictEqual(flatZero.length, 0);
assert.strictEqual(flatOne.toString(), 'asdf');

const check = new Array(10 + 1).join('asdf');
const check = 'asdf'.repeat(10);

// A special case where concat used to return the first item,
// if the length is one. This check is to make sure that we don't do that.
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-fs-long-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if (!common.isWindows) {

// make a path that will be at least 260 chars long.
const fileNameLen = Math.max(260 - common.tmpDir.length - 1, 1);
const fileName = path.join(common.tmpDir, new Array(fileNameLen + 1).join('x'));
const fileName = path.join(common.tmpDir, 'x'.repeat(fileNameLen));
const fullPath = path.resolve(fileName);

common.refreshTmpDir();
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-fs-readfile-pipe-large.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ if (process.argv[2] === 'child') {
}

const filename = path.join(common.tmpDir, '/readfile_pipe_large_test.txt');
const dataExpected = new Array(1000000).join('a');
const dataExpected = 'a'.repeat(999999);
common.refreshTmpDir();
fs.writeFileSync(filename, dataExpected);

Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-fs-readfilesync-pipe-large.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ if (process.argv[2] === 'child') {
}

const filename = path.join(common.tmpDir, '/readfilesync_pipe_large_test.txt');
const dataExpected = new Array(1000000).join('a');
const dataExpected = 'a'.repeat(999999);
common.refreshTmpDir();
fs.writeFileSync(filename, dataExpected);

Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http-byteswritten.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const httpServer = http.createServer(common.mustCall(function(req, res) {

// Write 1.5mb to cause some requests to buffer
// Also, mix up the encodings a bit.
const chunk = new Array(1024 + 1).join('7');
const chunk = '7'.repeat(1024);
const bchunk = Buffer.from(chunk);
for (let i = 0; i < 1024; i++) {
res.write(chunk);
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http-pipeline-flood.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function child() {

let req = `GET / HTTP/1.1\r\nHost: localhost:${port}\r\nAccept: */*\r\n\r\n`;

req = new Array(10241).join(req);
req = req.repeat(10240);

conn.on('connect', write);

Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http-pipeline-regr-3332.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const server = http.createServer(function(req, res) {
}
});
}).listen(0, function() {
const req = new Array(COUNT + 1).join('GET / HTTP/1.1\r\n\r\n');
const req = 'GET / HTTP/1.1\r\n\r\n'.repeat(COUNT);
client = net.connect(this.address().port, function() {
client.write(req);
});
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-stream2-writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ TestWriter.prototype._write = function(chunk, encoding, cb) {

const chunks = new Array(50);
for (let i = 0; i < chunks.length; i++) {
chunks[i] = new Array(i + 1).join('x');
chunks[i] = 'x'.repeat(i);
}

// tiny node-tap lookalike.
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-string-decoder-end.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const bufs = [ '☃💩', 'asdf' ].map((b) => Buffer.from(b));

// also test just arbitrary bytes from 0-15.
for (let i = 1; i <= 16; i++) {
const bytes = new Array(i).join('.').split('.').map((_, j) => j + 0x78);
const bytes = '.'.repeat(i - 1).split('.').map((_, j) => j + 0x78);
bufs.push(Buffer.from(bytes));
}

Expand Down
2 changes: 1 addition & 1 deletion test/pummel/test-tls-server-large-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const fs = require('fs');
const stream = require('stream');
const util = require('util');

const request = Buffer.from(new Array(1024 * 256).join('ABCD')); // 1mb
const request = Buffer.from('ABCD'.repeat(1024 * 256 - 1)); // 1mb

const options = {
key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),
Expand Down

0 comments on commit e2d9c23

Please sign in to comment.