Use disposableStore in a few test files

This commit is contained in:
Matt Bierner 2019-06-10 16:25:41 -07:00
parent ecad75fdeb
commit 856086b818
3 changed files with 55 additions and 49 deletions

View file

@ -5,7 +5,7 @@
import * as assert from 'assert';
import { CancellationToken } from 'vs/base/common/cancellation';
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
import { DisposableStore } from 'vs/base/common/lifecycle';
import { URI } from 'vs/base/common/uri';
import { Position } from 'vs/editor/common/core/position';
import { Handler } from 'vs/editor/common/editorCommon';
@ -32,10 +32,14 @@ const emptySigHelpResult = {
activeSignature: 0
};
suite('ParameterHintsModel', () => {
let disposables: IDisposable[] = [];
const disposables = new DisposableStore();
setup(function () {
disposables = dispose(disposables);
setup(() => {
disposables.clear();
});
teardown(() => {
disposables.clear();
});
function createMockEditor(fileContents: string) {
@ -47,8 +51,8 @@ suite('ParameterHintsModel', () => {
[IStorageService, new InMemoryStorageService()]
)
});
disposables.push(textModel);
disposables.push(editor);
disposables.add(textModel);
disposables.add(editor);
return editor;
}
@ -56,9 +60,9 @@ suite('ParameterHintsModel', () => {
const triggerChar = '(';
const editor = createMockEditor('');
disposables.push(new ParameterHintsModel(editor));
disposables.add(new ParameterHintsModel(editor));
disposables.push(modes.SignatureHelpProviderRegistry.register(mockFileSelector, new class implements modes.SignatureHelpProvider {
disposables.add(modes.SignatureHelpProviderRegistry.register(mockFileSelector, new class implements modes.SignatureHelpProvider {
signatureHelpTriggerCharacters = [triggerChar];
signatureHelpRetriggerCharacters = [];
@ -77,10 +81,10 @@ suite('ParameterHintsModel', () => {
const triggerChar = '(';
const editor = createMockEditor('');
disposables.push(new ParameterHintsModel(editor));
disposables.add(new ParameterHintsModel(editor));
let invokeCount = 0;
disposables.push(modes.SignatureHelpProviderRegistry.register(mockFileSelector, new class implements modes.SignatureHelpProvider {
disposables.add(modes.SignatureHelpProviderRegistry.register(mockFileSelector, new class implements modes.SignatureHelpProvider {
signatureHelpTriggerCharacters = [triggerChar];
signatureHelpRetriggerCharacters = [];
@ -115,10 +119,10 @@ suite('ParameterHintsModel', () => {
const editor = createMockEditor('');
const hintModel = new ParameterHintsModel(editor);
disposables.push(hintModel);
disposables.add(hintModel);
let invokeCount = 0;
disposables.push(modes.SignatureHelpProviderRegistry.register(mockFileSelector, new class implements modes.SignatureHelpProvider {
disposables.add(modes.SignatureHelpProviderRegistry.register(mockFileSelector, new class implements modes.SignatureHelpProvider {
signatureHelpTriggerCharacters = [triggerChar];
signatureHelpRetriggerCharacters = [];
@ -150,10 +154,10 @@ suite('ParameterHintsModel', () => {
test('Provider should get last trigger character when triggered multiple times and only be invoked once', (done) => {
const editor = createMockEditor('');
disposables.push(new ParameterHintsModel(editor, 5));
disposables.add(new ParameterHintsModel(editor, 5));
let invokeCount = 0;
disposables.push(modes.SignatureHelpProviderRegistry.register(mockFileSelector, new class implements modes.SignatureHelpProvider {
disposables.add(modes.SignatureHelpProviderRegistry.register(mockFileSelector, new class implements modes.SignatureHelpProvider {
signatureHelpTriggerCharacters = ['a', 'b', 'c'];
signatureHelpRetriggerCharacters = [];
@ -181,10 +185,10 @@ suite('ParameterHintsModel', () => {
test('Provider should be retriggered if already active', (done) => {
const editor = createMockEditor('');
disposables.push(new ParameterHintsModel(editor, 5));
disposables.add(new ParameterHintsModel(editor, 5));
let invokeCount = 0;
disposables.push(modes.SignatureHelpProviderRegistry.register(mockFileSelector, new class implements modes.SignatureHelpProvider {
disposables.add(modes.SignatureHelpProviderRegistry.register(mockFileSelector, new class implements modes.SignatureHelpProvider {
signatureHelpTriggerCharacters = ['a', 'b'];
signatureHelpRetriggerCharacters = [];
@ -247,7 +251,7 @@ suite('ParameterHintsModel', () => {
}
};
disposables.push(modes.SignatureHelpProviderRegistry.register(mockFileSelector, longRunningProvider));
disposables.add(modes.SignatureHelpProviderRegistry.register(mockFileSelector, longRunningProvider));
hintsModel.trigger({ triggerKind: modes.SignatureHelpTriggerKind.Invoke }, 0);
assert.strictEqual(-1, didRequestCancellationOf);
@ -269,10 +273,10 @@ suite('ParameterHintsModel', () => {
const retriggerChar = 'b';
const editor = createMockEditor('');
disposables.push(new ParameterHintsModel(editor, 5));
disposables.add(new ParameterHintsModel(editor, 5));
let invokeCount = 0;
disposables.push(modes.SignatureHelpProviderRegistry.register(mockFileSelector, new class implements modes.SignatureHelpProvider {
disposables.add(modes.SignatureHelpProviderRegistry.register(mockFileSelector, new class implements modes.SignatureHelpProvider {
signatureHelpTriggerCharacters = [triggerChar];
signatureHelpRetriggerCharacters = [retriggerChar];
@ -312,9 +316,9 @@ suite('ParameterHintsModel', () => {
const editor = createMockEditor('');
const model = new ParameterHintsModel(editor, 5);
disposables.push(model);
disposables.add(model);
disposables.push(modes.SignatureHelpProviderRegistry.register(mockFileSelector, new class implements modes.SignatureHelpProvider {
disposables.add(modes.SignatureHelpProviderRegistry.register(mockFileSelector, new class implements modes.SignatureHelpProvider {
signatureHelpTriggerCharacters = [triggerChar];
signatureHelpRetriggerCharacters = [];
@ -339,7 +343,7 @@ suite('ParameterHintsModel', () => {
}
}));
disposables.push(modes.SignatureHelpProviderRegistry.register(mockFileSelector, new class implements modes.SignatureHelpProvider {
disposables.add(modes.SignatureHelpProviderRegistry.register(mockFileSelector, new class implements modes.SignatureHelpProvider {
signatureHelpTriggerCharacters = [triggerChar];
signatureHelpRetriggerCharacters = [];

View file

@ -6,7 +6,7 @@
import * as assert from 'assert';
import { MenuRegistry, MenuId, isIMenuItem } from 'vs/platform/actions/common/actions';
import { MenuService } from 'vs/platform/actions/common/menuService';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { DisposableStore } from 'vs/base/common/lifecycle';
import { NullCommandService } from 'vs/platform/commands/common/commands';
import { MockContextKeyService } from 'vs/platform/keybinding/test/common/mockKeybindingService';
@ -23,42 +23,42 @@ const contextKeyService = new class extends MockContextKeyService {
suite('MenuService', function () {
let menuService: MenuService;
let disposables: IDisposable[];
const disposables = new DisposableStore();
let testMenuId: MenuId;
setup(function () {
menuService = new MenuService(NullCommandService);
testMenuId = Math.PI;
disposables = [];
disposables.clear();
});
teardown(function () {
dispose(disposables);
disposables.clear();
});
test('group sorting', function () {
disposables.push(MenuRegistry.appendMenuItem(testMenuId, {
disposables.add(MenuRegistry.appendMenuItem(testMenuId, {
command: { id: 'one', title: 'FOO' },
group: '0_hello'
}));
disposables.push(MenuRegistry.appendMenuItem(testMenuId, {
disposables.add(MenuRegistry.appendMenuItem(testMenuId, {
command: { id: 'two', title: 'FOO' },
group: 'hello'
}));
disposables.push(MenuRegistry.appendMenuItem(testMenuId, {
disposables.add(MenuRegistry.appendMenuItem(testMenuId, {
command: { id: 'three', title: 'FOO' },
group: 'Hello'
}));
disposables.push(MenuRegistry.appendMenuItem(testMenuId, {
disposables.add(MenuRegistry.appendMenuItem(testMenuId, {
command: { id: 'four', title: 'FOO' },
group: ''
}));
disposables.push(MenuRegistry.appendMenuItem(testMenuId, {
disposables.add(MenuRegistry.appendMenuItem(testMenuId, {
command: { id: 'five', title: 'FOO' },
group: 'navigation'
}));
@ -77,17 +77,17 @@ suite('MenuService', function () {
test('in group sorting, by title', function () {
disposables.push(MenuRegistry.appendMenuItem(testMenuId, {
disposables.add(MenuRegistry.appendMenuItem(testMenuId, {
command: { id: 'a', title: 'aaa' },
group: 'Hello'
}));
disposables.push(MenuRegistry.appendMenuItem(testMenuId, {
disposables.add(MenuRegistry.appendMenuItem(testMenuId, {
command: { id: 'b', title: 'fff' },
group: 'Hello'
}));
disposables.push(MenuRegistry.appendMenuItem(testMenuId, {
disposables.add(MenuRegistry.appendMenuItem(testMenuId, {
command: { id: 'c', title: 'zzz' },
group: 'Hello'
}));
@ -106,24 +106,24 @@ suite('MenuService', function () {
test('in group sorting, by title and order', function () {
disposables.push(MenuRegistry.appendMenuItem(testMenuId, {
disposables.add(MenuRegistry.appendMenuItem(testMenuId, {
command: { id: 'a', title: 'aaa' },
group: 'Hello',
order: 10
}));
disposables.push(MenuRegistry.appendMenuItem(testMenuId, {
disposables.add(MenuRegistry.appendMenuItem(testMenuId, {
command: { id: 'b', title: 'fff' },
group: 'Hello'
}));
disposables.push(MenuRegistry.appendMenuItem(testMenuId, {
disposables.add(MenuRegistry.appendMenuItem(testMenuId, {
command: { id: 'c', title: 'zzz' },
group: 'Hello',
order: -1
}));
disposables.push(MenuRegistry.appendMenuItem(testMenuId, {
disposables.add(MenuRegistry.appendMenuItem(testMenuId, {
command: { id: 'd', title: 'yyy' },
group: 'Hello',
order: -1
@ -145,19 +145,19 @@ suite('MenuService', function () {
test('in group sorting, special: navigation', function () {
disposables.push(MenuRegistry.appendMenuItem(testMenuId, {
disposables.add(MenuRegistry.appendMenuItem(testMenuId, {
command: { id: 'a', title: 'aaa' },
group: 'navigation',
order: 1.3
}));
disposables.push(MenuRegistry.appendMenuItem(testMenuId, {
disposables.add(MenuRegistry.appendMenuItem(testMenuId, {
command: { id: 'b', title: 'fff' },
group: 'navigation',
order: 1.2
}));
disposables.push(MenuRegistry.appendMenuItem(testMenuId, {
disposables.add(MenuRegistry.appendMenuItem(testMenuId, {
command: { id: 'c', title: 'zzz' },
group: 'navigation',
order: 1.1
@ -177,7 +177,7 @@ suite('MenuService', function () {
test('special MenuId palette', function () {
disposables.push(MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
disposables.add(MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
command: { id: 'a', title: 'Explicit' }
}));

View file

@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { IDisposable, DisposableStore } from 'vs/base/common/lifecycle';
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
import { CommandService } from 'vs/workbench/services/commands/common/commandService';
import { NullExtensionService } from 'vs/workbench/services/extensions/common/extensions';
@ -103,7 +103,7 @@ suite('CommandService', function () {
test('Stop waiting for * extensions to activate when trigger is satisfied #62457', function () {
let callCounter = 0;
let dispoables: IDisposable[] = [];
const dispoables = new DisposableStore();
let events: string[] = [];
let service = new CommandService(new InstantiationService(), new class extends NullExtensionService {
@ -118,7 +118,7 @@ suite('CommandService', function () {
let reg = CommandsRegistry.registerCommand(event.substr('onCommand:'.length), () => {
callCounter += 1;
});
dispoables.push(reg);
dispoables.add(reg);
resolve();
}, 0);
});
@ -131,14 +131,15 @@ suite('CommandService', function () {
return service.executeCommand('farboo').then(() => {
assert.equal(callCounter, 1);
assert.deepEqual(events.sort(), ['*', 'onCommand:farboo'].sort());
dispose(dispoables);
}).finally(() => {
dispoables.dispose();
});
});
test('issue #71471: wait for onCommand activation even if a command is registered', () => {
let expectedOrder: string[] = ['registering command', 'resolving activation event', 'executing command'];
let actualOrder: string[] = [];
let disposables: IDisposable[] = [];
const disposables = new DisposableStore();
let service = new CommandService(new InstantiationService(), new class extends NullExtensionService {
activateByEvent(event: string): Promise<void> {
@ -153,7 +154,7 @@ suite('CommandService', function () {
let reg = CommandsRegistry.registerCommand(event.substr('onCommand:'.length), () => {
actualOrder.push('executing command');
});
disposables.push(reg);
disposables.add(reg);
setTimeout(() => {
// Resolve the activation event after some more time
@ -170,7 +171,8 @@ suite('CommandService', function () {
return service.executeCommand('farboo2').then(() => {
assert.deepEqual(actualOrder, expectedOrder);
dispose(disposables);
}).finally(() => {
disposables.dispose();
});
});
});