11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures'); 41cb0ef41Sopenharmony_ciconst assert = require('assert'); 51cb0ef41Sopenharmony_ciconst fs = require('fs'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciconst string_dir = fs.realpathSync(fixtures.fixturesDir); 81cb0ef41Sopenharmony_ciconst buffer_dir = Buffer.from(string_dir); 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ciconst encodings = ['ascii', 'utf8', 'utf16le', 'ucs2', 111cb0ef41Sopenharmony_ci 'base64', 'binary', 'hex']; 121cb0ef41Sopenharmony_ciconst expected = {}; 131cb0ef41Sopenharmony_ciencodings.forEach((encoding) => { 141cb0ef41Sopenharmony_ci expected[encoding] = buffer_dir.toString(encoding); 151cb0ef41Sopenharmony_ci}); 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ci// test sync version 191cb0ef41Sopenharmony_cilet encoding; 201cb0ef41Sopenharmony_cifor (encoding in expected) { 211cb0ef41Sopenharmony_ci const expected_value = expected[encoding]; 221cb0ef41Sopenharmony_ci let result; 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_ci result = fs.realpathSync(string_dir, { encoding }); 251cb0ef41Sopenharmony_ci assert.strictEqual(result, expected_value); 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ci result = fs.realpathSync(string_dir, encoding); 281cb0ef41Sopenharmony_ci assert.strictEqual(result, expected_value); 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ci result = fs.realpathSync(buffer_dir, { encoding }); 311cb0ef41Sopenharmony_ci assert.strictEqual(result, expected_value); 321cb0ef41Sopenharmony_ci 331cb0ef41Sopenharmony_ci result = fs.realpathSync(buffer_dir, encoding); 341cb0ef41Sopenharmony_ci assert.strictEqual(result, expected_value); 351cb0ef41Sopenharmony_ci} 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_cilet buffer_result; 381cb0ef41Sopenharmony_cibuffer_result = fs.realpathSync(string_dir, { encoding: 'buffer' }); 391cb0ef41Sopenharmony_ciassert.deepStrictEqual(buffer_result, buffer_dir); 401cb0ef41Sopenharmony_ci 411cb0ef41Sopenharmony_cibuffer_result = fs.realpathSync(string_dir, 'buffer'); 421cb0ef41Sopenharmony_ciassert.deepStrictEqual(buffer_result, buffer_dir); 431cb0ef41Sopenharmony_ci 441cb0ef41Sopenharmony_cibuffer_result = fs.realpathSync(buffer_dir, { encoding: 'buffer' }); 451cb0ef41Sopenharmony_ciassert.deepStrictEqual(buffer_result, buffer_dir); 461cb0ef41Sopenharmony_ci 471cb0ef41Sopenharmony_cibuffer_result = fs.realpathSync(buffer_dir, 'buffer'); 481cb0ef41Sopenharmony_ciassert.deepStrictEqual(buffer_result, buffer_dir); 491cb0ef41Sopenharmony_ci 501cb0ef41Sopenharmony_ci// test async version 511cb0ef41Sopenharmony_cifor (encoding in expected) { 521cb0ef41Sopenharmony_ci const expected_value = expected[encoding]; 531cb0ef41Sopenharmony_ci 541cb0ef41Sopenharmony_ci fs.realpath( 551cb0ef41Sopenharmony_ci string_dir, 561cb0ef41Sopenharmony_ci { encoding }, 571cb0ef41Sopenharmony_ci common.mustSucceed((res) => { 581cb0ef41Sopenharmony_ci assert.strictEqual(res, expected_value); 591cb0ef41Sopenharmony_ci }) 601cb0ef41Sopenharmony_ci ); 611cb0ef41Sopenharmony_ci fs.realpath(string_dir, encoding, common.mustSucceed((res) => { 621cb0ef41Sopenharmony_ci assert.strictEqual(res, expected_value); 631cb0ef41Sopenharmony_ci })); 641cb0ef41Sopenharmony_ci fs.realpath( 651cb0ef41Sopenharmony_ci buffer_dir, 661cb0ef41Sopenharmony_ci { encoding }, 671cb0ef41Sopenharmony_ci common.mustSucceed((res) => { 681cb0ef41Sopenharmony_ci assert.strictEqual(res, expected_value); 691cb0ef41Sopenharmony_ci }) 701cb0ef41Sopenharmony_ci ); 711cb0ef41Sopenharmony_ci fs.realpath(buffer_dir, encoding, common.mustSucceed((res) => { 721cb0ef41Sopenharmony_ci assert.strictEqual(res, expected_value); 731cb0ef41Sopenharmony_ci })); 741cb0ef41Sopenharmony_ci} 751cb0ef41Sopenharmony_ci 761cb0ef41Sopenharmony_cifs.realpath(string_dir, { encoding: 'buffer' }, common.mustSucceed((res) => { 771cb0ef41Sopenharmony_ci assert.deepStrictEqual(res, buffer_dir); 781cb0ef41Sopenharmony_ci})); 791cb0ef41Sopenharmony_ci 801cb0ef41Sopenharmony_cifs.realpath(string_dir, 'buffer', common.mustSucceed((res) => { 811cb0ef41Sopenharmony_ci assert.deepStrictEqual(res, buffer_dir); 821cb0ef41Sopenharmony_ci})); 831cb0ef41Sopenharmony_ci 841cb0ef41Sopenharmony_cifs.realpath(buffer_dir, { encoding: 'buffer' }, common.mustSucceed((res) => { 851cb0ef41Sopenharmony_ci assert.deepStrictEqual(res, buffer_dir); 861cb0ef41Sopenharmony_ci})); 871cb0ef41Sopenharmony_ci 881cb0ef41Sopenharmony_cifs.realpath(buffer_dir, 'buffer', common.mustSucceed((res) => { 891cb0ef41Sopenharmony_ci assert.deepStrictEqual(res, buffer_dir); 901cb0ef41Sopenharmony_ci})); 91