diff options
author | Andrea Mah <31675041+andreamah@users.noreply.github.com> | 2022-11-09 23:13:49 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-09 23:13:49 +0300 |
commit | ad9a4ab198b21de2fa2eff563a45ec1e1a6f6a8a (patch) | |
tree | 8444ed2ca3f11f6abb024d3287c2ca26257305f5 | |
parent | 1b019bc592dc178e40f72a754e693e60d349ec11 (diff) |
Fix typings issues with `TestInstantiationService` (search) (#165945)
cherry-pick cbef6c2cfb3919f3b3a4b6eef45d31e8a3cf5855 for fixing testInstatiationService in search
3 files changed, 64 insertions, 15 deletions
diff --git a/src/vs/workbench/contrib/search/test/browser/searchActions.test.ts b/src/vs/workbench/contrib/search/test/browser/searchActions.test.ts index 975e022550b..f8103e8652c 100644 --- a/src/vs/workbench/contrib/search/test/browser/searchActions.test.ts +++ b/src/vs/workbench/contrib/search/test/browser/searchActions.test.ts @@ -5,7 +5,7 @@ import * as assert from 'assert'; import { Keybinding } from 'vs/base/common/keybindings'; -import { OS } from 'vs/base/common/platform'; +import { isWindows, OS } from 'vs/base/common/platform'; import { URI } from 'vs/base/common/uri'; import { IModelService } from 'vs/editor/common/services/model'; import { ModelService } from 'vs/editor/common/services/modelService'; @@ -16,7 +16,7 @@ import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; import { USLayoutResolvedKeybinding } from 'vs/platform/keybinding/common/usLayoutResolvedKeybinding'; import { IFileMatch } from 'vs/workbench/services/search/common/search'; import { getElementToFocusAfterRemoved, getLastNodeFromSameType } from 'vs/workbench/contrib/search/browser/searchActions'; -import { FileMatch, FileMatchOrMatch, Match } from 'vs/workbench/contrib/search/common/searchModel'; +import { FileMatch, FileMatchOrMatch, FolderMatch, Match, SearchModel } from 'vs/workbench/contrib/search/common/searchModel'; import { MockObjectTree } from 'vs/workbench/contrib/search/test/browser/mockSearchTree'; import { IThemeService } from 'vs/platform/theme/common/themeService'; import { TestThemeService } from 'vs/platform/theme/test/common/testThemeService'; @@ -109,7 +109,37 @@ suite('Search Actions', () => { resource: URI.file('somepath' + ++counter), results: [] }; - return instantiationService.createInstance(FileMatch, null, null, null, null, rawMatch, null); + + const searchModel = instantiationService.createInstance(SearchModel); + const folderMatch = instantiationService.createInstance(FolderMatch, URI.file('somepath'), '', 0, { + type: 1, folderQueries: [{ folder: createFileUriFromPathFromRoot() }], contentPattern: { + pattern: '' + } + }, searchModel.searchResult, searchModel, null); + return instantiationService.createInstance(FileMatch, { + pattern: '' + }, undefined, undefined, folderMatch, rawMatch, null); + } + + function createFileUriFromPathFromRoot(path?: string): URI { + const rootName = getRootName(); + if (path) { + return URI.file(`${rootName}${path}`); + } else { + if (isWindows) { + return URI.file(`${rootName}/`); + } else { + return URI.file(rootName); + } + } + } + + function getRootName(): string { + if (isWindows) { + return 'c:'; + } else { + return ''; + } } function aMatch(fileMatch: FileMatch): Match { diff --git a/src/vs/workbench/contrib/search/test/browser/searchViewlet.test.ts b/src/vs/workbench/contrib/search/test/browser/searchViewlet.test.ts index a51ea982326..b77466a34c4 100644 --- a/src/vs/workbench/contrib/search/test/browser/searchViewlet.test.ts +++ b/src/vs/workbench/contrib/search/test/browser/searchViewlet.test.ts @@ -40,7 +40,7 @@ suite('Search - Viewlet', () => { }); test('Data Source', function () { - const result: SearchResult = instantiation.createInstance(SearchResult, null); + const result: SearchResult = aSearchResult(); result.query = { type: QueryType.Text, contentPattern: { pattern: 'foo' }, @@ -166,20 +166,30 @@ suite('Search - Viewlet', () => { function aFileMatch(path: string, parentFolder?: FolderMatch, ...lineMatches: ITextSearchMatch[]): FileMatch { const rawMatch: IFileMatch = { - resource: createFileUriFromPathFromRoot(path), + resource: URI.file('/' + path), results: lineMatches }; - return instantiation.createInstance(FileMatch, null, null, null, parentFolder, rawMatch, parentFolder); + return instantiation.createInstance(FileMatch, { + pattern: '' + }, undefined, undefined, parentFolder ?? aFolderMatch('', 0), rawMatch, null); } function aFolderMatch(path: string, index: number, parent?: SearchResult): FolderMatch { const searchModel = instantiation.createInstance(SearchModel); - return instantiation.createInstance(FolderMatch, createFileUriFromPathFromRoot(path), path, index, null, parent, searchModel, parent); + return instantiation.createInstance(FolderMatch, createFileUriFromPathFromRoot(path), path, index, { + type: 1, folderQueries: [{ folder: createFileUriFromPathFromRoot() }], contentPattern: { + pattern: '' + } + }, parent ?? aSearchResult().folderMatches()[0], searchModel, null); } function aSearchResult(): SearchResult { const searchModel = instantiation.createInstance(SearchModel); - searchModel.searchResult.query = { type: 1, folderQueries: [{ folder: createFileUriFromPathFromRoot() }] }; + searchModel.searchResult.query = { + type: 1, folderQueries: [{ folder: createFileUriFromPathFromRoot() }], contentPattern: { + pattern: '' + } + }; return searchModel.searchResult; } diff --git a/src/vs/workbench/contrib/search/test/common/searchResult.test.ts b/src/vs/workbench/contrib/search/test/common/searchResult.test.ts index b7c72c0c44c..9ca82db188a 100644 --- a/src/vs/workbench/contrib/search/test/common/searchResult.test.ts +++ b/src/vs/workbench/contrib/search/test/common/searchResult.test.ts @@ -65,12 +65,12 @@ suite('SearchResult', () => { }); test('File Match', function () { - let fileMatch = aFileMatch('folder/file.txt'); + let fileMatch = aFileMatch('folder/file.txt', aSearchResult()); assert.strictEqual(fileMatch.matches().length, 0); assert.strictEqual(fileMatch.resource.toString(), 'file:///folder/file.txt'); assert.strictEqual(fileMatch.name(), 'file.txt'); - fileMatch = aFileMatch('file.txt'); + fileMatch = aFileMatch('file.txt', aSearchResult()); assert.strictEqual(fileMatch.matches().length, 0); assert.strictEqual(fileMatch.resource.toString(), 'file:///file.txt'); assert.strictEqual(fileMatch.name(), 'file.txt'); @@ -147,12 +147,14 @@ suite('SearchResult', () => { }); test('Match -> FileMatch -> SearchResult hierarchy exists', function () { - const searchResult = instantiationService.createInstance(SearchResult, null); + + const searchModel = instantiationService.createInstance(SearchModel); + const searchResult = instantiationService.createInstance(SearchResult, searchModel); const fileMatch = aFileMatch('far/boo', searchResult); const lineMatch = new Match(fileMatch, ['foo bar'], new OneLineRange(0, 0, 3), new OneLineRange(1, 0, 3)); assert(lineMatch.parent() === fileMatch); - assert(fileMatch.parent() === searchResult); + assert(fileMatch.parent() === searchResult.folderMatches()[0]); }); test('Adding a raw match will add a file match with line matches', function () { @@ -467,17 +469,24 @@ suite('SearchResult', () => { }); - function aFileMatch(path: string, searchResult?: SearchResult, ...lineMatches: ITextSearchMatch[]): FileMatch { + function aFileMatch(path: string, searchResult: SearchResult, ...lineMatches: ITextSearchMatch[]): FileMatch { const rawMatch: IFileMatch = { resource: URI.file('/' + path), results: lineMatches }; - return instantiationService.createInstance(FileMatch, null, null, null, searchResult, rawMatch, searchResult); + const root = searchResult?.folderMatches()[0]; + return instantiationService.createInstance(FileMatch, { + pattern: '' + }, undefined, undefined, root, rawMatch, null); } function aSearchResult(): SearchResult { const searchModel = instantiationService.createInstance(SearchModel); - searchModel.searchResult.query = { type: 1, folderQueries: [{ folder: createFileUriFromPathFromRoot() }] }; + searchModel.searchResult.query = { + type: 1, folderQueries: [{ folder: createFileUriFromPathFromRoot() }], contentPattern: { + pattern: '' + } + }; return searchModel.searchResult; } |