Remove set/getOption deprecated APIs

This commit is contained in:
Daniel Imms
2022-07-27 09:04:07 -07:00
parent b2aa100c58
commit 71911b501b
12 changed files with 29 additions and 269 deletions
-6
View File
@@ -136,12 +136,6 @@ export class MockOptionsService implements IOptionsService {
this.options[key] = options[key];
}
}
public setOption<T>(key: string, value: T): void {
throw new Error('Method not implemented.');
}
public getOption<T>(key: string): T {
throw new Error('Method not implemented.');
}
}
// defaults to V6 always to keep tests passing
+26 -26
View File
@@ -17,16 +17,16 @@ describe('OptionsService', () => {
});
it('uses default value if invalid constructor option values passed for cols/rows', () => {
const optionsService = new OptionsService({ cols: undefined, rows: undefined });
assert.equal(optionsService.getOption('rows'), DEFAULT_OPTIONS.rows);
assert.equal(optionsService.getOption('cols'), DEFAULT_OPTIONS.cols);
assert.equal(optionsService.options.rows, DEFAULT_OPTIONS.rows);
assert.equal(optionsService.options.cols, DEFAULT_OPTIONS.cols);
});
it('uses values from constructor option values if correctly passed', () => {
const optionsService = new OptionsService({ cols: 80, rows: 25 });
assert.equal(optionsService.getOption('rows'), 25);
assert.equal(optionsService.getOption('cols'), 80);
assert.equal(optionsService.options.rows, 25);
assert.equal(optionsService.options.cols, 80);
});
it('uses default value if invalid constructor option value passed', () => {
assert.equal(new OptionsService({ tabStopWidth: 0 }).getOption('tabStopWidth'), DEFAULT_OPTIONS.tabStopWidth);
assert.equal(new OptionsService({ tabStopWidth: 0 }).options.tabStopWidth, DEFAULT_OPTIONS.tabStopWidth);
});
it('object.keys return the correct number of options', () => {
const optionsService = new OptionsService({ cols: 80, rows: 25 });
@@ -39,36 +39,36 @@ describe('OptionsService', () => {
service = new OptionsService({});
});
it('applies valid fontWeight option values', () => {
service.setOption('fontWeight', 'bold');
assert.equal(service.getOption('fontWeight'), 'bold', '"bold" keyword value should be applied');
service.options.fontWeight = 'bold';
assert.equal(service.options.fontWeight, 'bold', '"bold" keyword value should be applied');
service.setOption('fontWeight', 'normal');
assert.equal(service.getOption('fontWeight'), 'normal', '"normal" keyword value should be applied');
service.options.fontWeight = 'normal';
assert.equal(service.options.fontWeight, 'normal', '"normal" keyword value should be applied');
service.setOption('fontWeight', '600');
assert.equal(service.getOption('fontWeight'), '600', 'String numeric values should be applied');
service.options.fontWeight = '600';
assert.equal(service.options.fontWeight, '600', 'String numeric values should be applied');
service.setOption('fontWeight', 350);
assert.equal(service.getOption('fontWeight'), 350, 'Values between 1 and 1000 should be applied as is');
service.options.fontWeight = 350;
assert.equal(service.options.fontWeight, 350, 'Values between 1 and 1000 should be applied as is');
service.setOption('fontWeight', 1);
assert.equal(service.getOption('fontWeight'), 1, 'Range should include minimum value: 1');
service.options.fontWeight = 1;
assert.equal(service.options.fontWeight, 1, 'Range should include minimum value: 1');
service.setOption('fontWeight', 1000);
assert.equal(service.getOption('fontWeight'), 1000, 'Range should include maximum value: 1000');
service.options.fontWeight = 1000;
assert.equal(service.options.fontWeight, 1000, 'Range should include maximum value: 1000');
});
it('normalizes invalid fontWeight option values', () => {
service.setOption('fontWeight', 350);
assert.doesNotThrow(() => service.setOption('fontWeight', 10000), 'fontWeight should be normalized instead of throwing');
assert.equal(service.getOption('fontWeight'), DEFAULT_OPTIONS.fontWeight, 'Values greater than 1000 should be reset to default');
service.options.fontWeight = 350;
assert.doesNotThrow(() => service.options.fontWeight = 10000), 'fontWeight should be normalized instead of throwing';
assert.equal(service.options.fontWeight, DEFAULT_OPTIONS.fontWeight, 'Values greater than 1000 should be reset to default');
service.setOption('fontWeight', 350);
service.setOption('fontWeight', -10);
assert.equal(service.getOption('fontWeight'), DEFAULT_OPTIONS.fontWeight, 'Values less than 1 should be reset to default');
service.options.fontWeight = 350;
service.options.fontWeight = -10;
assert.equal(service.options.fontWeight, DEFAULT_OPTIONS.fontWeight, 'Values less than 1 should be reset to default');
service.setOption('fontWeight', 350);
service.setOption('fontWeight', 'bold700');
assert.equal(service.getOption('fontWeight'), DEFAULT_OPTIONS.fontWeight, 'Wrong string literals should be reset to default');
service.options.fontWeight = 350;
service.options.fontWeight = 'bold700' as any;
assert.equal(service.options.fontWeight, DEFAULT_OPTIONS.fontWeight, 'Wrong string literals should be reset to default');
});
});
});
-8
View File
@@ -109,10 +109,6 @@ export class OptionsService implements IOptionsService {
}
}
public setOption(key: string, value: any): void {
this.options[key] = value;
}
private _sanitizeAndValidateOption(key: string, value: any): any {
switch (key) {
case 'cursorStyle':
@@ -170,10 +166,6 @@ export class OptionsService implements IOptionsService {
}
return value;
}
public getOption(key: string): any {
return this.options[key];
}
}
function isCursorStyle(value: unknown): value is CursorStyle {
-3
View File
@@ -198,9 +198,6 @@ export interface IOptionsService {
readonly options: ITerminalOptions;
readonly onOptionChange: IEvent<string>;
setOption<T>(key: string, value: T): void;
getOption<T>(key: string): T | undefined;
}
export type FontWeight = 'normal' | 'bold' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900' | number;