terminalConfigHelper.test.ts 8.2 KB
Newer Older
1 2 3 4 5 6 7 8
/*---------------------------------------------------------------------------------------------
 *  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';
D
Daniel Imms 已提交
9
import {Builder} from 'vs/base/browser/builder';
10 11 12 13
import {IConfigurationService} from 'vs/platform/configuration/common/configuration';
import {Platform} from 'vs/base/common/platform';
import {TPromise} from 'vs/base/common/winjs.base';
import {TerminalConfigHelper} from 'vs/workbench/parts/terminal/electron-browser/terminalConfigHelper';
14
import {DefaultConfig} from 'vs/editor/common/config/defaultConfig';
15 16 17


class MockConfigurationService implements IConfigurationService {
18
	public _serviceBrand: any;
19 20 21 22 23 24 25 26 27
	public constructor(private configuration: any = {}) {}
	public loadConfiguration<T>(section?: string): TPromise<T> { return TPromise.as(this.getConfiguration()); }
	public getConfiguration(): any { return this.configuration; }
	public hasWorkspaceConfiguration(): boolean { return false; }
	public onDidUpdateConfiguration() { return { dispose() { } }; }
	public setUserConfiguration(key: any, value: any): Thenable<void> { return TPromise.as(null); }
}

suite('Workbench - TerminalConfigHelper', () => {
D
Daniel Imms 已提交
28 29
	let fixture: Builder;

30
	setup(() => {
D
Daniel Imms 已提交
31
		fixture = new Builder(document.body, false);
32 33
	});

34
	test('TerminalConfigHelper - getFont fontFamily', function () {
35 36 37 38 39 40 41 42 43 44 45 46 47
		let configurationService: IConfigurationService;
		let configHelper: TerminalConfigHelper;

		configurationService = new MockConfigurationService({
			editor: {
				fontFamily: 'foo'
			},
			terminal: {
				integrated: {
					fontFamily: 'bar'
				}
			}
		});
48
		configHelper = new TerminalConfigHelper(Platform.Linux, configurationService, fixture);
49
		assert.equal(configHelper.getFont().fontFamily, 'bar', 'terminal.integrated.fontFamily should be selected over editor.fontFamily');
50 51 52 53 54 55 56

		configurationService = new MockConfigurationService({
			editor: {
				fontFamily: 'foo'
			},
			terminal: {
				integrated: {
57
					fontFamily: 0
58 59 60
				}
			}
		});
61
		configHelper = new TerminalConfigHelper(Platform.Linux, configurationService, fixture);
62
		assert.equal(configHelper.getFont().fontFamily, 'foo', 'editor.fontFamily should be the fallback when terminal.integrated.fontFamily not set');
63 64 65 66 67
	});

	test('TerminalConfigHelper - getFont fontSize', function () {
		let configurationService: IConfigurationService;
		let configHelper: TerminalConfigHelper;
68 69 70 71 72 73 74 75 76 77 78 79 80

		configurationService = new MockConfigurationService({
			editor: {
				fontFamily: 'foo',
				fontSize: 1
			},
			terminal: {
				integrated: {
					fontFamily: 'bar',
					fontSize: 2
				}
			}
		});
81
		configHelper = new TerminalConfigHelper(Platform.Linux, configurationService, fixture);
82
		assert.equal(configHelper.getFont().fontSize, '2px', 'terminal.integrated.fontSize should be selected over editor.fontSize');
83 84 85 86 87 88 89 90

		configurationService = new MockConfigurationService({
			editor: {
				fontFamily: 'foo',
				fontSize: 1
			},
			terminal: {
				integrated: {
91 92
					fontFamily: 0,
					fontSize: 0
93 94 95
				}
			}
		});
96
		configHelper = new TerminalConfigHelper(Platform.Linux, configurationService, fixture);
97
		assert.equal(configHelper.getFont().fontSize, '1px', 'editor.fontSize should be the fallback when terminal.integrated.fontSize not set');
98

99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
		configurationService = new MockConfigurationService({
			editor: {
				fontFamily: 'foo',
				fontSize: 0
			},
			terminal: {
				integrated: {
					fontFamily: 0,
					fontSize: 0
				}
			}
		});
		configHelper = new TerminalConfigHelper(Platform.Linux, configurationService, fixture);
		assert.equal(configHelper.getFont().fontSize, `${DefaultConfig.editor.fontSize}px`, 'The default editor font size should be used when editor.fontSize is 0 and terminal.integrated.fontSize not set');

		configurationService = new MockConfigurationService({
			editor: {
				fontFamily: 'foo',
				fontSize: 0
			},
			terminal: {
				integrated: {
					fontFamily: 0,
					fontSize: -10
				}
			}
		});
		configHelper = new TerminalConfigHelper(Platform.Linux, configurationService, fixture);
		assert.equal(configHelper.getFont().fontSize, `${DefaultConfig.editor.fontSize}px`, 'The default editor font size should be used when editor.fontSize is < 0 and terminal.integrated.fontSize not set');
	});

	test('TerminalConfigHelper - getFont lineHeight', function () {
		let configurationService: IConfigurationService;
		let configHelper: TerminalConfigHelper;

134 135 136 137 138 139 140
		configurationService = new MockConfigurationService({
			editor: {
				fontFamily: 'foo',
				lineHeight: 1
			},
			terminal: {
				integrated: {
141
					fontFamily: 0,
142 143 144 145
					lineHeight: 2
				}
			}
		});
146
		configHelper = new TerminalConfigHelper(Platform.Linux, configurationService, fixture);
D
Daniel Imms 已提交
147
		assert.equal(configHelper.getFont().lineHeight, 2, 'terminal.integrated.lineHeight should be selected over editor.lineHeight');
148 149 150 151 152 153 154 155

		configurationService = new MockConfigurationService({
			editor: {
				fontFamily: 'foo',
				lineHeight: 1
			},
			terminal: {
				integrated: {
156 157
					fontFamily: 0,
					lineHeight: 0
158 159 160
				}
			}
		});
161
		configHelper = new TerminalConfigHelper(Platform.Linux, configurationService, fixture);
D
Daniel Imms 已提交
162
		assert.equal(configHelper.getFont().lineHeight, 1.2, 'editor.lineHeight should be 1.2 when terminal.integrated.lineHeight not set');
163 164 165 166 167 168 169 170 171 172 173
	});

	test('TerminalConfigHelper - getShell', function () {
		let configurationService: IConfigurationService;
		let configHelper: TerminalConfigHelper;

		configurationService = new MockConfigurationService({
			terminal: {
				integrated: {
					shell: {
						linux: 'foo'
A
Andre Weinand 已提交
174 175 176
					},
					shellArgs: {
						linux: []
177 178 179 180
					}
				}
			}
		});
181
		configHelper = new TerminalConfigHelper(Platform.Linux, configurationService, fixture);
A
Andre Weinand 已提交
182
		assert.equal(configHelper.getShell().executable, 'foo', 'terminal.integrated.shell.linux should be selected on Linux');
183 184 185 186 187 188

		configurationService = new MockConfigurationService({
			terminal: {
				integrated: {
					shell: {
						osx: 'foo'
A
Andre Weinand 已提交
189 190 191
					},
					shellArgs: {
						osx: []
192 193 194 195
					}
				}
			}
		});
196
		configHelper = new TerminalConfigHelper(Platform.Mac, configurationService, fixture);
A
Andre Weinand 已提交
197
		assert.equal(configHelper.getShell().executable, 'foo', 'terminal.integrated.shell.osx should be selected on OS X');
198 199 200 201 202 203 204 205 206 207

		configurationService = new MockConfigurationService({
			terminal: {
				integrated: {
					shell: {
						windows: 'foo'
					}
				}
			}
		});
208
		configHelper = new TerminalConfigHelper(Platform.Windows, configurationService, fixture);
A
Andre Weinand 已提交
209
		assert.equal(configHelper.getShell().executable, 'foo', 'terminal.integrated.shell.windows should be selected on Windows');
210 211 212 213 214 215
	});

	test('TerminalConfigHelper - getTheme', function () {
		let configurationService: IConfigurationService = new MockConfigurationService();
		let configHelper: TerminalConfigHelper;

216
		configHelper = new TerminalConfigHelper(Platform.Linux, configurationService, fixture);
217
		assert.deepEqual(configHelper.getTheme('hc-black'), [
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
			'#000000',
			'#cd0000',
			'#00cd00',
			'#cdcd00',
			'#0000ee',
			'#cd00cd',
			'#00cdcd',
			'#e5e5e5',
			'#7f7f7f',
			'#ff0000',
			'#00ff00',
			'#ffff00',
			'#5c5cff',
			'#ff00ff',
			'#00ffff',
			'#ffffff'
		], 'The high contrast terminal theme should be selected when the hc-black theme is active');

236
		configHelper = new TerminalConfigHelper(Platform.Linux, configurationService, fixture);
237
		assert.deepEqual(configHelper.getTheme('vs'), [
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
			'#000000',
			'#cd3131',
			'#008000',
			'#949800',
			'#0451a5',
			'#bc05bc',
			'#0598bc',
			'#555555',
			'#666666',
			'#cd3131',
			'#00aa00',
			'#b5ba00',
			'#0451a5',
			'#bc05bc',
			'#0598bc',
			'#a5a5a5'
		], 'The light terminal theme should be selected when a vs theme is active');

256
		configHelper = new TerminalConfigHelper(Platform.Linux, configurationService, fixture);
257
		assert.deepEqual(configHelper.getTheme('vs-dark'), [
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
			'#000000',
			'#cd3131',
			'#09885a',
			'#e5e510',
			'#2472c8',
			'#bc3fbc',
			'#11a8cd',
			'#e5e5e5',
			'#666666',
			'#f14c4c',
			'#17a773',
			'#f5f543',
			'#3b8eea',
			'#d670d6',
			'#29b8db',
			'#e5e5e5'
		], 'The dark terminal theme should be selected when a vs-dark theme is active');
	});
});