11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_cirequire('../common');
31cb0ef41Sopenharmony_ciconst assert = require('assert');
41cb0ef41Sopenharmony_ciconst path = require('path');
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ciconst failures = [];
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ciconst relativeTests = [
91cb0ef41Sopenharmony_ci  [ path.win32.relative,
101cb0ef41Sopenharmony_ci    // Arguments                     result
111cb0ef41Sopenharmony_ci    [['c:/blah\\blah', 'd:/games', 'd:\\games'],
121cb0ef41Sopenharmony_ci     ['c:/aaaa/bbbb', 'c:/aaaa', '..'],
131cb0ef41Sopenharmony_ci     ['c:/aaaa/bbbb', 'c:/cccc', '..\\..\\cccc'],
141cb0ef41Sopenharmony_ci     ['c:/aaaa/bbbb', 'c:/aaaa/bbbb', ''],
151cb0ef41Sopenharmony_ci     ['c:/aaaa/bbbb', 'c:/aaaa/cccc', '..\\cccc'],
161cb0ef41Sopenharmony_ci     ['c:/aaaa/', 'c:/aaaa/cccc', 'cccc'],
171cb0ef41Sopenharmony_ci     ['c:/', 'c:\\aaaa\\bbbb', 'aaaa\\bbbb'],
181cb0ef41Sopenharmony_ci     ['c:/aaaa/bbbb', 'd:\\', 'd:\\'],
191cb0ef41Sopenharmony_ci     ['c:/AaAa/bbbb', 'c:/aaaa/bbbb', ''],
201cb0ef41Sopenharmony_ci     ['c:/aaaaa/', 'c:/aaaa/cccc', '..\\aaaa\\cccc'],
211cb0ef41Sopenharmony_ci     ['C:\\foo\\bar\\baz\\quux', 'C:\\', '..\\..\\..\\..'],
221cb0ef41Sopenharmony_ci     ['C:\\foo\\test', 'C:\\foo\\test\\bar\\package.json', 'bar\\package.json'],
231cb0ef41Sopenharmony_ci     ['C:\\foo\\bar\\baz-quux', 'C:\\foo\\bar\\baz', '..\\baz'],
241cb0ef41Sopenharmony_ci     ['C:\\foo\\bar\\baz', 'C:\\foo\\bar\\baz-quux', '..\\baz-quux'],
251cb0ef41Sopenharmony_ci     ['\\\\foo\\bar', '\\\\foo\\bar\\baz', 'baz'],
261cb0ef41Sopenharmony_ci     ['\\\\foo\\bar\\baz', '\\\\foo\\bar', '..'],
271cb0ef41Sopenharmony_ci     ['\\\\foo\\bar\\baz-quux', '\\\\foo\\bar\\baz', '..\\baz'],
281cb0ef41Sopenharmony_ci     ['\\\\foo\\bar\\baz', '\\\\foo\\bar\\baz-quux', '..\\baz-quux'],
291cb0ef41Sopenharmony_ci     ['C:\\baz-quux', 'C:\\baz', '..\\baz'],
301cb0ef41Sopenharmony_ci     ['C:\\baz', 'C:\\baz-quux', '..\\baz-quux'],
311cb0ef41Sopenharmony_ci     ['\\\\foo\\baz-quux', '\\\\foo\\baz', '..\\baz'],
321cb0ef41Sopenharmony_ci     ['\\\\foo\\baz', '\\\\foo\\baz-quux', '..\\baz-quux'],
331cb0ef41Sopenharmony_ci     ['C:\\baz', '\\\\foo\\bar\\baz', '\\\\foo\\bar\\baz'],
341cb0ef41Sopenharmony_ci     ['\\\\foo\\bar\\baz', 'C:\\baz', 'C:\\baz'],
351cb0ef41Sopenharmony_ci    ],
361cb0ef41Sopenharmony_ci  ],
371cb0ef41Sopenharmony_ci  [ path.posix.relative,
381cb0ef41Sopenharmony_ci    // Arguments          result
391cb0ef41Sopenharmony_ci    [['/var/lib', '/var', '..'],
401cb0ef41Sopenharmony_ci     ['/var/lib', '/bin', '../../bin'],
411cb0ef41Sopenharmony_ci     ['/var/lib', '/var/lib', ''],
421cb0ef41Sopenharmony_ci     ['/var/lib', '/var/apache', '../apache'],
431cb0ef41Sopenharmony_ci     ['/var/', '/var/lib', 'lib'],
441cb0ef41Sopenharmony_ci     ['/', '/var/lib', 'var/lib'],
451cb0ef41Sopenharmony_ci     ['/foo/test', '/foo/test/bar/package.json', 'bar/package.json'],
461cb0ef41Sopenharmony_ci     ['/Users/a/web/b/test/mails', '/Users/a/web/b', '../..'],
471cb0ef41Sopenharmony_ci     ['/foo/bar/baz-quux', '/foo/bar/baz', '../baz'],
481cb0ef41Sopenharmony_ci     ['/foo/bar/baz', '/foo/bar/baz-quux', '../baz-quux'],
491cb0ef41Sopenharmony_ci     ['/baz-quux', '/baz', '../baz'],
501cb0ef41Sopenharmony_ci     ['/baz', '/baz-quux', '../baz-quux'],
511cb0ef41Sopenharmony_ci     ['/page1/page2/foo', '/', '../../..'],
521cb0ef41Sopenharmony_ci    ],
531cb0ef41Sopenharmony_ci  ],
541cb0ef41Sopenharmony_ci];
551cb0ef41Sopenharmony_cirelativeTests.forEach((test) => {
561cb0ef41Sopenharmony_ci  const relative = test[0];
571cb0ef41Sopenharmony_ci  test[1].forEach((test) => {
581cb0ef41Sopenharmony_ci    const actual = relative(test[0], test[1]);
591cb0ef41Sopenharmony_ci    const expected = test[2];
601cb0ef41Sopenharmony_ci    if (actual !== expected) {
611cb0ef41Sopenharmony_ci      const os = relative === path.win32.relative ? 'win32' : 'posix';
621cb0ef41Sopenharmony_ci      const message = `path.${os}.relative(${
631cb0ef41Sopenharmony_ci        test.slice(0, 2).map(JSON.stringify).join(',')})\n  expect=${
641cb0ef41Sopenharmony_ci        JSON.stringify(expected)}\n  actual=${JSON.stringify(actual)}`;
651cb0ef41Sopenharmony_ci      failures.push(`\n${message}`);
661cb0ef41Sopenharmony_ci    }
671cb0ef41Sopenharmony_ci  });
681cb0ef41Sopenharmony_ci});
691cb0ef41Sopenharmony_ciassert.strictEqual(failures.length, 0, failures.join(''));
70