diff --git a/lib/index.ts b/lib/index.ts index cea2ec7..f715a2c 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -62,16 +62,6 @@ export function extname(path: string): string { return '' } -/** - * Joins multiple path segments into a single path. - * - * @param args - The path segments to join - * @deprecated use `join()` instead - */ -export function joinPaths(...args: string[]): string { - return join(...args) -} - /** * Joins multiple path segments into a single path. * diff --git a/test/join.test.ts b/test/join.test.ts new file mode 100644 index 0000000..5792e3d --- /dev/null +++ b/test/join.test.ts @@ -0,0 +1,52 @@ +/** + * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import { describe, expect, it } from 'vitest' +import { join } from '../lib/index.ts' + +describe('join', () => { + it('returns empty string with no or empty arguments', function() { + expect(join()).toEqual('') + expect(join('')).toEqual('') + expect(join('', '')).toEqual('') + }) + it('returns joined path sections', function() { + expect(join('abc')).toEqual('abc') + expect(join('abc', 'def')).toEqual('abc/def') + expect(join('abc', 'def', 'ghi')).toEqual('abc/def/ghi') + }) + it('keeps leading slashes', function() { + expect(join('/abc')).toEqual('/abc') + expect(join('/abc', '')).toEqual('/abc') + expect(join('', '/abc')).toEqual('/abc') + expect(join('/abc', 'def')).toEqual('/abc/def') + expect(join('/abc', 'def', 'ghi')).toEqual('/abc/def/ghi') + }) + it('keeps trailing slashes', function() { + expect(join('', 'abc/')).toEqual('abc/') + expect(join('abc/')).toEqual('abc/') + expect(join('abc/', '')).toEqual('abc/') + expect(join('abc', 'def/')).toEqual('abc/def/') + expect(join('abc', 'def', 'ghi/')).toEqual('abc/def/ghi/') + }) + it('splits paths in specified strings and discards extra slashes', function() { + expect(join('//abc//')).toEqual('/abc/') + expect(join('//abc//def//')).toEqual('/abc/def/') + expect(join('//abc//', '//def//')).toEqual('/abc/def/') + expect(join('//abc//', '//def//', '//ghi//')).toEqual('/abc/def/ghi/') + expect(join('//abc//def//', '//ghi//jkl/mno/', '//pqr//')).toEqual('/abc/def/ghi/jkl/mno/pqr/') + expect(join('/abc', '/def')).toEqual('/abc/def') + expect(join('/abc/', '/def')).toEqual('/abc/def') + expect(join('/abc/', 'def')).toEqual('/abc/def') + }) + it('discards empty sections', function() { + expect(join('abc', '', 'def')).toEqual('abc/def') + }) + it('returns root if only slashes', function() { + expect(join('//')).toEqual('/') + expect(join('/', '/')).toEqual('/') + expect(join('/', '//', '/')).toEqual('/') + }) +}) diff --git a/test/joinPaths.test.ts b/test/joinPaths.test.ts deleted file mode 100644 index c0a0552..0000000 --- a/test/joinPaths.test.ts +++ /dev/null @@ -1,52 +0,0 @@ -/** - * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors - * SPDX-License-Identifier: GPL-3.0-or-later - */ - -import { describe, expect, it } from 'vitest' -import { join, joinPaths } from '../lib/index.ts' - -describe.for([join, joinPaths])('joinPaths', (joinPaths) => { - it('returns empty string with no or empty arguments', function() { - expect(joinPaths()).toEqual('') - expect(joinPaths('')).toEqual('') - expect(joinPaths('', '')).toEqual('') - }) - it('returns joined path sections', function() { - expect(joinPaths('abc')).toEqual('abc') - expect(joinPaths('abc', 'def')).toEqual('abc/def') - expect(joinPaths('abc', 'def', 'ghi')).toEqual('abc/def/ghi') - }) - it('keeps leading slashes', function() { - expect(joinPaths('/abc')).toEqual('/abc') - expect(joinPaths('/abc', '')).toEqual('/abc') - expect(joinPaths('', '/abc')).toEqual('/abc') - expect(joinPaths('/abc', 'def')).toEqual('/abc/def') - expect(joinPaths('/abc', 'def', 'ghi')).toEqual('/abc/def/ghi') - }) - it('keeps trailing slashes', function() { - expect(joinPaths('', 'abc/')).toEqual('abc/') - expect(joinPaths('abc/')).toEqual('abc/') - expect(joinPaths('abc/', '')).toEqual('abc/') - expect(joinPaths('abc', 'def/')).toEqual('abc/def/') - expect(joinPaths('abc', 'def', 'ghi/')).toEqual('abc/def/ghi/') - }) - it('splits paths in specified strings and discards extra slashes', function() { - expect(joinPaths('//abc//')).toEqual('/abc/') - expect(joinPaths('//abc//def//')).toEqual('/abc/def/') - expect(joinPaths('//abc//', '//def//')).toEqual('/abc/def/') - expect(joinPaths('//abc//', '//def//', '//ghi//')).toEqual('/abc/def/ghi/') - expect(joinPaths('//abc//def//', '//ghi//jkl/mno/', '//pqr//')).toEqual('/abc/def/ghi/jkl/mno/pqr/') - expect(joinPaths('/abc', '/def')).toEqual('/abc/def') - expect(joinPaths('/abc/', '/def')).toEqual('/abc/def') - expect(joinPaths('/abc/', 'def')).toEqual('/abc/def') - }) - it('discards empty sections', function() { - expect(joinPaths('abc', '', 'def')).toEqual('abc/def') - }) - it('returns root if only slashes', function() { - expect(joinPaths('//')).toEqual('/') - expect(joinPaths('/', '/')).toEqual('/') - expect(joinPaths('/', '//', '/')).toEqual('/') - }) -})