From fd7f87ef402c87580df168151ed1cbd644623699 Mon Sep 17 00:00:00 2001 From: Ishan Aditya Date: Sat, 17 Sep 2016 14:39:36 +0200 Subject: [PATCH] test: var variables to const in zlib MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changes in test-zlib-from-string is because var->const pushed us over the max char limit per line. PR-URL: https://github.com/nodejs/node/pull/8627 Reviewed-By: Colin Ihrig Reviewed-By: Michael Dawson Reviewed-By: targos - Michaël Zasso Reviewed-By: Anna Henningsen --- test/parallel/test-zlib-close-after-write.js | 4 +- test/parallel/test-zlib-const.js | 4 +- .../parallel/test-zlib-convenience-methods.js | 8 +-- test/parallel/test-zlib-dictionary-fail.js | 6 +- test/parallel/test-zlib-flush.js | 10 ++-- test/parallel/test-zlib-from-gzip.js | 26 ++++----- test/parallel/test-zlib-from-string.js | 57 ++++++++++--------- test/parallel/test-zlib-invalid-input.js | 4 +- test/parallel/test-zlib-params.js | 13 +++-- test/parallel/test-zlib-random-byte-pipes.js | 18 +++--- test/parallel/test-zlib-write-after-close.js | 6 +- test/parallel/test-zlib-write-after-flush.js | 10 ++-- test/parallel/test-zlib-zero-byte.js | 8 +-- test/parallel/test-zlib.js | 8 +-- 14 files changed, 92 insertions(+), 90 deletions(-) diff --git a/test/parallel/test-zlib-close-after-write.js b/test/parallel/test-zlib-close-after-write.js index 4e99ad07760ad4..d25ccfe381f113 100644 --- a/test/parallel/test-zlib-close-after-write.js +++ b/test/parallel/test-zlib-close-after-write.js @@ -1,9 +1,9 @@ 'use strict'; const common = require('../common'); -var zlib = require('zlib'); +const zlib = require('zlib'); zlib.gzip('hello', common.mustCall(function(err, out) { - var unzip = zlib.createGunzip(); + const unzip = zlib.createGunzip(); unzip.write(out); unzip.close(common.mustCall(function() {})); })); diff --git a/test/parallel/test-zlib-const.js b/test/parallel/test-zlib-const.js index b7eb31d2c5f48c..22852b297e7ed0 100644 --- a/test/parallel/test-zlib-const.js +++ b/test/parallel/test-zlib-const.js @@ -1,8 +1,8 @@ /* eslint-disable strict */ require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var zlib = require('zlib'); +const zlib = require('zlib'); assert.equal(zlib.Z_OK, 0, 'Z_OK should be 0'); zlib.Z_OK = 1; diff --git a/test/parallel/test-zlib-convenience-methods.js b/test/parallel/test-zlib-convenience-methods.js index ccb3347266a9b4..3aac0142b55d66 100644 --- a/test/parallel/test-zlib-convenience-methods.js +++ b/test/parallel/test-zlib-convenience-methods.js @@ -2,13 +2,13 @@ // test convenience methods with and without options supplied require('../common'); -var assert = require('assert'); -var zlib = require('zlib'); +const assert = require('assert'); +const zlib = require('zlib'); var hadRun = 0; -var expect = 'blahblahblahblahblahblah'; -var opts = { +const expect = 'blahblahblahblahblahblah'; +const opts = { level: 9, chunkSize: 1024, }; diff --git a/test/parallel/test-zlib-dictionary-fail.js b/test/parallel/test-zlib-dictionary-fail.js index 21c94b2c41015b..52f295157b7e4f 100644 --- a/test/parallel/test-zlib-dictionary-fail.js +++ b/test/parallel/test-zlib-dictionary-fail.js @@ -1,7 +1,7 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var zlib = require('zlib'); +const common = require('../common'); +const assert = require('assert'); +const zlib = require('zlib'); // Should raise an error, not trigger an assertion in src/node_zlib.cc { diff --git a/test/parallel/test-zlib-flush.js b/test/parallel/test-zlib-flush.js index 1bec5ff54391f6..abaa9ed2953d49 100644 --- a/test/parallel/test-zlib-flush.js +++ b/test/parallel/test-zlib-flush.js @@ -1,9 +1,9 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var zlib = require('zlib'); -var path = require('path'); -var fs = require('fs'); +const common = require('../common'); +const assert = require('assert'); +const zlib = require('zlib'); +const path = require('path'); +const fs = require('fs'); const file = fs.readFileSync(path.resolve(common.fixturesDir, 'person.jpg')); const chunkSize = 16; diff --git a/test/parallel/test-zlib-from-gzip.js b/test/parallel/test-zlib-from-gzip.js index 5d1c4bb562da52..3739d8f9b48b28 100644 --- a/test/parallel/test-zlib-from-gzip.js +++ b/test/parallel/test-zlib-from-gzip.js @@ -2,27 +2,27 @@ // test unzipping a file that was created with a non-node gzip lib, // piped in as fast as possible. -var common = require('../common'); -var assert = require('assert'); -var zlib = require('zlib'); -var path = require('path'); +const common = require('../common'); +const assert = require('assert'); +const zlib = require('zlib'); +const path = require('path'); common.refreshTmpDir(); -var gunzip = zlib.createGunzip(); +const gunzip = zlib.createGunzip(); -var fs = require('fs'); +const fs = require('fs'); -var fixture = path.resolve(common.fixturesDir, 'person.jpg.gz'); -var unzippedFixture = path.resolve(common.fixturesDir, 'person.jpg'); -var outputFile = path.resolve(common.tmpDir, 'person.jpg'); -var expect = fs.readFileSync(unzippedFixture); -var inp = fs.createReadStream(fixture); -var out = fs.createWriteStream(outputFile); +const fixture = path.resolve(common.fixturesDir, 'person.jpg.gz'); +const unzippedFixture = path.resolve(common.fixturesDir, 'person.jpg'); +const outputFile = path.resolve(common.tmpDir, 'person.jpg'); +const expect = fs.readFileSync(unzippedFixture); +const inp = fs.createReadStream(fixture); +const out = fs.createWriteStream(outputFile); inp.pipe(gunzip).pipe(out); out.on('close', function() { - var actual = fs.readFileSync(outputFile); + const actual = fs.readFileSync(outputFile); assert.equal(actual.length, expect.length, 'length should match'); for (var i = 0, l = actual.length; i < l; i++) { assert.equal(actual[i], expect[i], 'byte[' + i + ']'); diff --git a/test/parallel/test-zlib-from-string.js b/test/parallel/test-zlib-from-string.js index bff81b78d67ced..f3b8426eb4d862 100644 --- a/test/parallel/test-zlib-from-string.js +++ b/test/parallel/test-zlib-from-string.js @@ -2,35 +2,36 @@ // test compressing and uncompressing a string with zlib require('../common'); -var assert = require('assert'); -var zlib = require('zlib'); +const assert = require('assert'); +const zlib = require('zlib'); -var inputString = 'ΩΩLorem ipsum dolor sit amet, consectetur adipiscing elit.' + - ' Morbi faucibus, purus at gravida dictum, libero arcu conv' + - 'allis lacus, in commodo libero metus eu nisi. Nullam commo' + - 'do, neque nec porta placerat, nisi est fermentum augue, vi' + - 'tae gravida tellus sapien sit amet tellus. Aenean non diam' + - ' orci. Proin quis elit turpis. Suspendisse non diam ipsum.' + - ' Suspendisse nec ullamcorper odio. Vestibulum arcu mi, sod' + - 'ales non suscipit id, ultrices ut massa. Sed ac sem sit am' + - 'et arcu malesuada fermentum. Nunc sed. '; -var expectedBase64Deflate = 'eJxdUUtOQzEMvMoc4OndgT0gJCT2buJWlpI4jePeqZfpmXAK' + - 'LRKbLOzx/HK73q6vOrhCunlF1qIDJhNUeW5I2ozT5OkDlKWL' + - 'JWkncJG5403HQXAkT3Jw29B9uIEmToMukglZ0vS6ociBh4JG' + - '8sV4oVLEUCitK2kxq1WzPnChHDzsaGKy491LofoAbWh8do43' + - 'oeuYhB5EPCjcLjzYJo48KrfQBvnJecNFJvHT1+RSQsGoC7dn' + - '2t/xjhduTA1NWyQIZR0pbHwMDatnD+crPqKSqGPHp1vnlsWM' + - '/07ubf7bheF7kqSj84Bm0R1fYTfaK8vqqqfKBtNMhe3OZh6N' + - '95CTvMX5HJJi4xOVzCgUOIMSLH7wmeOHaFE4RdpnGavKtrB5' + - 'xzfO/Ll9'; -var expectedBase64Gzip = 'H4sIAAAAAAAAA11RS05DMQy8yhzg6d2BPSAkJPZu4laWkjiN496' + - 'pl+mZcAotEpss7PH8crverq86uEK6eUXWogMmE1R5bkjajNPk6Q' + - 'OUpYslaSdwkbnjTcdBcCRPcnDb0H24gSZOgy6SCVnS9LqhyIGHg' + - 'kbyxXihUsRQKK0raTGrVbM+cKEcPOxoYrLj3Uuh+gBtaHx2jjeh' + - '65iEHkQ8KNwuPNgmjjwqt9AG+cl5w0Um8dPX5FJCwagLt2fa3/G' + - 'OF25MDU1bJAhlHSlsfAwNq2cP5ys+opKoY8enW+eWxYz/Tu5t/t' + - 'uF4XuSpKPzgGbRHV9hN9ory+qqp8oG00yF7c5mHo33kJO8xfkck' + - 'mLjE5XMKBQ4gxIsfvCZ44doUThF2mcZq8q2sHnHNzRtagj5AQAA'; +const inputString = 'ΩΩLorem ipsum dolor sit amet, consectetur adipiscing eli' + + 't. Morbi faucibus, purus at gravida dictum, libero arcu ' + + 'convallis lacus, in commodo libero metus eu nisi. Nullam' + + ' commodo, neque nec porta placerat, nisi est fermentum a' + + 'ugue, vitae gravida tellus sapien sit amet tellus. Aenea' + + 'n non diam orci. Proin quis elit turpis. Suspendisse non' + + ' diam ipsum. Suspendisse nec ullamcorper odio. Vestibulu' + + 'm arcu mi, sodales non suscipit id, ultrices ut massa. S' + + 'ed ac sem sit amet arcu malesuada fermentum. Nunc sed. '; +const expectedBase64Deflate = 'eJxdUUtOQzEMvMoc4OndgT0gJCT2buJWlpI4jePeqZfpmX' + + 'AKLRKbLOzx/HK73q6vOrhCunlF1qIDJhNUeW5I2ozT5OkD' + + 'lKWLJWkncJG5403HQXAkT3Jw29B9uIEmToMukglZ0vS6oc' + + 'iBh4JG8sV4oVLEUCitK2kxq1WzPnChHDzsaGKy491LofoA' + + 'bWh8do43oeuYhB5EPCjcLjzYJo48KrfQBvnJecNFJvHT1+' + + 'RSQsGoC7dn2t/xjhduTA1NWyQIZR0pbHwMDatnD+crPqKS' + + 'qGPHp1vnlsWM/07ubf7bheF7kqSj84Bm0R1fYTfaK8vqqq' + + 'fKBtNMhe3OZh6N95CTvMX5HJJi4xOVzCgUOIMSLH7wmeOH' + + 'aFE4RdpnGavKtrB5xzfO/Ll9'; +const expectedBase64Gzip = 'H4sIAAAAAAAAA11RS05DMQy8yhzg6d2BPSAkJPZu4laWkjiN4' + + '96pl+mZcAotEpss7PH8crverq86uEK6eUXWogMmE1R5bkjajN' + + 'Pk6QOUpYslaSdwkbnjTcdBcCRPcnDb0H24gSZOgy6SCVnS9Lq' + + 'hyIGHgkbyxXihUsRQKK0raTGrVbM+cKEcPOxoYrLj3Uuh+gBt' + + 'aHx2jjeh65iEHkQ8KNwuPNgmjjwqt9AG+cl5w0Um8dPX5FJCw' + + 'agLt2fa3/GOF25MDU1bJAhlHSlsfAwNq2cP5ys+opKoY8enW+' + + 'eWxYz/Tu5t/tuF4XuSpKPzgGbRHV9hN9ory+qqp8oG00yF7c5' + + 'mHo33kJO8xfkckmLjE5XMKBQ4gxIsfvCZ44doUThF2mcZq8q2' + + 'sHnHNzRtagj5AQAA'; zlib.deflate(inputString, function(err, buffer) { assert.equal(buffer.toString('base64'), expectedBase64Deflate, diff --git a/test/parallel/test-zlib-invalid-input.js b/test/parallel/test-zlib-invalid-input.js index 4eb6779c4158ae..ee2ee85d73ff09 100644 --- a/test/parallel/test-zlib-invalid-input.js +++ b/test/parallel/test-zlib-invalid-input.js @@ -5,7 +5,7 @@ require('../common'); const assert = require('assert'); const zlib = require('zlib'); -var nonStringInputs = [1, true, {a: 1}, ['a']]; +const nonStringInputs = [1, true, {a: 1}, ['a']]; console.error('Doing the non-strings'); nonStringInputs.forEach(function(input) { @@ -20,7 +20,7 @@ nonStringInputs.forEach(function(input) { console.error('Doing the unzips'); // zlib.Unzip classes need to get valid data, or else they'll throw. -var unzips = [ zlib.Unzip(), +const unzips = [ zlib.Unzip(), zlib.Gunzip(), zlib.Inflate(), zlib.InflateRaw() ]; diff --git a/test/parallel/test-zlib-params.js b/test/parallel/test-zlib-params.js index eea47979e3b3db..fc5888b32ac60d 100644 --- a/test/parallel/test-zlib-params.js +++ b/test/parallel/test-zlib-params.js @@ -1,9 +1,9 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var zlib = require('zlib'); -var path = require('path'); -var fs = require('fs'); +const common = require('../common'); +const assert = require('assert'); +const zlib = require('zlib'); +const path = require('path'); +const fs = require('fs'); const file = fs.readFileSync(path.resolve(common.fixturesDir, 'person.jpg')); const chunkSize = 12 * 1024; @@ -20,7 +20,8 @@ deflater.write(chunk1, function() { deflater.params(0, zlib.Z_DEFAULT_STRATEGY, function() { while (deflater.read()); deflater.end(chunk2, function() { - var bufs = [], buf; + const bufs = []; + var buf; while (buf = deflater.read()) bufs.push(buf); actual = Buffer.concat(bufs); diff --git a/test/parallel/test-zlib-random-byte-pipes.js b/test/parallel/test-zlib-random-byte-pipes.js index 006bf14b8c2d80..6037703f7bf2ca 100644 --- a/test/parallel/test-zlib-random-byte-pipes.js +++ b/test/parallel/test-zlib-random-byte-pipes.js @@ -1,17 +1,17 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var crypto = require('crypto'); +const crypto = require('crypto'); -var stream = require('stream'); -var Stream = stream.Stream; -var util = require('util'); -var zlib = require('zlib'); +const stream = require('stream'); +const Stream = stream.Stream; +const util = require('util'); +const zlib = require('zlib'); // emit random bytes, and keep a shasum @@ -73,12 +73,12 @@ RandomReadStream.prototype._process = function() { // figure out how many bytes to output // if finished, then just emit end. var block = this._opt.block; - var jitter = this._opt.jitter; + const jitter = this._opt.jitter; if (jitter) { block += Math.ceil(Math.random() * jitter - (jitter / 2)); } block = Math.min(block, this._remaining); - var buf = Buffer.allocUnsafe(block); + const buf = Buffer.allocUnsafe(block); for (var i = 0; i < block; i++) { buf[i] = Math.random() * 256; } diff --git a/test/parallel/test-zlib-write-after-close.js b/test/parallel/test-zlib-write-after-close.js index b346d2069a5e96..0c54270ec29b13 100644 --- a/test/parallel/test-zlib-write-after-close.js +++ b/test/parallel/test-zlib-write-after-close.js @@ -1,10 +1,10 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); -var zlib = require('zlib'); +const assert = require('assert'); +const zlib = require('zlib'); zlib.gzip('hello', common.mustCall(function(err, out) { - var unzip = zlib.createGunzip(); + const unzip = zlib.createGunzip(); unzip.close(common.mustCall(function() {})); assert.throws(function() { unzip.write(out); diff --git a/test/parallel/test-zlib-write-after-flush.js b/test/parallel/test-zlib-write-after-flush.js index fa70c5f14dee6c..9409558a3dee69 100644 --- a/test/parallel/test-zlib-write-after-flush.js +++ b/test/parallel/test-zlib-write-after-flush.js @@ -1,15 +1,15 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var zlib = require('zlib'); +const assert = require('assert'); +const zlib = require('zlib'); -var gzip = zlib.createGzip(); -var gunz = zlib.createUnzip(); +const gzip = zlib.createGzip(); +const gunz = zlib.createUnzip(); gzip.pipe(gunz); var output = ''; -var input = 'A line of data\n'; +const input = 'A line of data\n'; gunz.setEncoding('utf8'); gunz.on('data', function(c) { output += c; diff --git a/test/parallel/test-zlib-zero-byte.js b/test/parallel/test-zlib-zero-byte.js index 97586040541046..ca58d06ff272ba 100644 --- a/test/parallel/test-zlib-zero-byte.js +++ b/test/parallel/test-zlib-zero-byte.js @@ -1,10 +1,10 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var zlib = require('zlib'); -var gz = zlib.Gzip(); -var emptyBuffer = Buffer.alloc(0); +const zlib = require('zlib'); +const gz = zlib.Gzip(); +const emptyBuffer = Buffer.alloc(0); var received = 0; gz.on('data', function(c) { received += c.length; diff --git a/test/parallel/test-zlib.js b/test/parallel/test-zlib.js index cd2503b86859d0..044b71db1bddd0 100644 --- a/test/parallel/test-zlib.js +++ b/test/parallel/test-zlib.js @@ -1,8 +1,8 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var zlib = require('zlib'); -var path = require('path'); +const common = require('../common'); +const assert = require('assert'); +const zlib = require('zlib'); +const path = require('path'); var zlibPairs = [[zlib.Deflate, zlib.Inflate],