当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript instantiationServiceMock.TestInstantiationService类代码示例

本文整理汇总了TypeScript中vs/platform/instantiation/test/common/instantiationServiceMock.TestInstantiationService的典型用法代码示例。如果您正苦于以下问题:TypeScript TestInstantiationService类的具体用法?TypeScript TestInstantiationService怎么用?TypeScript TestInstantiationService使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了TestInstantiationService类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: suite

suite('SearchModel', () => {

	let instantiationService: TestInstantiationService;
	let restoreStubs: sinon.SinonStub[];

	const testSearchStats: IUncachedSearchStats = {
		fromCache: false,
		resultCount: 4,
		traversal: 'node',
		errors: [],
		fileWalkStartTime: 0,
		fileWalkResultTime: 1,
		directoriesWalked: 2,
		filesWalked: 3
	};

	const folderQueries: IFolderQuery[] = [
		{ folder: URI.parse('file://c:/') }
	];

	setup(() => {
		restoreStubs = [];
		instantiationService = new TestInstantiationService();
		instantiationService.stub(ITelemetryService, NullTelemetryService);
		instantiationService.stub(IModelService, stubModelService(instantiationService));
		instantiationService.stub(ISearchService, {});
		instantiationService.stub(ISearchService, 'search', PPromise.as({ results: [] }));
	});

	teardown(() => {
		restoreStubs.forEach(element => {
			element.restore();
		});
	});

	test('Search Model: Search adds to results', function () {
		let results = [aRawMatch('file://c:/1', aLineMatch('preview 1', 1, [[1, 3], [4, 7]])), aRawMatch('file://c:/2', aLineMatch('preview 2'))];
		instantiationService.stub(ISearchService, 'search', PPromise.as({ results: results }));

		let testObject: SearchModel = instantiationService.createInstance(SearchModel);
		testObject.search({ contentPattern: { pattern: 'somestring' }, type: 1, folderQueries });

		let actual = testObject.searchResult.matches();

		assert.equal(2, actual.length);
		assert.equal('file://c:/1', actual[0].resource().toString());

		let actuaMatches = actual[0].matches();
		assert.equal(2, actuaMatches.length);
		assert.equal('preview 1', actuaMatches[0].text());
		assert.ok(new Range(2, 2, 2, 5).equalsRange(actuaMatches[0].range()));
		assert.equal('preview 1', actuaMatches[1].text());
		assert.ok(new Range(2, 5, 2, 12).equalsRange(actuaMatches[1].range()));

		actuaMatches = actual[1].matches();
		assert.equal(1, actuaMatches.length);
		assert.equal('preview 2', actuaMatches[0].text());
		assert.ok(new Range(2, 1, 2, 2).equalsRange(actuaMatches[0].range()));
	});

	test('Search Model: Search adds to results during progress', function (done) {
		let results = [aRawMatch('file://c:/1', aLineMatch('preview 1', 1, [[1, 3], [4, 7]])), aRawMatch('file://c:/2', aLineMatch('preview 2'))];
		let promise = new DeferredPPromise<ISearchComplete, ISearchProgressItem>();
		instantiationService.stub(ISearchService, 'search', promise);

		let testObject = instantiationService.createInstance(SearchModel);
		let result = testObject.search({ contentPattern: { pattern: 'somestring' }, type: 1, folderQueries });

		promise.progress(results[0]);
		promise.progress(results[1]);
		promise.complete({ results: [], stats: testSearchStats });

		result.done(() => {
			let actual = testObject.searchResult.matches();

			assert.equal(2, actual.length);
			assert.equal('file://c:/1', actual[0].resource().toString());

			let actuaMatches = actual[0].matches();
			assert.equal(2, actuaMatches.length);
			assert.equal('preview 1', actuaMatches[0].text());
			assert.ok(new Range(2, 2, 2, 5).equalsRange(actuaMatches[0].range()));
			assert.equal('preview 1', actuaMatches[1].text());
			assert.ok(new Range(2, 5, 2, 12).equalsRange(actuaMatches[1].range()));

			actuaMatches = actual[1].matches();
			assert.equal(1, actuaMatches.length);
			assert.equal('preview 2', actuaMatches[0].text());
			assert.ok(new Range(2, 1, 2, 2).equalsRange(actuaMatches[0].range()));

			done();
		});
	});

	test('Search Model: Search reports telemetry on search completed', function () {
		let target = instantiationService.spy(ITelemetryService, 'publicLog');
		let results = [aRawMatch('file://c:/1', aLineMatch('preview 1', 1, [[1, 3], [4, 7]])), aRawMatch('file://c:/2', aLineMatch('preview 2'))];
		instantiationService.stub(ISearchService, 'search', PPromise.as({ results: results }));

		let testObject = instantiationService.createInstance(SearchModel);
//.........这里部分代码省略.........
开发者ID:JarnoNijboer,项目名称:vscode,代码行数:101,代码来源:searchModel.test.ts

示例2: suite

suite('Search Actions', () => {

	let instantiationService: TestInstantiationService;
	let counter: number;

	setup(() => {
		instantiationService = new TestInstantiationService();
		instantiationService.stub(IModelService, stubModelService(instantiationService));
		instantiationService.stub(IKeybindingService, {});
		instantiationService.stub(IKeybindingService, 'resolveKeybinding', (keybinding: Keybinding) => [new USLayoutResolvedKeybinding(keybinding, OS)]);
		instantiationService.stub(IKeybindingService, 'lookupKeybinding', (id: string) => null);
		counter = 0;
	});

	test('get next element to focus after removing a match when it has next sibling file', function () {
		let fileMatch1 = aFileMatch();
		let fileMatch2 = aFileMatch();
		let data = [fileMatch1, aMatch(fileMatch1), aMatch(fileMatch1), fileMatch2, aMatch(fileMatch2), aMatch(fileMatch2)];
		let tree = aTree(data);
		let target = data[2];
		let testObject: ReplaceAction = instantiationService.createInstance(ReplaceAction, tree, target, null);

		let actual = testObject.getElementToFocusAfterRemoved(tree, target);

		assert.equal(data[4], actual);
	});

	test('get next element to focus after removing a match when it does not have next sibling match', function () {
		let fileMatch1 = aFileMatch();
		let fileMatch2 = aFileMatch();
		let data = [fileMatch1, aMatch(fileMatch1), aMatch(fileMatch1), fileMatch2, aMatch(fileMatch2), aMatch(fileMatch2)];
		let tree = aTree(data);
		let target = data[5];
		let testObject: ReplaceAction = instantiationService.createInstance(ReplaceAction, tree, target, null);

		let actual = testObject.getElementToFocusAfterRemoved(tree, target);

		assert.equal(data[4], actual);
	});

	test('get next element to focus after removing a match when it does not have next sibling match and previous match is file match', function () {
		let fileMatch1 = aFileMatch();
		let fileMatch2 = aFileMatch();
		let data = [fileMatch1, aMatch(fileMatch1), aMatch(fileMatch1), fileMatch2, aMatch(fileMatch2)];
		let tree = aTree(data);
		let target = data[4];
		let testObject: ReplaceAction = instantiationService.createInstance(ReplaceAction, tree, target, null);

		let actual = testObject.getElementToFocusAfterRemoved(tree, target);

		assert.equal(data[2], actual);
	});

	test('get next element to focus after removing a match when it is the only match', function () {
		let fileMatch1 = aFileMatch();
		let data = [fileMatch1, aMatch(fileMatch1)];
		let tree = aTree(data);
		let target = data[1];
		let testObject: ReplaceAction = instantiationService.createInstance(ReplaceAction, tree, target, null);

		let actual = testObject.getElementToFocusAfterRemoved(tree, target);

		assert.equal(void 0, actual);
	});

	test('get next element to focus after removing a file match when it has next sibling', function () {
		let fileMatch1 = aFileMatch();
		let fileMatch2 = aFileMatch();
		let fileMatch3 = aFileMatch();
		let data = [fileMatch1, aMatch(fileMatch1), fileMatch2, aMatch(fileMatch2), fileMatch3, aMatch(fileMatch3)];
		let tree = aTree(data);
		let target = data[2];
		let testObject: ReplaceAction = instantiationService.createInstance(ReplaceAction, tree, target, null);

		let actual = testObject.getElementToFocusAfterRemoved(tree, target);

		assert.equal(data[4], actual);
	});

	test('get next element to focus after removing a file match when it has no next sibling', function () {
		let fileMatch1 = aFileMatch();
		let fileMatch2 = aFileMatch();
		let fileMatch3 = aFileMatch();
		let data = [fileMatch1, aMatch(fileMatch1), fileMatch2, aMatch(fileMatch2), fileMatch3, aMatch(fileMatch3)];
		let tree = aTree(data);
		let target = data[4];
		let testObject: ReplaceAction = instantiationService.createInstance(ReplaceAction, tree, target, null);

		let actual = testObject.getElementToFocusAfterRemoved(tree, target);

		assert.equal(data[3], actual);
	});

	test('get next element to focus after removing a file match when it is only match', function () {
		let fileMatch1 = aFileMatch();
		let data = [fileMatch1, aMatch(fileMatch1)];
		let tree = aTree(data);
		let target = data[0];
		let testObject: ReplaceAction = instantiationService.createInstance(ReplaceAction, tree, target, null);

//.........这里部分代码省略.........
开发者ID:KTXSoftware,项目名称:KodeStudio,代码行数:101,代码来源:searchActions.test.ts

示例3: stubModelService

	function stubModelService(instantiationService: TestInstantiationService): IModelService {
		instantiationService.stub(IConfigurationService, new TestConfigurationService());
		return instantiationService.createInstance(ModelServiceImpl);
	}
开发者ID:JarnoNijboer,项目名称:vscode,代码行数:4,代码来源:searchModel.test.ts

示例4: suite

suite('Search - Viewlet', () => {
	let instantiation: TestInstantiationService;

	setup(() => {
		instantiation = new TestInstantiationService();
		instantiation.stub(IModelService, stubModelService(instantiation));
		instantiation.set(IWorkspaceContextService, new TestContextService(TestWorkspace));
	});

	test('Data Source', function () {
		let ds = instantiation.createInstance(SearchDataSource);
		let result: SearchResult = instantiation.createInstance(SearchResult, null);
		result.query = { type: 1, folderQueries: [{ folder: uri.parse('file://c:/') }] };
		result.add([{
			resource: uri.parse('file:///c:/foo'),
			lineMatches: [{ lineNumber: 1, preview: 'bar', offsetAndLengths: [[0, 1]] }]
		}]);

		let fileMatch = result.matches()[0];
		let lineMatch = fileMatch.matches()[0];

		assert.equal(ds.getId(null, result), 'root');
		assert.equal(ds.getId(null, fileMatch), 'file:///c%3A/foo');
		assert.equal(ds.getId(null, lineMatch), 'file:///c%3A/foo>1>0b');

		assert(!ds.hasChildren(null, 'foo'));
		assert(ds.hasChildren(null, result));
		assert(ds.hasChildren(null, fileMatch));
		assert(!ds.hasChildren(null, lineMatch));
	});

	test('Sorter', function () {
		let fileMatch1 = aFileMatch('C:\\foo');
		let fileMatch2 = aFileMatch('C:\\with\\path');
		let fileMatch3 = aFileMatch('C:\\with\\path\\foo');
		let lineMatch1 = new Match(fileMatch1, 'bar', 1, 1, 1);
		let lineMatch2 = new Match(fileMatch1, 'bar', 2, 1, 1);
		let lineMatch3 = new Match(fileMatch1, 'bar', 2, 1, 1);

		let s = new SearchSorter();

		assert(s.compare(null, fileMatch1, fileMatch2) < 0);
		assert(s.compare(null, fileMatch2, fileMatch1) > 0);
		assert(s.compare(null, fileMatch1, fileMatch1) === 0);
		assert(s.compare(null, fileMatch2, fileMatch3) < 0);

		assert(s.compare(null, lineMatch1, lineMatch2) < 0);
		assert(s.compare(null, lineMatch2, lineMatch1) > 0);
		assert(s.compare(null, lineMatch2, lineMatch3) === 0);
	});

	function aFileMatch(path: string, searchResult?: SearchResult, ...lineMatches: ILineMatch[]): FileMatch {
		let rawMatch: IFileMatch = {
			resource: uri.file('C:\\' + path),
			lineMatches: lineMatches
		};
		return instantiation.createInstance(FileMatch, null, null, searchResult, rawMatch);
	}

	function stubModelService(instantiationService: TestInstantiationService): IModelService {
		instantiationService.stub(IConfigurationService, new TestConfigurationService());
		return instantiationService.createInstance(ModelServiceImpl);
	}
});
开发者ID:AlexxNica,项目名称:sqlopsstudio,代码行数:64,代码来源:searchViewlet.test.ts

示例5: setup

	setup(() => {
		instantiation = new TestInstantiationService();
		instantiation.stub(IModelService, stubModelService(instantiation));
		instantiation.set(IWorkspaceContextService, new TestContextService(TestWorkspace));
	});
开发者ID:AlexxNica,项目名称:sqlopsstudio,代码行数:5,代码来源:searchViewlet.test.ts

示例6: setup

	setup(() => {
		instantiationService = new TestInstantiationService();
		instantiationService.stub(INotificationService, new TestNotificationService());
		instantiationService.stub(IHistoryService, new TestHistoryService());
	});
开发者ID:costincaraivan,项目名称:vscode,代码行数:5,代码来源:terminalInstance.test.ts

示例7: setup

	setup(() => {
		instantiation = new TestInstantiationService();
		instantiation.stub(IModelService, stubModelService(instantiation));
	});
开发者ID:FabianLauer,项目名称:vscode,代码行数:4,代码来源:searchViewlet.test.ts

示例8: suite

suite('SearchResult', () => {

	let instantiationService: TestInstantiationService;

	setup(() => {
		instantiationService = new TestInstantiationService();
		instantiationService.stub(ITelemetryService, NullTelemetryService);
		instantiationService.stub(IModelService, stubModelService(instantiationService));
		instantiationService.stubPromise(IReplaceService, {});
		instantiationService.stubPromise(IReplaceService, 'replace', null);
	});

	test('Line Match', function () {
		let fileMatch = aFileMatch('folder\\file.txt', null);
		let lineMatch = new Match(fileMatch, 'foo bar', 1, 0, 3);
		assert.equal(lineMatch.text(), 'foo bar');
		assert.equal(lineMatch.range().startLineNumber, 2);
		assert.equal(lineMatch.range().endLineNumber, 2);
		assert.equal(lineMatch.range().startColumn, 1);
		assert.equal(lineMatch.range().endColumn, 4);
		assert.equal('file:///c%3A/folder/file.txt>1>0foo', lineMatch.id());
	});

	test('Line Match - Remove', function () {
		let fileMatch = aFileMatch('folder\\file.txt', aSearchResult(), ...[{
			preview: 'foo bar',
			lineNumber: 1,
			offsetAndLengths: [[0, 3]]
		}]);
		let lineMatch = fileMatch.matches()[0];
		fileMatch.remove(lineMatch);
		assert.equal(fileMatch.matches().length, 0);
	});

	test('File Match', function () {
		let fileMatch = aFileMatch('folder\\file.txt');
		assert.equal(fileMatch.matches(), 0);
		assert.equal(fileMatch.resource().toString(), 'file:///c%3A/folder/file.txt');
		assert.equal(fileMatch.name(), 'file.txt');

		fileMatch = aFileMatch('file.txt');
		assert.equal(fileMatch.matches(), 0);
		assert.equal(fileMatch.resource().toString(), 'file:///c%3A/file.txt');
		assert.equal(fileMatch.name(), 'file.txt');
	});

	test('File Match: Select an existing match', function () {
		let testObject = aFileMatch('folder\\file.txt', aSearchResult(), ...[{
			preview: 'foo',
			lineNumber: 1,
			offsetAndLengths: [[0, 3]]
		}, {
			preview: 'bar',
			lineNumber: 1,
			offsetAndLengths: [[5, 3]]
		}]);

		testObject.setSelectedMatch(testObject.matches()[0]);

		assert.equal(testObject.matches()[0], testObject.getSelectedMatch());
	});

	test('File Match: Select non existing match', function () {
		let testObject = aFileMatch('folder\\file.txt', aSearchResult(), ...[{
			preview: 'foo',
			lineNumber: 1,
			offsetAndLengths: [[0, 3]]
		}, {
			preview: 'bar',
			lineNumber: 1,
			offsetAndLengths: [[5, 3]]
		}]);
		let target = testObject.matches()[0];
		testObject.remove(target);

		testObject.setSelectedMatch(target);

		assert.equal(undefined, testObject.getSelectedMatch());
	});

	test('File Match: isSelected return true for selected match', function () {
		let testObject = aFileMatch('folder\\file.txt', aSearchResult(), ...[{
			preview: 'foo',
			lineNumber: 1,
			offsetAndLengths: [[0, 3]]
		}, {
			preview: 'bar',
			lineNumber: 1,
			offsetAndLengths: [[5, 3]]
		}]);
		let target = testObject.matches()[0];
		testObject.setSelectedMatch(target);

		assert.ok(testObject.isMatchSelected(target));
	});

	test('File Match: isSelected return false for un-selected match', function () {
		let testObject = aFileMatch('folder\\file.txt', aSearchResult(), ...[{
			preview: 'foo',
			lineNumber: 1,
//.........这里部分代码省略.........
开发者ID:StateFarmIns,项目名称:vscode,代码行数:101,代码来源:searchResult.test.ts

示例9: aSearchResult

	function aSearchResult(): SearchResult {
		let searchModel = instantiationService.createInstance(SearchModel);
		return searchModel.searchResult;
	}
开发者ID:StateFarmIns,项目名称:vscode,代码行数:4,代码来源:searchResult.test.ts

示例10: aSearchResult

	function aSearchResult(): SearchResult {
		let searchModel = instantiationService.createInstance(SearchModel);
		searchModel.searchResult.query = { type: 1, folderQueries: [{ folder: URI.parse('file://c:/') }] };
		return searchModel.searchResult;
	}
开发者ID:AllureFer,项目名称:vscode,代码行数:5,代码来源:searchResult.test.ts


注:本文中的vs/platform/instantiation/test/common/instantiationServiceMock.TestInstantiationService类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。