Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: use String.prototype.repeat() for clarity #5311

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/parallel/test-crypto-from-binary.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about skipping the while loop and doing

ucs2_control = ucs2_control.repeat(EXTERN_APEX / ucs2_control.length);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That will loop until the string is just under length EXTERN_APEX but I think what we want is for it to loop until it exceeds EXTERN_APEX.

To fix that, you could simply add 1 to the number that results from the division. But by looping, I preserve the power of two length as well. That may not be significant, but I don't like to mess with crypto, so I did it this way so it was exactly the same.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough.

}


Expand Down
7 changes: 1 addition & 6 deletions test/parallel/test-http-dns-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 +
Expand Down
7 changes: 1 addition & 6 deletions test/parallel/test-net-dns-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
Expand Down