0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-fs-realpath-buffer-encoding.js
Gibson Fahnestock 7a0e462f9f test: use eslint to fix var->const/let
Manually fix issues that eslint --fix couldn't do automatically.

PR-URL: https://github.com/nodejs/node/pull/10685
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
2017-01-11 11:43:52 +00:00

90 lines
2.7 KiB
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const fs = require('fs');
const string_dir = fs.realpathSync(common.fixturesDir);
const buffer_dir = Buffer.from(string_dir);
const encodings = ['ascii', 'utf8', 'utf16le', 'ucs2',
'base64', 'binary', 'hex'];
const expected = {};
encodings.forEach((encoding) => {
expected[encoding] = buffer_dir.toString(encoding);
});
// test sync version
let encoding;
for (encoding in expected) {
const expected_value = expected[encoding];
let result;
result = fs.realpathSync(string_dir, {encoding: encoding});
assert.strictEqual(result, expected_value);
result = fs.realpathSync(string_dir, encoding);
assert.strictEqual(result, expected_value);
result = fs.realpathSync(buffer_dir, {encoding: encoding});
assert.strictEqual(result, expected_value);
result = fs.realpathSync(buffer_dir, encoding);
assert.strictEqual(result, expected_value);
}
let buffer_result;
buffer_result = fs.realpathSync(string_dir, {encoding: 'buffer'});
assert.deepStrictEqual(buffer_result, buffer_dir);
buffer_result = fs.realpathSync(string_dir, 'buffer');
assert.deepStrictEqual(buffer_result, buffer_dir);
buffer_result = fs.realpathSync(buffer_dir, {encoding: 'buffer'});
assert.deepStrictEqual(buffer_result, buffer_dir);
buffer_result = fs.realpathSync(buffer_dir, 'buffer');
assert.deepStrictEqual(buffer_result, buffer_dir);
// test async version
for (encoding in expected) {
const expected_value = expected[encoding];
fs.realpath(string_dir, {encoding: encoding}, common.mustCall((err, res) => {
assert.ifError(err);
assert.strictEqual(res, expected_value);
}));
fs.realpath(string_dir, encoding, common.mustCall((err, res) => {
assert.ifError(err);
assert.strictEqual(res, expected_value);
}));
fs.realpath(buffer_dir, {encoding: encoding}, common.mustCall((err, res) => {
assert.ifError(err);
assert.strictEqual(res, expected_value);
}));
fs.realpath(buffer_dir, encoding, common.mustCall((err, res) => {
assert.ifError(err);
assert.strictEqual(res, expected_value);
}));
}
fs.realpath(string_dir, {encoding: 'buffer'}, common.mustCall((err, res) => {
assert.ifError(err);
assert.deepStrictEqual(res, buffer_dir);
}));
fs.realpath(string_dir, 'buffer', common.mustCall((err, res) => {
assert.ifError(err);
assert.deepStrictEqual(res, buffer_dir);
}));
fs.realpath(buffer_dir, {encoding: 'buffer'}, common.mustCall((err, res) => {
assert.ifError(err);
assert.deepStrictEqual(res, buffer_dir);
}));
fs.realpath(buffer_dir, 'buffer', common.mustCall((err, res) => {
assert.ifError(err);
assert.deepStrictEqual(res, buffer_dir);
}));