Skip to content
Permalink
Browse files

test: swap actual and expected in assertions

'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 <cjihrig@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Shelley Vohr <codebytere@gmail.com>
  • Loading branch information...
yitongding authored and MylesBorins committed Oct 12, 2018
1 parent 5b95bdf commit 762c2d03fc76353e8baa957678f557f201365e0b
Showing with 15 additions and 15 deletions.
  1. +15 −15 test/parallel/test-fs-write.js
@@ -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 */

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

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

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

0 comments on commit 762c2d0

Please sign in to comment.
You can’t perform that action at this time.