11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_cirequire('../common');
31cb0ef41Sopenharmony_ciconst assert = require('assert');
41cb0ef41Sopenharmony_ciconst path = require('path');
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ciconst failures = [];
71cb0ef41Sopenharmony_ciconst slashRE = /\//g;
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ci[
101cb0ef41Sopenharmony_ci  [__filename, '.js'],
111cb0ef41Sopenharmony_ci  ['', ''],
121cb0ef41Sopenharmony_ci  ['/path/to/file', ''],
131cb0ef41Sopenharmony_ci  ['/path/to/file.ext', '.ext'],
141cb0ef41Sopenharmony_ci  ['/path.to/file.ext', '.ext'],
151cb0ef41Sopenharmony_ci  ['/path.to/file', ''],
161cb0ef41Sopenharmony_ci  ['/path.to/.file', ''],
171cb0ef41Sopenharmony_ci  ['/path.to/.file.ext', '.ext'],
181cb0ef41Sopenharmony_ci  ['/path/to/f.ext', '.ext'],
191cb0ef41Sopenharmony_ci  ['/path/to/..ext', '.ext'],
201cb0ef41Sopenharmony_ci  ['/path/to/..', ''],
211cb0ef41Sopenharmony_ci  ['file', ''],
221cb0ef41Sopenharmony_ci  ['file.ext', '.ext'],
231cb0ef41Sopenharmony_ci  ['.file', ''],
241cb0ef41Sopenharmony_ci  ['.file.ext', '.ext'],
251cb0ef41Sopenharmony_ci  ['/file', ''],
261cb0ef41Sopenharmony_ci  ['/file.ext', '.ext'],
271cb0ef41Sopenharmony_ci  ['/.file', ''],
281cb0ef41Sopenharmony_ci  ['/.file.ext', '.ext'],
291cb0ef41Sopenharmony_ci  ['.path/file.ext', '.ext'],
301cb0ef41Sopenharmony_ci  ['file.ext.ext', '.ext'],
311cb0ef41Sopenharmony_ci  ['file.', '.'],
321cb0ef41Sopenharmony_ci  ['.', ''],
331cb0ef41Sopenharmony_ci  ['./', ''],
341cb0ef41Sopenharmony_ci  ['.file.ext', '.ext'],
351cb0ef41Sopenharmony_ci  ['.file', ''],
361cb0ef41Sopenharmony_ci  ['.file.', '.'],
371cb0ef41Sopenharmony_ci  ['.file..', '.'],
381cb0ef41Sopenharmony_ci  ['..', ''],
391cb0ef41Sopenharmony_ci  ['../', ''],
401cb0ef41Sopenharmony_ci  ['..file.ext', '.ext'],
411cb0ef41Sopenharmony_ci  ['..file', '.file'],
421cb0ef41Sopenharmony_ci  ['..file.', '.'],
431cb0ef41Sopenharmony_ci  ['..file..', '.'],
441cb0ef41Sopenharmony_ci  ['...', '.'],
451cb0ef41Sopenharmony_ci  ['...ext', '.ext'],
461cb0ef41Sopenharmony_ci  ['....', '.'],
471cb0ef41Sopenharmony_ci  ['file.ext/', '.ext'],
481cb0ef41Sopenharmony_ci  ['file.ext//', '.ext'],
491cb0ef41Sopenharmony_ci  ['file/', ''],
501cb0ef41Sopenharmony_ci  ['file//', ''],
511cb0ef41Sopenharmony_ci  ['file./', '.'],
521cb0ef41Sopenharmony_ci  ['file.//', '.'],
531cb0ef41Sopenharmony_ci].forEach((test) => {
541cb0ef41Sopenharmony_ci  const expected = test[1];
551cb0ef41Sopenharmony_ci  [path.posix.extname, path.win32.extname].forEach((extname) => {
561cb0ef41Sopenharmony_ci    let input = test[0];
571cb0ef41Sopenharmony_ci    let os;
581cb0ef41Sopenharmony_ci    if (extname === path.win32.extname) {
591cb0ef41Sopenharmony_ci      input = input.replace(slashRE, '\\');
601cb0ef41Sopenharmony_ci      os = 'win32';
611cb0ef41Sopenharmony_ci    } else {
621cb0ef41Sopenharmony_ci      os = 'posix';
631cb0ef41Sopenharmony_ci    }
641cb0ef41Sopenharmony_ci    const actual = extname(input);
651cb0ef41Sopenharmony_ci    const message = `path.${os}.extname(${JSON.stringify(input)})\n  expect=${
661cb0ef41Sopenharmony_ci      JSON.stringify(expected)}\n  actual=${JSON.stringify(actual)}`;
671cb0ef41Sopenharmony_ci    if (actual !== expected)
681cb0ef41Sopenharmony_ci      failures.push(`\n${message}`);
691cb0ef41Sopenharmony_ci  });
701cb0ef41Sopenharmony_ci  {
711cb0ef41Sopenharmony_ci    const input = `C:${test[0].replace(slashRE, '\\')}`;
721cb0ef41Sopenharmony_ci    const actual = path.win32.extname(input);
731cb0ef41Sopenharmony_ci    const message = `path.win32.extname(${JSON.stringify(input)})\n  expect=${
741cb0ef41Sopenharmony_ci      JSON.stringify(expected)}\n  actual=${JSON.stringify(actual)}`;
751cb0ef41Sopenharmony_ci    if (actual !== expected)
761cb0ef41Sopenharmony_ci      failures.push(`\n${message}`);
771cb0ef41Sopenharmony_ci  }
781cb0ef41Sopenharmony_ci});
791cb0ef41Sopenharmony_ciassert.strictEqual(failures.length, 0, failures.join(''));
801cb0ef41Sopenharmony_ci
811cb0ef41Sopenharmony_ci// On Windows, backslash is a path separator.
821cb0ef41Sopenharmony_ciassert.strictEqual(path.win32.extname('.\\'), '');
831cb0ef41Sopenharmony_ciassert.strictEqual(path.win32.extname('..\\'), '');
841cb0ef41Sopenharmony_ciassert.strictEqual(path.win32.extname('file.ext\\'), '.ext');
851cb0ef41Sopenharmony_ciassert.strictEqual(path.win32.extname('file.ext\\\\'), '.ext');
861cb0ef41Sopenharmony_ciassert.strictEqual(path.win32.extname('file\\'), '');
871cb0ef41Sopenharmony_ciassert.strictEqual(path.win32.extname('file\\\\'), '');
881cb0ef41Sopenharmony_ciassert.strictEqual(path.win32.extname('file.\\'), '.');
891cb0ef41Sopenharmony_ciassert.strictEqual(path.win32.extname('file.\\\\'), '.');
901cb0ef41Sopenharmony_ci
911cb0ef41Sopenharmony_ci// On *nix, backslash is a valid name component like any other character.
921cb0ef41Sopenharmony_ciassert.strictEqual(path.posix.extname('.\\'), '');
931cb0ef41Sopenharmony_ciassert.strictEqual(path.posix.extname('..\\'), '.\\');
941cb0ef41Sopenharmony_ciassert.strictEqual(path.posix.extname('file.ext\\'), '.ext\\');
951cb0ef41Sopenharmony_ciassert.strictEqual(path.posix.extname('file.ext\\\\'), '.ext\\\\');
961cb0ef41Sopenharmony_ciassert.strictEqual(path.posix.extname('file\\'), '');
971cb0ef41Sopenharmony_ciassert.strictEqual(path.posix.extname('file\\\\'), '');
981cb0ef41Sopenharmony_ciassert.strictEqual(path.posix.extname('file.\\'), '.\\');
991cb0ef41Sopenharmony_ciassert.strictEqual(path.posix.extname('file.\\\\'), '.\\\\');
100