1'use strict'; 2require('../common'); 3const assert = require('assert'); 4const path = require('path'); 5 6const failures = []; 7 8const relativeTests = [ 9 [ path.win32.relative, 10 // Arguments result 11 [['c:/blah\\blah', 'd:/games', 'd:\\games'], 12 ['c:/aaaa/bbbb', 'c:/aaaa', '..'], 13 ['c:/aaaa/bbbb', 'c:/cccc', '..\\..\\cccc'], 14 ['c:/aaaa/bbbb', 'c:/aaaa/bbbb', ''], 15 ['c:/aaaa/bbbb', 'c:/aaaa/cccc', '..\\cccc'], 16 ['c:/aaaa/', 'c:/aaaa/cccc', 'cccc'], 17 ['c:/', 'c:\\aaaa\\bbbb', 'aaaa\\bbbb'], 18 ['c:/aaaa/bbbb', 'd:\\', 'd:\\'], 19 ['c:/AaAa/bbbb', 'c:/aaaa/bbbb', ''], 20 ['c:/aaaaa/', 'c:/aaaa/cccc', '..\\aaaa\\cccc'], 21 ['C:\\foo\\bar\\baz\\quux', 'C:\\', '..\\..\\..\\..'], 22 ['C:\\foo\\test', 'C:\\foo\\test\\bar\\package.json', 'bar\\package.json'], 23 ['C:\\foo\\bar\\baz-quux', 'C:\\foo\\bar\\baz', '..\\baz'], 24 ['C:\\foo\\bar\\baz', 'C:\\foo\\bar\\baz-quux', '..\\baz-quux'], 25 ['\\\\foo\\bar', '\\\\foo\\bar\\baz', 'baz'], 26 ['\\\\foo\\bar\\baz', '\\\\foo\\bar', '..'], 27 ['\\\\foo\\bar\\baz-quux', '\\\\foo\\bar\\baz', '..\\baz'], 28 ['\\\\foo\\bar\\baz', '\\\\foo\\bar\\baz-quux', '..\\baz-quux'], 29 ['C:\\baz-quux', 'C:\\baz', '..\\baz'], 30 ['C:\\baz', 'C:\\baz-quux', '..\\baz-quux'], 31 ['\\\\foo\\baz-quux', '\\\\foo\\baz', '..\\baz'], 32 ['\\\\foo\\baz', '\\\\foo\\baz-quux', '..\\baz-quux'], 33 ['C:\\baz', '\\\\foo\\bar\\baz', '\\\\foo\\bar\\baz'], 34 ['\\\\foo\\bar\\baz', 'C:\\baz', 'C:\\baz'], 35 ], 36 ], 37 [ path.posix.relative, 38 // Arguments result 39 [['/var/lib', '/var', '..'], 40 ['/var/lib', '/bin', '../../bin'], 41 ['/var/lib', '/var/lib', ''], 42 ['/var/lib', '/var/apache', '../apache'], 43 ['/var/', '/var/lib', 'lib'], 44 ['/', '/var/lib', 'var/lib'], 45 ['/foo/test', '/foo/test/bar/package.json', 'bar/package.json'], 46 ['/Users/a/web/b/test/mails', '/Users/a/web/b', '../..'], 47 ['/foo/bar/baz-quux', '/foo/bar/baz', '../baz'], 48 ['/foo/bar/baz', '/foo/bar/baz-quux', '../baz-quux'], 49 ['/baz-quux', '/baz', '../baz'], 50 ['/baz', '/baz-quux', '../baz-quux'], 51 ['/page1/page2/foo', '/', '../../..'], 52 ], 53 ], 54]; 55relativeTests.forEach((test) => { 56 const relative = test[0]; 57 test[1].forEach((test) => { 58 const actual = relative(test[0], test[1]); 59 const expected = test[2]; 60 if (actual !== expected) { 61 const os = relative === path.win32.relative ? 'win32' : 'posix'; 62 const message = `path.${os}.relative(${ 63 test.slice(0, 2).map(JSON.stringify).join(',')})\n expect=${ 64 JSON.stringify(expected)}\n actual=${JSON.stringify(actual)}`; 65 failures.push(`\n${message}`); 66 } 67 }); 68}); 69assert.strictEqual(failures.length, 0, failures.join('')); 70