1'use strict'; 2const common = require('../common'); 3const fixtures = require('../common/fixtures'); 4const assert = require('assert'); 5const fs = require('fs'); 6 7const string_dir = fs.realpathSync(fixtures.fixturesDir); 8const buffer_dir = Buffer.from(string_dir); 9 10const encodings = ['ascii', 'utf8', 'utf16le', 'ucs2', 11 'base64', 'binary', 'hex']; 12const expected = {}; 13encodings.forEach((encoding) => { 14 expected[encoding] = buffer_dir.toString(encoding); 15}); 16 17 18// test sync version 19let encoding; 20for (encoding in expected) { 21 const expected_value = expected[encoding]; 22 let result; 23 24 result = fs.realpathSync(string_dir, { encoding }); 25 assert.strictEqual(result, expected_value); 26 27 result = fs.realpathSync(string_dir, encoding); 28 assert.strictEqual(result, expected_value); 29 30 result = fs.realpathSync(buffer_dir, { encoding }); 31 assert.strictEqual(result, expected_value); 32 33 result = fs.realpathSync(buffer_dir, encoding); 34 assert.strictEqual(result, expected_value); 35} 36 37let buffer_result; 38buffer_result = fs.realpathSync(string_dir, { encoding: 'buffer' }); 39assert.deepStrictEqual(buffer_result, buffer_dir); 40 41buffer_result = fs.realpathSync(string_dir, 'buffer'); 42assert.deepStrictEqual(buffer_result, buffer_dir); 43 44buffer_result = fs.realpathSync(buffer_dir, { encoding: 'buffer' }); 45assert.deepStrictEqual(buffer_result, buffer_dir); 46 47buffer_result = fs.realpathSync(buffer_dir, 'buffer'); 48assert.deepStrictEqual(buffer_result, buffer_dir); 49 50// test async version 51for (encoding in expected) { 52 const expected_value = expected[encoding]; 53 54 fs.realpath( 55 string_dir, 56 { encoding }, 57 common.mustSucceed((res) => { 58 assert.strictEqual(res, expected_value); 59 }) 60 ); 61 fs.realpath(string_dir, encoding, common.mustSucceed((res) => { 62 assert.strictEqual(res, expected_value); 63 })); 64 fs.realpath( 65 buffer_dir, 66 { encoding }, 67 common.mustSucceed((res) => { 68 assert.strictEqual(res, expected_value); 69 }) 70 ); 71 fs.realpath(buffer_dir, encoding, common.mustSucceed((res) => { 72 assert.strictEqual(res, expected_value); 73 })); 74} 75 76fs.realpath(string_dir, { encoding: 'buffer' }, common.mustSucceed((res) => { 77 assert.deepStrictEqual(res, buffer_dir); 78})); 79 80fs.realpath(string_dir, 'buffer', common.mustSucceed((res) => { 81 assert.deepStrictEqual(res, buffer_dir); 82})); 83 84fs.realpath(buffer_dir, { encoding: 'buffer' }, common.mustSucceed((res) => { 85 assert.deepStrictEqual(res, buffer_dir); 86})); 87 88fs.realpath(buffer_dir, 'buffer', common.mustSucceed((res) => { 89 assert.deepStrictEqual(res, buffer_dir); 90})); 91