Skip to content

Commit

Permalink
test: modernize JS and tighten equality checking
Browse files Browse the repository at this point in the history
Node todo process example with the follow test-net-binary.js changes:

var --> const where applicable

==, assert.equal--> ===, assert.strictEqual for all cases

PR-URL: #8476
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
pogilvie authored and Fishrock123 committed Sep 14, 2016
1 parent 1a30fe5 commit 2ce364a
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions test/parallel/test-net-binary.js
Original file line number Diff line number Diff line change
@@ -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;
}

Expand All @@ -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++;
Expand All @@ -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);
});

0 comments on commit 2ce364a

Please sign in to comment.