Skip to content

Commit 9d0b7ce

Browse files
authored
debt - speed up sticky scroll unit tests (microsoft#149712) (microsoft#181196)
1 parent d289165 commit 9d0b7ce

File tree

1 file changed

+157
-151
lines changed

1 file changed

+157
-151
lines changed

src/vs/editor/contrib/stickyScroll/test/browser/stickyScroll.test.ts

Lines changed: 157 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { ILanguageConfigurationService } from 'vs/editor/common/languages/langua
1919
import { ILanguageFeatureDebounceService, LanguageFeatureDebounceService } from 'vs/editor/common/services/languageFeatureDebounce';
2020
import { TestLanguageConfigurationService } from 'vs/editor/test/common/modes/testLanguageConfigurationService';
2121
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
22+
import { runWithFakedTimers } from 'vs/base/test/common/timeTravelScheduler';
2223

2324
suite('Sticky Scroll Tests', () => {
2425

@@ -110,120 +111,124 @@ suite('Sticky Scroll Tests', () => {
110111
};
111112
}
112113

113-
test('Testing the function getCandidateStickyLinesIntersecting', async () => {
114-
const model = createTextModel(text);
115-
await withAsyncTestCodeEditor(model, {
116-
stickyScroll: {
117-
enabled: true,
118-
maxLineCount: 5,
119-
defaultModel: 'outlineModel'
120-
}, serviceCollection: serviceCollection
121-
}, async (editor, _viewModel, instantiationService) => {
122-
const languageService = instantiationService.get(ILanguageFeaturesService);
123-
const languageConfigurationService = instantiationService.get(ILanguageConfigurationService);
124-
languageService.documentSymbolProvider.register('*', documentSymbolProviderForTestModel());
125-
const provider: StickyLineCandidateProvider = new StickyLineCandidateProvider(editor, languageService, languageConfigurationService);
126-
await provider.update();
127-
assert.deepStrictEqual(provider.getCandidateStickyLinesIntersecting({ startLineNumber: 1, endLineNumber: 4 }), [new StickyLineCandidate(1, 2, 1)]);
128-
assert.deepStrictEqual(provider.getCandidateStickyLinesIntersecting({ startLineNumber: 8, endLineNumber: 10 }), [new StickyLineCandidate(7, 11, 1), new StickyLineCandidate(9, 11, 2), new StickyLineCandidate(10, 10, 3)]);
129-
assert.deepStrictEqual(provider.getCandidateStickyLinesIntersecting({ startLineNumber: 10, endLineNumber: 13 }), [new StickyLineCandidate(7, 11, 1), new StickyLineCandidate(9, 11, 2), new StickyLineCandidate(10, 10, 3)]);
130-
131-
provider.dispose();
132-
model.dispose();
114+
test('Testing the function getCandidateStickyLinesIntersecting', () => {
115+
return runWithFakedTimers({ useFakeTimers: true }, async () => {
116+
const model = createTextModel(text);
117+
await withAsyncTestCodeEditor(model, {
118+
stickyScroll: {
119+
enabled: true,
120+
maxLineCount: 5,
121+
defaultModel: 'outlineModel'
122+
}, serviceCollection: serviceCollection
123+
}, async (editor, _viewModel, instantiationService) => {
124+
const languageService = instantiationService.get(ILanguageFeaturesService);
125+
const languageConfigurationService = instantiationService.get(ILanguageConfigurationService);
126+
languageService.documentSymbolProvider.register('*', documentSymbolProviderForTestModel());
127+
const provider: StickyLineCandidateProvider = new StickyLineCandidateProvider(editor, languageService, languageConfigurationService);
128+
await provider.update();
129+
assert.deepStrictEqual(provider.getCandidateStickyLinesIntersecting({ startLineNumber: 1, endLineNumber: 4 }), [new StickyLineCandidate(1, 2, 1)]);
130+
assert.deepStrictEqual(provider.getCandidateStickyLinesIntersecting({ startLineNumber: 8, endLineNumber: 10 }), [new StickyLineCandidate(7, 11, 1), new StickyLineCandidate(9, 11, 2), new StickyLineCandidate(10, 10, 3)]);
131+
assert.deepStrictEqual(provider.getCandidateStickyLinesIntersecting({ startLineNumber: 10, endLineNumber: 13 }), [new StickyLineCandidate(7, 11, 1), new StickyLineCandidate(9, 11, 2), new StickyLineCandidate(10, 10, 3)]);
132+
133+
provider.dispose();
134+
model.dispose();
135+
});
133136
});
134137
});
135138

136-
test('issue #157180: Render the correct line corresponding to the scope definition', async () => {
137-
138-
const model = createTextModel(text);
139-
await withAsyncTestCodeEditor(model, {
140-
stickyScroll: {
141-
enabled: true,
142-
maxLineCount: 5,
143-
defaultModel: 'outlineModel'
144-
}, serviceCollection
145-
}, async (editor, _viewModel, instantiationService) => {
146-
147-
const stickyScrollController: StickyScrollController = editor.registerAndInstantiateContribution(StickyScrollController.ID, StickyScrollController);
148-
const lineHeight: number = editor.getOption(EditorOption.lineHeight);
149-
const languageService: ILanguageFeaturesService = instantiationService.get(ILanguageFeaturesService);
150-
languageService.documentSymbolProvider.register('*', documentSymbolProviderForTestModel());
151-
await stickyScrollController.stickyScrollCandidateProvider.update();
152-
let state;
153-
154-
editor.setScrollTop(1);
155-
state = stickyScrollController.findScrollWidgetState();
156-
assert.deepStrictEqual(state.lineNumbers, [1]);
157-
158-
editor.setScrollTop(lineHeight + 1);
159-
state = stickyScrollController.findScrollWidgetState();
160-
assert.deepStrictEqual(state.lineNumbers, [1]);
161-
162-
editor.setScrollTop(4 * lineHeight + 1);
163-
state = stickyScrollController.findScrollWidgetState();
164-
assert.deepStrictEqual(state.lineNumbers, []);
165-
166-
editor.setScrollTop(8 * lineHeight + 1);
167-
state = stickyScrollController.findScrollWidgetState();
168-
assert.deepStrictEqual(state.lineNumbers, [7, 9]);
169-
170-
editor.setScrollTop(9 * lineHeight + 1);
171-
state = stickyScrollController.findScrollWidgetState();
172-
assert.deepStrictEqual(state.lineNumbers, [7, 9]);
173-
174-
editor.setScrollTop(10 * lineHeight + 1);
175-
state = stickyScrollController.findScrollWidgetState();
176-
assert.deepStrictEqual(state.lineNumbers, [7]);
177-
178-
stickyScrollController.dispose();
179-
stickyScrollController.stickyScrollCandidateProvider.dispose();
180-
model.dispose();
139+
test('issue #157180: Render the correct line corresponding to the scope definition', () => {
140+
return runWithFakedTimers({ useFakeTimers: true }, async () => {
141+
const model = createTextModel(text);
142+
await withAsyncTestCodeEditor(model, {
143+
stickyScroll: {
144+
enabled: true,
145+
maxLineCount: 5,
146+
defaultModel: 'outlineModel'
147+
}, serviceCollection
148+
}, async (editor, _viewModel, instantiationService) => {
149+
150+
const stickyScrollController: StickyScrollController = editor.registerAndInstantiateContribution(StickyScrollController.ID, StickyScrollController);
151+
const lineHeight: number = editor.getOption(EditorOption.lineHeight);
152+
const languageService: ILanguageFeaturesService = instantiationService.get(ILanguageFeaturesService);
153+
languageService.documentSymbolProvider.register('*', documentSymbolProviderForTestModel());
154+
await stickyScrollController.stickyScrollCandidateProvider.update();
155+
let state;
156+
157+
editor.setScrollTop(1);
158+
state = stickyScrollController.findScrollWidgetState();
159+
assert.deepStrictEqual(state.lineNumbers, [1]);
160+
161+
editor.setScrollTop(lineHeight + 1);
162+
state = stickyScrollController.findScrollWidgetState();
163+
assert.deepStrictEqual(state.lineNumbers, [1]);
164+
165+
editor.setScrollTop(4 * lineHeight + 1);
166+
state = stickyScrollController.findScrollWidgetState();
167+
assert.deepStrictEqual(state.lineNumbers, []);
168+
169+
editor.setScrollTop(8 * lineHeight + 1);
170+
state = stickyScrollController.findScrollWidgetState();
171+
assert.deepStrictEqual(state.lineNumbers, [7, 9]);
172+
173+
editor.setScrollTop(9 * lineHeight + 1);
174+
state = stickyScrollController.findScrollWidgetState();
175+
assert.deepStrictEqual(state.lineNumbers, [7, 9]);
176+
177+
editor.setScrollTop(10 * lineHeight + 1);
178+
state = stickyScrollController.findScrollWidgetState();
179+
assert.deepStrictEqual(state.lineNumbers, [7]);
180+
181+
stickyScrollController.dispose();
182+
stickyScrollController.stickyScrollCandidateProvider.dispose();
183+
model.dispose();
184+
});
181185
});
182186
});
183187

184-
test('issue #156268 : Do not reveal sticky lines when they are in a folded region ', async () => {
185-
186-
const model = createTextModel(text);
187-
await withAsyncTestCodeEditor(model, {
188-
stickyScroll: {
189-
enabled: true,
190-
maxLineCount: 5,
191-
defaultModel: 'outlineModel'
192-
}, serviceCollection
193-
}, async (editor, viewModel, instantiationService) => {
194-
195-
const stickyScrollController: StickyScrollController = editor.registerAndInstantiateContribution(StickyScrollController.ID, StickyScrollController);
196-
const lineHeight = editor.getOption(EditorOption.lineHeight);
197-
198-
const languageService = instantiationService.get(ILanguageFeaturesService);
199-
languageService.documentSymbolProvider.register('*', documentSymbolProviderForTestModel());
200-
await stickyScrollController.stickyScrollCandidateProvider.update();
201-
editor.setHiddenAreas([{ startLineNumber: 2, endLineNumber: 2, startColumn: 1, endColumn: 1 }, { startLineNumber: 10, endLineNumber: 11, startColumn: 1, endColumn: 1 }]);
202-
let state;
203-
204-
editor.setScrollTop(1);
205-
state = stickyScrollController.findScrollWidgetState();
206-
assert.deepStrictEqual(state.lineNumbers, [1]);
207-
208-
editor.setScrollTop(lineHeight + 1);
209-
state = stickyScrollController.findScrollWidgetState();
210-
assert.deepStrictEqual(state.lineNumbers, []);
211-
212-
editor.setScrollTop(6 * lineHeight + 1);
213-
state = stickyScrollController.findScrollWidgetState();
214-
assert.deepStrictEqual(state.lineNumbers, [7, 9]);
215-
216-
editor.setScrollTop(7 * lineHeight + 1);
217-
state = stickyScrollController.findScrollWidgetState();
218-
assert.deepStrictEqual(state.lineNumbers, [7]);
219-
220-
editor.setScrollTop(10 * lineHeight + 1);
221-
state = stickyScrollController.findScrollWidgetState();
222-
assert.deepStrictEqual(state.lineNumbers, []);
223-
224-
stickyScrollController.dispose();
225-
stickyScrollController.stickyScrollCandidateProvider.dispose();
226-
model.dispose();
188+
test('issue #156268 : Do not reveal sticky lines when they are in a folded region ', () => {
189+
return runWithFakedTimers({ useFakeTimers: true }, async () => {
190+
const model = createTextModel(text);
191+
await withAsyncTestCodeEditor(model, {
192+
stickyScroll: {
193+
enabled: true,
194+
maxLineCount: 5,
195+
defaultModel: 'outlineModel'
196+
}, serviceCollection
197+
}, async (editor, viewModel, instantiationService) => {
198+
199+
const stickyScrollController: StickyScrollController = editor.registerAndInstantiateContribution(StickyScrollController.ID, StickyScrollController);
200+
const lineHeight = editor.getOption(EditorOption.lineHeight);
201+
202+
const languageService = instantiationService.get(ILanguageFeaturesService);
203+
languageService.documentSymbolProvider.register('*', documentSymbolProviderForTestModel());
204+
await stickyScrollController.stickyScrollCandidateProvider.update();
205+
editor.setHiddenAreas([{ startLineNumber: 2, endLineNumber: 2, startColumn: 1, endColumn: 1 }, { startLineNumber: 10, endLineNumber: 11, startColumn: 1, endColumn: 1 }]);
206+
let state;
207+
208+
editor.setScrollTop(1);
209+
state = stickyScrollController.findScrollWidgetState();
210+
assert.deepStrictEqual(state.lineNumbers, [1]);
211+
212+
editor.setScrollTop(lineHeight + 1);
213+
state = stickyScrollController.findScrollWidgetState();
214+
assert.deepStrictEqual(state.lineNumbers, []);
215+
216+
editor.setScrollTop(6 * lineHeight + 1);
217+
state = stickyScrollController.findScrollWidgetState();
218+
assert.deepStrictEqual(state.lineNumbers, [7, 9]);
219+
220+
editor.setScrollTop(7 * lineHeight + 1);
221+
state = stickyScrollController.findScrollWidgetState();
222+
assert.deepStrictEqual(state.lineNumbers, [7]);
223+
224+
editor.setScrollTop(10 * lineHeight + 1);
225+
state = stickyScrollController.findScrollWidgetState();
226+
assert.deepStrictEqual(state.lineNumbers, []);
227+
228+
stickyScrollController.dispose();
229+
stickyScrollController.stickyScrollCandidateProvider.dispose();
230+
model.dispose();
231+
});
227232
});
228233
});
229234

@@ -274,49 +279,50 @@ suite('Sticky Scroll Tests', () => {
274279
};
275280
}
276281

277-
test('issue #159271 : render the correct widget state when the child scope starts on the same line as the parent scope', async () => {
278-
279-
const model = createTextModel(textWithScopesWithSameStartingLines);
280-
await withAsyncTestCodeEditor(model, {
281-
stickyScroll: {
282-
enabled: true,
283-
maxLineCount: 5,
284-
defaultModel: 'outlineModel'
285-
}, serviceCollection
286-
}, async (editor, _viewModel, instantiationService) => {
287-
288-
const stickyScrollController: StickyScrollController = editor.registerAndInstantiateContribution(StickyScrollController.ID, StickyScrollController);
289-
await stickyScrollController.stickyScrollCandidateProvider.update();
290-
const lineHeight = editor.getOption(EditorOption.lineHeight);
291-
292-
const languageService = instantiationService.get(ILanguageFeaturesService);
293-
languageService.documentSymbolProvider.register('*', documentSymbolProviderForSecondTestModel());
294-
await stickyScrollController.stickyScrollCandidateProvider.update();
295-
let state;
296-
297-
editor.setScrollTop(1);
298-
state = stickyScrollController.findScrollWidgetState();
299-
assert.deepStrictEqual(state.lineNumbers, [1, 2]);
300-
301-
editor.setScrollTop(lineHeight + 1);
302-
state = stickyScrollController.findScrollWidgetState();
303-
assert.deepStrictEqual(state.lineNumbers, [1, 2]);
304-
305-
editor.setScrollTop(2 * lineHeight + 1);
306-
state = stickyScrollController.findScrollWidgetState();
307-
assert.deepStrictEqual(state.lineNumbers, [1]);
308-
309-
editor.setScrollTop(3 * lineHeight + 1);
310-
state = stickyScrollController.findScrollWidgetState();
311-
assert.deepStrictEqual(state.lineNumbers, [1]);
312-
313-
editor.setScrollTop(4 * lineHeight + 1);
314-
state = stickyScrollController.findScrollWidgetState();
315-
assert.deepStrictEqual(state.lineNumbers, []);
316-
317-
stickyScrollController.dispose();
318-
stickyScrollController.stickyScrollCandidateProvider.dispose();
319-
model.dispose();
282+
test('issue #159271 : render the correct widget state when the child scope starts on the same line as the parent scope', () => {
283+
return runWithFakedTimers({ useFakeTimers: true }, async () => {
284+
const model = createTextModel(textWithScopesWithSameStartingLines);
285+
await withAsyncTestCodeEditor(model, {
286+
stickyScroll: {
287+
enabled: true,
288+
maxLineCount: 5,
289+
defaultModel: 'outlineModel'
290+
}, serviceCollection
291+
}, async (editor, _viewModel, instantiationService) => {
292+
293+
const stickyScrollController: StickyScrollController = editor.registerAndInstantiateContribution(StickyScrollController.ID, StickyScrollController);
294+
await stickyScrollController.stickyScrollCandidateProvider.update();
295+
const lineHeight = editor.getOption(EditorOption.lineHeight);
296+
297+
const languageService = instantiationService.get(ILanguageFeaturesService);
298+
languageService.documentSymbolProvider.register('*', documentSymbolProviderForSecondTestModel());
299+
await stickyScrollController.stickyScrollCandidateProvider.update();
300+
let state;
301+
302+
editor.setScrollTop(1);
303+
state = stickyScrollController.findScrollWidgetState();
304+
assert.deepStrictEqual(state.lineNumbers, [1, 2]);
305+
306+
editor.setScrollTop(lineHeight + 1);
307+
state = stickyScrollController.findScrollWidgetState();
308+
assert.deepStrictEqual(state.lineNumbers, [1, 2]);
309+
310+
editor.setScrollTop(2 * lineHeight + 1);
311+
state = stickyScrollController.findScrollWidgetState();
312+
assert.deepStrictEqual(state.lineNumbers, [1]);
313+
314+
editor.setScrollTop(3 * lineHeight + 1);
315+
state = stickyScrollController.findScrollWidgetState();
316+
assert.deepStrictEqual(state.lineNumbers, [1]);
317+
318+
editor.setScrollTop(4 * lineHeight + 1);
319+
state = stickyScrollController.findScrollWidgetState();
320+
assert.deepStrictEqual(state.lineNumbers, []);
321+
322+
stickyScrollController.dispose();
323+
stickyScrollController.stickyScrollCandidateProvider.dispose();
324+
model.dispose();
325+
});
320326
});
321327
});
322328
});

0 commit comments

Comments
 (0)