提交 42392190 编写于 作者: D Daniel Imms

Fix terminal config tests

上级 d03cc545
...@@ -16,10 +16,6 @@ import { TPromise } from 'vs/base/common/winjs.base'; ...@@ -16,10 +16,6 @@ import { TPromise } from 'vs/base/common/winjs.base';
import Severity from 'vs/base/common/severity'; import Severity from 'vs/base/common/severity';
import { isFedora } from 'vs/workbench/parts/terminal/electron-browser/terminal'; import { isFedora } from 'vs/workbench/parts/terminal/electron-browser/terminal';
interface IEditorConfiguration {
editor: IEditorOptions;
}
const DEFAULT_LINE_HEIGHT = 1.0; const DEFAULT_LINE_HEIGHT = 1.0;
const MINIMUM_FONT_SIZE = 6; const MINIMUM_FONT_SIZE = 6;
...@@ -90,21 +86,19 @@ export class TerminalConfigHelper implements ITerminalConfigHelper { ...@@ -90,21 +86,19 @@ export class TerminalConfigHelper implements ITerminalConfigHelper {
* terminal.integrated.fontSize, terminal.integrated.lineHeight configuration properties * terminal.integrated.fontSize, terminal.integrated.lineHeight configuration properties
*/ */
public getFont(excludeDimensions?: boolean): ITerminalFont { public getFont(excludeDimensions?: boolean): ITerminalFont {
const config = this._configurationService.getValue(); const editorConfig = this._configurationService.getValue<IEditorOptions>('editor');
const editorConfig = (<IEditorConfiguration>config).editor;
const terminalConfig = this.config;
let fontFamily = terminalConfig.fontFamily || editorConfig.fontFamily; let fontFamily = this.config.fontFamily || editorConfig.fontFamily;
// Work around bad font on Fedora // Work around bad font on Fedora
if (!terminalConfig.fontFamily) { if (!this.config.fontFamily) {
if (isFedora) { if (isFedora) {
fontFamily = '\'DejaVu Sans Mono\''; fontFamily = '\'DejaVu Sans Mono\'';
} }
} }
let fontSize = this._toInteger(terminalConfig.fontSize, MINIMUM_FONT_SIZE, MAXIMUM_FONT_SIZE, EDITOR_FONT_DEFAULTS.fontSize); let fontSize = this._toInteger(this.config.fontSize, MINIMUM_FONT_SIZE, MAXIMUM_FONT_SIZE, EDITOR_FONT_DEFAULTS.fontSize);
const lineHeight = terminalConfig.lineHeight ? Math.max(terminalConfig.lineHeight, 1) : DEFAULT_LINE_HEIGHT; const lineHeight = this.config.lineHeight ? Math.max(this.config.lineHeight, 1) : DEFAULT_LINE_HEIGHT;
if (excludeDimensions) { if (excludeDimensions) {
return { return {
......
...@@ -11,6 +11,7 @@ import { TPromise } from 'vs/base/common/winjs.base'; ...@@ -11,6 +11,7 @@ import { TPromise } from 'vs/base/common/winjs.base';
import { TerminalConfigHelper } from 'vs/workbench/parts/terminal/electron-browser/terminalConfigHelper'; import { TerminalConfigHelper } from 'vs/workbench/parts/terminal/electron-browser/terminalConfigHelper';
import { EDITOR_FONT_DEFAULTS } from 'vs/editor/common/config/editorOptions'; import { EDITOR_FONT_DEFAULTS } from 'vs/editor/common/config/editorOptions';
import { isFedora } from 'vs/workbench/parts/terminal/electron-browser/terminal'; import { isFedora } from 'vs/workbench/parts/terminal/electron-browser/terminal';
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
class MockConfigurationService implements IConfigurationService { class MockConfigurationService implements IConfigurationService {
public _serviceBrand: any; public _serviceBrand: any;
...@@ -33,33 +34,17 @@ suite('Workbench - TerminalConfigHelper', () => { ...@@ -33,33 +34,17 @@ suite('Workbench - TerminalConfigHelper', () => {
}); });
test('TerminalConfigHelper - getFont fontFamily', function () { test('TerminalConfigHelper - getFont fontFamily', function () {
let configurationService: IConfigurationService; const configurationService = new TestConfigurationService();
let configHelper: TerminalConfigHelper; configurationService.setUserConfiguration('editor', { fontFamily: 'foo' });
configurationService.setUserConfiguration('terminal', { integrated: { fontFamily: 'bar' } });
configurationService = new MockConfigurationService({
editor: { let configHelper = new TerminalConfigHelper(configurationService, null, null, null);
fontFamily: 'foo'
},
terminal: {
integrated: {
fontFamily: 'bar'
}
}
});
configHelper = new TerminalConfigHelper(configurationService, null, null, null);
configHelper.panelContainer = fixture; configHelper.panelContainer = fixture;
assert.equal(configHelper.getFont().fontFamily, 'bar', 'terminal.integrated.fontFamily should be selected over editor.fontFamily'); assert.equal(configHelper.getFont().fontFamily, 'bar', 'terminal.integrated.fontFamily should be selected over editor.fontFamily');
configurationService = new MockConfigurationService({ configurationService.setUserConfiguration('terminal', { integrated: { fontFamily: null } });
editor: {
fontFamily: 'foo' // Recreate config helper as onDidChangeConfiguration isn't implemented in TestConfigurationService
},
terminal: {
integrated: {
fontFamily: 0
}
}
});
configHelper = new TerminalConfigHelper(configurationService, null, null, null); configHelper = new TerminalConfigHelper(configurationService, null, null, null);
configHelper.panelContainer = fixture; configHelper.panelContainer = fixture;
if (isFedora) { if (isFedora) {
...@@ -70,64 +55,55 @@ suite('Workbench - TerminalConfigHelper', () => { ...@@ -70,64 +55,55 @@ suite('Workbench - TerminalConfigHelper', () => {
}); });
test('TerminalConfigHelper - getFont fontSize', function () { test('TerminalConfigHelper - getFont fontSize', function () {
let configurationService: IConfigurationService; const configurationService = new TestConfigurationService();
let configHelper: TerminalConfigHelper;
configurationService.setUserConfiguration('editor', {
configurationService = new MockConfigurationService({ fontFamily: 'foo',
editor: { fontSize: 9
fontFamily: 'foo', });
fontSize: 9 configurationService.setUserConfiguration('terminal', {
}, integrated: {
terminal: { fontFamily: 'bar',
integrated: { fontSize: 10
fontFamily: 'bar',
fontSize: 10
}
} }
}); });
configHelper = new TerminalConfigHelper(configurationService, null, null, null); let configHelper = new TerminalConfigHelper(configurationService, null, null, null);
configHelper.panelContainer = fixture; configHelper.panelContainer = fixture;
assert.equal(configHelper.getFont().fontSize, 10, 'terminal.integrated.fontSize should be selected over editor.fontSize'); assert.equal(configHelper.getFont().fontSize, 10, 'terminal.integrated.fontSize should be selected over editor.fontSize');
configurationService = new MockConfigurationService({ configurationService.setUserConfiguration('editor', {
editor: { fontFamily: 'foo'
fontFamily: 'foo' });
}, configurationService.setUserConfiguration('terminal', {
terminal: { integrated: {
integrated: { fontFamily: null,
fontFamily: 0, fontSize: 0
fontSize: 0
}
} }
}); });
configHelper = new TerminalConfigHelper(configurationService, null, null, null); configHelper = new TerminalConfigHelper(configurationService, null, null, null);
configHelper.panelContainer = fixture; configHelper.panelContainer = fixture;
assert.equal(configHelper.getFont().fontSize, 6, 'The minimum terminal font size should be used when terminal.integrated.fontSize less than it'); assert.equal(configHelper.getFont().fontSize, 6, 'The minimum terminal font size should be used when terminal.integrated.fontSize less than it');
configurationService = new MockConfigurationService({ configurationService.setUserConfiguration('editor', {
editor: { fontFamily: 'foo'
fontFamily: 'foo' });
}, configurationService.setUserConfiguration('terminal', {
terminal: { integrated: {
integrated: { fontFamily: 0,
fontFamily: 0, fontSize: 1500
fontSize: 1500
}
} }
}); });
configHelper = new TerminalConfigHelper(configurationService, null, null, null); configHelper = new TerminalConfigHelper(configurationService, null, null, null);
configHelper.panelContainer = fixture; configHelper.panelContainer = fixture;
assert.equal(configHelper.getFont().fontSize, 25, 'The maximum terminal font size should be used when terminal.integrated.fontSize more than it'); assert.equal(configHelper.getFont().fontSize, 25, 'The maximum terminal font size should be used when terminal.integrated.fontSize more than it');
configurationService = new MockConfigurationService({ configurationService.setUserConfiguration('editor', {
editor: { fontFamily: 'foo'
fontFamily: 'foo', });
}, configurationService.setUserConfiguration('terminal', {
terminal: { integrated: {
integrated: { fontFamily: 0,
fontFamily: 0, fontSize: null
fontSize: null
}
} }
}); });
configHelper = new TerminalConfigHelper(configurationService, null, null, null); configHelper = new TerminalConfigHelper(configurationService, null, null, null);
...@@ -136,35 +112,30 @@ suite('Workbench - TerminalConfigHelper', () => { ...@@ -136,35 +112,30 @@ suite('Workbench - TerminalConfigHelper', () => {
}); });
test('TerminalConfigHelper - getFont lineHeight', function () { test('TerminalConfigHelper - getFont lineHeight', function () {
let configurationService: IConfigurationService; const configurationService = new TestConfigurationService();
let configHelper: TerminalConfigHelper;
configurationService.setUserConfiguration('editor', {
configurationService = new MockConfigurationService({ fontFamily: 'foo',
editor: { lineHeight: 1
fontFamily: 'foo', });
lineHeight: 1 configurationService.setUserConfiguration('terminal', {
}, integrated: {
terminal: { fontFamily: 0,
integrated: { lineHeight: 2
fontFamily: 0,
lineHeight: 2
}
} }
}); });
configHelper = new TerminalConfigHelper(configurationService, null, null, null); let configHelper = new TerminalConfigHelper(configurationService, null, null, null);
configHelper.panelContainer = fixture; configHelper.panelContainer = fixture;
assert.equal(configHelper.getFont().lineHeight, 2, 'terminal.integrated.lineHeight should be selected over editor.lineHeight'); assert.equal(configHelper.getFont().lineHeight, 2, 'terminal.integrated.lineHeight should be selected over editor.lineHeight');
configurationService = new MockConfigurationService({ configurationService.setUserConfiguration('editor', {
editor: { fontFamily: 'foo',
fontFamily: 'foo', lineHeight: 1
lineHeight: 1 });
}, configurationService.setUserConfiguration('terminal', {
terminal: { integrated: {
integrated: { fontFamily: 0,
fontFamily: 0, lineHeight: 0
lineHeight: 0
}
} }
}); });
configHelper = new TerminalConfigHelper(configurationService, null, null, null); configHelper = new TerminalConfigHelper(configurationService, null, null, null);
......
...@@ -21,8 +21,11 @@ import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; ...@@ -21,8 +21,11 @@ import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IHistoryService } from 'vs/workbench/services/history/common/history'; import { IHistoryService } from 'vs/workbench/services/history/common/history';
import { TPromise } from 'vs/base/common/winjs.base'; import { TPromise } from 'vs/base/common/winjs.base';
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
class TestTerminalInstance extends TerminalInstance { class TestTerminalInstance extends TerminalInstance {
public _getCwd(shell: IShellLaunchConfig, root: Uri): string { public _getCwd(shell: IShellLaunchConfig, root: Uri): string {
return super._getCwd(shell, root); return super._getCwd(shell, root);
} }
...@@ -152,6 +155,7 @@ suite('Workbench - TerminalInstance', () => { ...@@ -152,6 +155,7 @@ suite('Workbench - TerminalInstance', () => {
let keybindingService = new MockKeybindingService(); let keybindingService = new MockKeybindingService();
let terminalFocusContextKey = contextKeyService.createKey('test', false); let terminalFocusContextKey = contextKeyService.createKey('test', false);
instantiationService = new TestInstantiationService(); instantiationService = new TestInstantiationService();
instantiationService.stub(IConfigurationService, new TestConfigurationService());
instantiationService.stub(IMessageService, new TestMessageService()); instantiationService.stub(IMessageService, new TestMessageService());
instantiationService.stub(IWorkspaceContextService, new TestContextService()); instantiationService.stub(IWorkspaceContextService, new TestContextService());
instantiationService.stub(IKeybindingService, keybindingService); instantiationService.stub(IKeybindingService, keybindingService);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册