summaryrefslogtreecommitdiff
path: root/test/parallel/test-http-parser.js
diff options
context:
space:
mode:
authorVse Mozhet Byt <vsemozhetbyt@gmail.com>2017-04-28 04:06:42 +0300
committerVse Mozhet Byt <vsemozhetbyt@gmail.com>2017-05-05 17:39:05 +0300
commit8b76c3e60c7b5c274c757257580a2c0faae69097 (patch)
treea9f686995887dbeb0b5c5b23c5f3188987c99b2e /test/parallel/test-http-parser.js
parent6bcf65d4a788a73b3c3f27d75796609f948f7885 (diff)
downloadandroid-node-v8-8b76c3e60c7b5c274c757257580a2c0faae69097.tar.gz
android-node-v8-8b76c3e60c7b5c274c757257580a2c0faae69097.tar.bz2
android-node-v8-8b76c3e60c7b5c274c757257580a2c0faae69097.zip
test: reduce string concatenations
PR-URL: https://github.com/nodejs/node/pull/12735 Refs: https://github.com/nodejs/node/pull/12455 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Diffstat (limited to 'test/parallel/test-http-parser.js')
-rw-r--r--test/parallel/test-http-parser.js36
1 files changed, 14 insertions, 22 deletions
diff --git a/test/parallel/test-http-parser.js b/test/parallel/test-http-parser.js
index b919891cbf..f0a525cda3 100644
--- a/test/parallel/test-http-parser.js
+++ b/test/parallel/test-http-parser.js
@@ -82,7 +82,7 @@ function mustCall(f, times) {
function expectBody(expected) {
return mustCall(function(buf, start, len) {
- const body = '' + buf.slice(start, start + len);
+ const body = String(buf.slice(start, start + len));
assert.strictEqual(body, expected);
});
}
@@ -92,9 +92,7 @@ function expectBody(expected) {
// Simple request test.
//
{
- const request = Buffer.from(
- 'GET /hello HTTP/1.1' + CRLF +
- CRLF);
+ const request = Buffer.from(`GET /hello HTTP/1.1${CRLF}${CRLF}`);
const onHeadersComplete = (versionMajor, versionMinor, headers,
method, url, statusCode, statusMessage,
@@ -148,7 +146,7 @@ function expectBody(expected) {
};
const onBody = (buf, start, len) => {
- const body = '' + buf.slice(start, start + len);
+ const body = String(buf.slice(start, start + len));
assert.strictEqual(body, 'pong');
};
@@ -164,8 +162,7 @@ function expectBody(expected) {
//
{
const request = Buffer.from(
- 'HTTP/1.0 200 Connection established' + CRLF +
- CRLF);
+ `HTTP/1.0 200 Connection established${CRLF}${CRLF}`);
const onHeadersComplete = (versionMajor, versionMinor, headers,
method, url, statusCode, statusMessage,
@@ -219,7 +216,7 @@ function expectBody(expected) {
};
const onBody = (buf, start, len) => {
- const body = '' + buf.slice(start, start + len);
+ const body = String(buf.slice(start, start + len));
assert.strictEqual(body, 'ping');
seen_body = true;
};
@@ -264,8 +261,7 @@ function expectBody(expected) {
//
{
// 256 X-Filler headers
- let lots_of_headers = 'X-Filler: 42' + CRLF;
- lots_of_headers = lots_of_headers.repeat(256);
+ const lots_of_headers = `X-Filler: 42${CRLF}`.repeat(256);
const request = Buffer.from(
'GET /foo/bar/baz?quux=42#1337 HTTP/1.0' + CRLF +
@@ -316,7 +312,7 @@ function expectBody(expected) {
};
const onBody = (buf, start, len) => {
- const body = '' + buf.slice(start, start + len);
+ const body = String(buf.slice(start, start + len));
assert.strictEqual(body, 'foo=42&bar=1337');
};
@@ -357,7 +353,7 @@ function expectBody(expected) {
const body_parts = ['123', '123456', '1234567890'];
const onBody = (buf, start, len) => {
- const body = '' + buf.slice(start, start + len);
+ const body = String(buf.slice(start, start + len));
assert.strictEqual(body, body_parts[body_part++]);
};
@@ -396,7 +392,7 @@ function expectBody(expected) {
['123', '123456', '123456789', '123456789ABC', '123456789ABCDEF'];
const onBody = (buf, start, len) => {
- const body = '' + buf.slice(start, start + len);
+ const body = String(buf.slice(start, start + len));
assert.strictEqual(body, body_parts[body_part++]);
};
@@ -452,7 +448,7 @@ function expectBody(expected) {
let expected_body = '123123456123456789123456789ABC123456789ABCDEF';
const onBody = (buf, start, len) => {
- const chunk = '' + buf.slice(start, start + len);
+ const chunk = String(buf.slice(start, start + len));
assert.strictEqual(expected_body.indexOf(chunk), 0);
expected_body = expected_body.slice(chunk.length);
};
@@ -468,11 +464,9 @@ function expectBody(expected) {
for (let i = 1; i < request.length - 1; ++i) {
const a = request.slice(0, i);
- console.error('request.slice(0, ' + i + ') = ',
- JSON.stringify(a.toString()));
+ console.error(`request.slice(0, ${i}) = ${JSON.stringify(a.toString())}`);
const b = request.slice(i);
- console.error('request.slice(' + i + ') = ',
- JSON.stringify(b.toString()));
+ console.error(`request.slice(${i}) = ${JSON.stringify(b.toString())}`);
test(a, b);
}
}
@@ -514,7 +508,7 @@ function expectBody(expected) {
let expected_body = '123123456123456789123456789ABC123456789ABCDEF';
const onBody = (buf, start, len) => {
- const chunk = '' + buf.slice(start, start + len);
+ const chunk = String(buf.slice(start, start + len));
assert.strictEqual(expected_body.indexOf(chunk), 0);
expected_body = expected_body.slice(chunk.length);
};
@@ -590,9 +584,7 @@ function expectBody(expected) {
// Test parser 'this' safety
// https://github.com/joyent/node/issues/6690
assert.throws(function() {
- const request = Buffer.from(
- 'GET /hello HTTP/1.1' + CRLF +
- CRLF);
+ const request = Buffer.from(`GET /hello HTTP/1.1${CRLF}${CRLF}`);
const parser = newParser(REQUEST);
const notparser = { execute: parser.execute };