From bf268bea08aa0bba7ba488fe66e95942af179b4b Mon Sep 17 00:00:00 2001 From: Peter Ogilvie Date: Fri, 9 Sep 2016 17:52:21 -0700 Subject: [PATCH 1/2] test: modernize JS and tighten equality checking Node todo process example with the follow test-net-binary.js changes: var --> const where applicable ==, assert.equal--> ===, assert.strictEqual for all cases --- test/parallel/test-net-binary.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/test/parallel/test-net-binary.js b/test/parallel/test-net-binary.js index 111682a74f3d95..0cf9749e1c1380 100644 --- a/test/parallel/test-net-binary.js +++ b/test/parallel/test-net-binary.js @@ -1,14 +1,14 @@ /* eslint-disable strict */ require('../common'); -var assert = require('assert'); -var net = require('net'); +const assert = require('assert'); +const net = require('net'); var binaryString = ''; for (var i = 255; i >= 0; i--) { - var s = '\'\\' + i.toString(8) + '\''; - var S = eval(s); - assert.ok(S.charCodeAt(0) == i); - assert.ok(S == String.fromCharCode(i)); + const s = '\'\\' + i.toString(8) + '\''; + const S = eval(s); + assert.strictEqual(S.charCodeAt(0), i); + assert.strictEqual(S, String.fromCharCode(i)); binaryString += S; } @@ -28,13 +28,13 @@ var recv = ''; echoServer.on('listening', function() { var j = 0; - var c = net.createConnection({ + const c = net.createConnection({ port: this.address().port }); c.setEncoding('latin1'); c.on('data', function(chunk) { - var n = j + chunk.length; + const n = j + chunk.length; while (j < n && j < 256) { c.write(String.fromCharCode(j), 'latin1'); j++; @@ -57,11 +57,11 @@ echoServer.on('listening', function() { process.on('exit', function() { assert.equal(2 * 256, recv.length); - var a = recv.split(''); + const a = recv.split(''); - var first = a.slice(0, 256).reverse().join(''); + const first = a.slice(0, 256).reverse().join(''); - var second = a.slice(256, 2 * 256).join(''); + const second = a.slice(256, 2 * 256).join(''); - assert.equal(first, second); + assert.strictEqual(first, second); }); From 57681c45b3d93b9372a1036585b733a5b567e86a Mon Sep 17 00:00:00 2001 From: Peter Ogilvie Date: Sat, 10 Sep 2016 14:28:06 -0700 Subject: [PATCH 2/2] use template literal --- test/parallel/test-net-binary.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-net-binary.js b/test/parallel/test-net-binary.js index 0cf9749e1c1380..47e0be8d04dcf6 100644 --- a/test/parallel/test-net-binary.js +++ b/test/parallel/test-net-binary.js @@ -5,7 +5,7 @@ const net = require('net'); var binaryString = ''; for (var i = 255; i >= 0; i--) { - const s = '\'\\' + i.toString(8) + '\''; + const s = `'\\${i.toString(8)}'`; const S = eval(s); assert.strictEqual(S.charCodeAt(0), i); assert.strictEqual(S, String.fromCharCode(i));