11cb0ef41Sopenharmony_ci// Flags: --expose-internals
21cb0ef41Sopenharmony_ci'use strict';
31cb0ef41Sopenharmony_ci
41cb0ef41Sopenharmony_cirequire('../common');
51cb0ef41Sopenharmony_ciconst assert = require('assert');
61cb0ef41Sopenharmony_ciconst fs = require('internal/fs/utils');
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci// Valid encodings and no args should not throw.
91cb0ef41Sopenharmony_cifs.assertEncoding();
101cb0ef41Sopenharmony_cifs.assertEncoding('utf8');
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ciassert.throws(
131cb0ef41Sopenharmony_ci  () => fs.assertEncoding('foo'),
141cb0ef41Sopenharmony_ci  { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError' }
151cb0ef41Sopenharmony_ci);
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ci// Test junction symlinks
181cb0ef41Sopenharmony_ci{
191cb0ef41Sopenharmony_ci  const pathString = 'c:\\test1';
201cb0ef41Sopenharmony_ci  const linkPathString = '\\test2';
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ci  const preprocessSymlinkDestination = fs.preprocessSymlinkDestination(
231cb0ef41Sopenharmony_ci    pathString,
241cb0ef41Sopenharmony_ci    'junction',
251cb0ef41Sopenharmony_ci    linkPathString
261cb0ef41Sopenharmony_ci  );
271cb0ef41Sopenharmony_ci
281cb0ef41Sopenharmony_ci  if (process.platform === 'win32') {
291cb0ef41Sopenharmony_ci    assert.match(preprocessSymlinkDestination, /^\\\\\?\\/);
301cb0ef41Sopenharmony_ci  } else {
311cb0ef41Sopenharmony_ci    assert.strictEqual(preprocessSymlinkDestination, pathString);
321cb0ef41Sopenharmony_ci  }
331cb0ef41Sopenharmony_ci}
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_ci// Test none junction symlinks
361cb0ef41Sopenharmony_ci{
371cb0ef41Sopenharmony_ci  const pathString = 'c:\\test1';
381cb0ef41Sopenharmony_ci  const linkPathString = '\\test2';
391cb0ef41Sopenharmony_ci
401cb0ef41Sopenharmony_ci  const preprocessSymlinkDestination = fs.preprocessSymlinkDestination(
411cb0ef41Sopenharmony_ci    pathString,
421cb0ef41Sopenharmony_ci    undefined,
431cb0ef41Sopenharmony_ci    linkPathString
441cb0ef41Sopenharmony_ci  );
451cb0ef41Sopenharmony_ci
461cb0ef41Sopenharmony_ci  if (process.platform === 'win32') {
471cb0ef41Sopenharmony_ci    // There should not be any forward slashes
481cb0ef41Sopenharmony_ci    assert.strictEqual(
491cb0ef41Sopenharmony_ci      /\//.test(preprocessSymlinkDestination), false);
501cb0ef41Sopenharmony_ci  } else {
511cb0ef41Sopenharmony_ci    assert.strictEqual(preprocessSymlinkDestination, pathString);
521cb0ef41Sopenharmony_ci  }
531cb0ef41Sopenharmony_ci}
54