import { sep } from 'path'; import { decodeUriPathComponents, encodeUriPathComponents, ensureTrailingSlash, joinFilePath, normalizeFilePath, toCanonicalUriPath, toSystemFilePath, } from '../../../src/util/PathUtil'; describe('PathUtil', (): void => { describe('normalizeFilePath', (): void => { it('normalizes POSIX paths.', async(): Promise => { expect(normalizeFilePath('/foo/bar/../baz')).toEqual('/foo/baz'); }); it('normalizes Windows paths.', async(): Promise => { expect(normalizeFilePath('c:\\foo\\bar\\..\\baz')).toEqual('c:/foo/baz'); }); }); describe('joinFilePath', (): void => { it('joins POSIX paths.', async(): Promise => { expect(joinFilePath('/foo/bar/', '..', '/baz')).toEqual('/foo/baz'); }); it('joins Windows paths.', async(): Promise => { expect(joinFilePath('c:\\foo\\bar\\', '..', '/baz')).toEqual(`c:/foo/baz`); }); }); describe('toSystemFilePath', (): void => { it('converts a POSIX path to an OS-specific path.', async(): Promise => { expect(toSystemFilePath('c:/foo/bar/')).toEqual(`c:${sep}foo${sep}bar${sep}`); }); }); describe('#ensureTrailingSlash', (): void => { it('makes sure there is always exactly 1 slash.', async(): Promise => { expect(ensureTrailingSlash('http://test.com')).toEqual('http://test.com/'); expect(ensureTrailingSlash('http://test.com/')).toEqual('http://test.com/'); expect(ensureTrailingSlash('http://test.com//')).toEqual('http://test.com/'); expect(ensureTrailingSlash('http://test.com///')).toEqual('http://test.com/'); }); }); describe('UriPath functions', (): void => { it('makes sure only the necessary parts are encoded with toCanonicalUriPath.', async(): Promise => { expect(toCanonicalUriPath('/a%20path&/name')).toEqual('/a%20path%26/name'); }); it('decodes all parts of a path with decodeUriPathComponents.', async(): Promise => { expect(decodeUriPathComponents('/a%20path&/name')).toEqual('/a path&/name'); }); it('encodes all parts of a path with encodeUriPathComponents.', async(): Promise => { expect(encodeUriPathComponents('/a%20path&/name')).toEqual('/a%2520path%26/name'); }); }); });