|
| 1 | +/*--------------------------------------------------------------------------------------------- |
| 2 | + * Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | + * Licensed under the MIT License. See License.txt in the project root for license information. |
| 4 | + *--------------------------------------------------------------------------------------------*/ |
| 5 | +import * as assert from 'assert'; |
| 6 | +import * as extpath from 'vs/base/common/extpath'; |
| 7 | +import * as platform from 'vs/base/common/platform'; |
| 8 | + |
| 9 | +suite('Paths', () => { |
| 10 | + |
| 11 | + test('normalize', () => { |
| 12 | + assert.equal(extpath.normalize(''), '.'); |
| 13 | + assert.equal(extpath.normalize('.'), '.'); |
| 14 | + assert.equal(extpath.normalize('.'), '.'); |
| 15 | + assert.equal(extpath.normalize('../../far'), '../../far'); |
| 16 | + assert.equal(extpath.normalize('../bar'), '../bar'); |
| 17 | + assert.equal(extpath.normalize('../far'), '../far'); |
| 18 | + assert.equal(extpath.normalize('./'), './'); |
| 19 | + assert.equal(extpath.normalize('./././'), './'); |
| 20 | + assert.equal(extpath.normalize('./ff/./'), 'ff/'); |
| 21 | + assert.equal(extpath.normalize('./foo'), 'foo'); |
| 22 | + assert.equal(extpath.normalize('/'), '/'); |
| 23 | + assert.equal(extpath.normalize('/..'), '/'); |
| 24 | + assert.equal(extpath.normalize('///'), '/'); |
| 25 | + assert.equal(extpath.normalize('//foo'), '/foo'); |
| 26 | + assert.equal(extpath.normalize('//foo//'), '/foo/'); |
| 27 | + assert.equal(extpath.normalize('/foo'), '/foo'); |
| 28 | + assert.equal(extpath.normalize('/foo/bar.test'), '/foo/bar.test'); |
| 29 | + assert.equal(extpath.normalize('\\\\\\'), '/'); |
| 30 | + assert.equal(extpath.normalize('c:/../ff'), 'c:/ff'); |
| 31 | + assert.equal(extpath.normalize('c:\\./'), 'c:/'); |
| 32 | + assert.equal(extpath.normalize('foo/'), 'foo/'); |
| 33 | + assert.equal(extpath.normalize('foo/../../bar'), '../bar'); |
| 34 | + assert.equal(extpath.normalize('foo/./'), 'foo/'); |
| 35 | + assert.equal(extpath.normalize('foo/./bar'), 'foo/bar'); |
| 36 | + assert.equal(extpath.normalize('foo//'), 'foo/'); |
| 37 | + assert.equal(extpath.normalize('foo//'), 'foo/'); |
| 38 | + assert.equal(extpath.normalize('foo//bar'), 'foo/bar'); |
| 39 | + assert.equal(extpath.normalize('foo//bar/far'), 'foo/bar/far'); |
| 40 | + assert.equal(extpath.normalize('foo/bar/../../far'), 'far'); |
| 41 | + assert.equal(extpath.normalize('foo/bar/../far'), 'foo/far'); |
| 42 | + assert.equal(extpath.normalize('foo/far/../../bar'), 'bar'); |
| 43 | + assert.equal(extpath.normalize('foo/far/../../bar'), 'bar'); |
| 44 | + assert.equal(extpath.normalize('foo/xxx/..'), 'foo'); |
| 45 | + assert.equal(extpath.normalize('foo/xxx/../bar'), 'foo/bar'); |
| 46 | + assert.equal(extpath.normalize('foo/xxx/./..'), 'foo'); |
| 47 | + assert.equal(extpath.normalize('foo/xxx/./../bar'), 'foo/bar'); |
| 48 | + assert.equal(extpath.normalize('foo/xxx/./bar'), 'foo/xxx/bar'); |
| 49 | + assert.equal(extpath.normalize('foo\\bar'), 'foo/bar'); |
| 50 | + assert.equal(extpath.normalize(null), null); |
| 51 | + assert.equal(extpath.normalize(undefined), undefined); |
| 52 | + |
| 53 | + // https://github.com/Microsoft/vscode/issues/7234 |
| 54 | + assert.equal(extpath.join('/home/aeschli/workspaces/vscode/extensions/css', './syntaxes/css.plist'), '/home/aeschli/workspaces/vscode/extensions/css/syntaxes/css.plist'); |
| 55 | + }); |
| 56 | + |
| 57 | + test('getRootLength', () => { |
| 58 | + |
| 59 | + assert.equal(extpath.getRoot('/user/far'), '/'); |
| 60 | + assert.equal(extpath.getRoot('\\\\server\\share\\some\\path'), '//server/share/'); |
| 61 | + assert.equal(extpath.getRoot('//server/share/some/path'), '//server/share/'); |
| 62 | + assert.equal(extpath.getRoot('//server/share'), '/'); |
| 63 | + assert.equal(extpath.getRoot('//server'), '/'); |
| 64 | + assert.equal(extpath.getRoot('//server//'), '/'); |
| 65 | + assert.equal(extpath.getRoot('c:/user/far'), 'c:/'); |
| 66 | + assert.equal(extpath.getRoot('c:user/far'), 'c:'); |
| 67 | + assert.equal(extpath.getRoot('http://www'), ''); |
| 68 | + assert.equal(extpath.getRoot('http://www/'), 'http://www/'); |
| 69 | + assert.equal(extpath.getRoot('file:///foo'), 'file:///'); |
| 70 | + assert.equal(extpath.getRoot('file://foo'), ''); |
| 71 | + |
| 72 | + }); |
| 73 | + |
| 74 | + test('join', () => { |
| 75 | + assert.equal(extpath.join('.', 'bar'), 'bar'); |
| 76 | + assert.equal(extpath.join('../../foo/bar', '../../foo'), '../../foo'); |
| 77 | + assert.equal(extpath.join('../../foo/bar', '../bar/foo'), '../../foo/bar/foo'); |
| 78 | + assert.equal(extpath.join('../foo/bar', '../bar/foo'), '../foo/bar/foo'); |
| 79 | + assert.equal(extpath.join('/', 'bar'), '/bar'); |
| 80 | + assert.equal(extpath.join('//server/far/boo', '../file.txt'), '//server/far/file.txt'); |
| 81 | + assert.equal(extpath.join('/foo/', '/bar'), '/foo/bar'); |
| 82 | + assert.equal(extpath.join('\\\\server\\far\\boo', '../file.txt'), '//server/far/file.txt'); |
| 83 | + assert.equal(extpath.join('\\\\server\\far\\boo', './file.txt'), '//server/far/boo/file.txt'); |
| 84 | + assert.equal(extpath.join('\\\\server\\far\\boo', '.\\file.txt'), '//server/far/boo/file.txt'); |
| 85 | + assert.equal(extpath.join('\\\\server\\far\\boo', 'file.txt'), '//server/far/boo/file.txt'); |
| 86 | + assert.equal(extpath.join('file:///c/users/test', 'test'), 'file:///c/users/test/test'); |
| 87 | + assert.equal(extpath.join('file://localhost/c$/GitDevelopment/express', './settings'), 'file://localhost/c$/GitDevelopment/express/settings'); // unc |
| 88 | + assert.equal(extpath.join('file://localhost/c$/GitDevelopment/express', '.settings'), 'file://localhost/c$/GitDevelopment/express/.settings'); // unc |
| 89 | + assert.equal(extpath.join('foo', '/bar'), 'foo/bar'); |
| 90 | + assert.equal(extpath.join('foo', 'bar'), 'foo/bar'); |
| 91 | + assert.equal(extpath.join('foo', 'bar/'), 'foo/bar/'); |
| 92 | + assert.equal(extpath.join('foo/', '/bar'), 'foo/bar'); |
| 93 | + assert.equal(extpath.join('foo/', '/bar/'), 'foo/bar/'); |
| 94 | + assert.equal(extpath.join('foo/', 'bar'), 'foo/bar'); |
| 95 | + assert.equal(extpath.join('foo/bar', '../bar/foo'), 'foo/bar/foo'); |
| 96 | + assert.equal(extpath.join('foo/bar', './bar/foo'), 'foo/bar/bar/foo'); |
| 97 | + assert.equal(extpath.join('http://localhost/test', '../next'), 'http://localhost/next'); |
| 98 | + assert.equal(extpath.join('http://localhost/test', 'test'), 'http://localhost/test/test'); |
| 99 | + }); |
| 100 | + |
| 101 | + test('isUNC', () => { |
| 102 | + if (platform.isWindows) { |
| 103 | + assert.ok(!extpath.isUNC('foo')); |
| 104 | + assert.ok(!extpath.isUNC('/foo')); |
| 105 | + assert.ok(!extpath.isUNC('\\foo')); |
| 106 | + assert.ok(!extpath.isUNC('\\\\foo')); |
| 107 | + assert.ok(extpath.isUNC('\\\\a\\b')); |
| 108 | + assert.ok(!extpath.isUNC('//a/b')); |
| 109 | + assert.ok(extpath.isUNC('\\\\server\\share')); |
| 110 | + assert.ok(extpath.isUNC('\\\\server\\share\\')); |
| 111 | + assert.ok(extpath.isUNC('\\\\server\\share\\path')); |
| 112 | + } |
| 113 | + }); |
| 114 | + |
| 115 | + test('isValidBasename', () => { |
| 116 | + assert.ok(!extpath.isValidBasename(null)); |
| 117 | + assert.ok(!extpath.isValidBasename('')); |
| 118 | + assert.ok(extpath.isValidBasename('test.txt')); |
| 119 | + assert.ok(!extpath.isValidBasename('/test.txt')); |
| 120 | + assert.ok(!extpath.isValidBasename('\\test.txt')); |
| 121 | + |
| 122 | + if (platform.isWindows) { |
| 123 | + assert.ok(!extpath.isValidBasename('aux')); |
| 124 | + assert.ok(!extpath.isValidBasename('Aux')); |
| 125 | + assert.ok(!extpath.isValidBasename('LPT0')); |
| 126 | + assert.ok(!extpath.isValidBasename('test.txt.')); |
| 127 | + assert.ok(!extpath.isValidBasename('test.txt..')); |
| 128 | + assert.ok(!extpath.isValidBasename('test.txt ')); |
| 129 | + assert.ok(!extpath.isValidBasename('test.txt\t')); |
| 130 | + assert.ok(!extpath.isValidBasename('tes:t.txt')); |
| 131 | + assert.ok(!extpath.isValidBasename('tes"t.txt')); |
| 132 | + } |
| 133 | + }); |
| 134 | +}); |
0 commit comments