Skip to content

Commit

Permalink
test: swap actual and expected in assertions
Browse files Browse the repository at this point in the history
'test/parallel/test-fs-write.js' contains assertions where the first
argument provided is the expected value and the second value is the
actual value. This is backward from the documentation for assertions
like 'assert.strictEqual()' where the first value should be the actual
value being tested and the second value is the expected value.

PR-URL: #23474
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Gireesh Punathil <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
Reviewed-By: Shelley Vohr <[email protected]>
  • Loading branch information
yitongding authored and MylesBorins committed Nov 29, 2018
1 parent 5b95bdf commit 762c2d0
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions test/parallel/test-fs-write.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,41 +41,41 @@ common.allowGlobals(externalizeString, isOneByteString, x);
{
const expected = 'ümlaut eins'; // Must be a unique string.
externalizeString(expected);
assert.strictEqual(true, isOneByteString(expected));
assert.strictEqual(isOneByteString(expected), true);
const fd = fs.openSync(fn, 'w');
fs.writeSync(fd, expected, 0, 'latin1');
fs.closeSync(fd);
assert.strictEqual(expected, fs.readFileSync(fn, 'latin1'));
assert.strictEqual(fs.readFileSync(fn, 'latin1'), expected);
}

{
const expected = 'ümlaut zwei'; // Must be a unique string.
externalizeString(expected);
assert.strictEqual(true, isOneByteString(expected));
assert.strictEqual(isOneByteString(expected), true);
const fd = fs.openSync(fn, 'w');
fs.writeSync(fd, expected, 0, 'utf8');
fs.closeSync(fd);
assert.strictEqual(expected, fs.readFileSync(fn, 'utf8'));
assert.strictEqual(fs.readFileSync(fn, 'utf8'), expected);
}

{
const expected = '中文 1'; // Must be a unique string.
externalizeString(expected);
assert.strictEqual(false, isOneByteString(expected));
assert.strictEqual(isOneByteString(expected), false);
const fd = fs.openSync(fn, 'w');
fs.writeSync(fd, expected, 0, 'ucs2');
fs.closeSync(fd);
assert.strictEqual(expected, fs.readFileSync(fn, 'ucs2'));
assert.strictEqual(fs.readFileSync(fn, 'ucs2'), expected);
}

{
const expected = '中文 2'; // Must be a unique string.
externalizeString(expected);
assert.strictEqual(false, isOneByteString(expected));
assert.strictEqual(isOneByteString(expected), false);
const fd = fs.openSync(fn, 'w');
fs.writeSync(fd, expected, 0, 'utf8');
fs.closeSync(fd);
assert.strictEqual(expected, fs.readFileSync(fn, 'utf8'));
assert.strictEqual(fs.readFileSync(fn, 'utf8'), expected);
}
/* eslint-enable no-undef */

Expand All @@ -84,16 +84,16 @@ fs.open(fn, 'w', 0o644, common.mustCall(function(err, fd) {

const done = common.mustCall(function(err, written) {
assert.ifError(err);
assert.strictEqual(Buffer.byteLength(expected), written);
assert.strictEqual(written, Buffer.byteLength(expected));
fs.closeSync(fd);
const found = fs.readFileSync(fn, 'utf8');
fs.unlinkSync(fn);
assert.strictEqual(expected, found);
assert.strictEqual(found, expected);
});

const written = common.mustCall(function(err, written) {
assert.ifError(err);
assert.strictEqual(0, written);
assert.strictEqual(written, 0);
fs.write(fd, expected, 0, 'utf8', done);
});

Expand All @@ -106,16 +106,16 @@ fs.open(fn2, args, 0o644, common.mustCall((err, fd) => {

const done = common.mustCall((err, written) => {
assert.ifError(err);
assert.strictEqual(Buffer.byteLength(expected), written);
assert.strictEqual(written, Buffer.byteLength(expected));
fs.closeSync(fd);
const found = fs.readFileSync(fn2, 'utf8');
fs.unlinkSync(fn2);
assert.strictEqual(expected, found);
assert.strictEqual(found, expected);
});

const written = common.mustCall(function(err, written) {
assert.ifError(err);
assert.strictEqual(0, written);
assert.strictEqual(written, 0);
fs.write(fd, expected, 0, 'utf8', done);
});

Expand All @@ -127,7 +127,7 @@ fs.open(fn3, 'w', 0o644, common.mustCall(function(err, fd) {

const done = common.mustCall(function(err, written) {
assert.ifError(err);
assert.strictEqual(Buffer.byteLength(expected), written);
assert.strictEqual(written, Buffer.byteLength(expected));
fs.closeSync(fd);
});

Expand Down

0 comments on commit 762c2d0

Please sign in to comment.