Skip to content

Commit

Permalink
Merge pull request #30198 from Microsoft/tyriar/27771
Browse files Browse the repository at this point in the history
Add tests for TerminalPanel.preparePathForTerminal
  • Loading branch information
Tyriar authored Jul 6, 2017
2 parents 5a40dc5 + fe5027c commit 1401c30
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ export class TerminalPanel extends Panel {
}

const terminal = this._terminalService.getActiveInstance();
terminal.sendText(this._preparePathForTerminal(uri), false);
terminal.sendText(TerminalPanel.preparePathForTerminal(uri), false);
}
}));
}
Expand Down Expand Up @@ -327,7 +327,7 @@ export class TerminalPanel extends Panel {
/**
* Adds quotes to a path if it contains whitespaces
*/
private _preparePathForTerminal(path: string) {
public static preparePathForTerminal(path: string): string {
if (platform.isWindows) {
if (/\s+/.test(path)) {
return `"${path}"`;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

'use strict';

import * as assert from 'assert';
import { TerminalPanel } from 'vs/workbench/parts/terminal/electron-browser/terminalPanel';
import * as platform from 'vs/base/common/platform';

suite('Workbench - TerminalPanel', () => {
test('preparePathForTerminal', function () {
if (platform.isWindows) {
assert.equal(TerminalPanel.preparePathForTerminal('C:\\foo'), 'C:\\foo');
assert.equal(TerminalPanel.preparePathForTerminal('C:\\foo bar'), '"C:\\foo bar"');
return;
}
assert.equal(TerminalPanel.preparePathForTerminal('/a/\\foo bar"\'? ;\'?? :'), '/a/\\\\foo\\ bar\\"\\\'\\?\\ \\;\\\'\\?\\?\\ \\ \\:');
assert.equal(TerminalPanel.preparePathForTerminal('/\\\'"?:;!*(){}[]'), '/\\\\\\\'\\"\\?\\:\\;\\!\\*\\(\\)\\{\\}\\[\\]');
});
});

0 comments on commit 1401c30

Please sign in to comment.