Skip to content

Commit

Permalink
Combined text search result tests
Browse files Browse the repository at this point in the history
  • Loading branch information
roblourens committed Oct 26, 2018
1 parent 36d5e04 commit 5d68db0
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
53 changes: 53 additions & 0 deletions src/vs/workbench/services/search/test/common/searchHelpers.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as assert from 'assert';
import { ITextModel, FindMatch } from 'vs/editor/common/model';
import { editorMatchesToTextSearchResults } from 'vs/workbench/services/search/common/searchHelpers';
import { Range } from 'vs/editor/common/core/range';

suite('editorMatchesToTextSearchResults', () => {
const mockTextModel: ITextModel = <ITextModel>{
getLineContent(lineNumber: number): string {
return '' + lineNumber;
}
};

test('simple', () => {
const results = editorMatchesToTextSearchResults([new FindMatch(new Range(6, 1, 6, 2), null)], mockTextModel);
assert.equal(results.length, 1);
assert.equal(results[0].preview.text, '6');
assert.deepEqual(results[0].preview.matches, [new Range(0, 0, 0, 1)]);
assert.deepEqual(results[0].ranges, [new Range(5, 0, 5, 1)]);
});

test('multiple', () => {
const results = editorMatchesToTextSearchResults(
[
new FindMatch(new Range(6, 1, 6, 2), null),
new FindMatch(new Range(6, 4, 8, 2), null),
new FindMatch(new Range(9, 1, 10, 3), null),
],
mockTextModel);
assert.equal(results.length, 2);
assert.deepEqual(results[0].preview.matches, [
new Range(0, 0, 0, 1),
new Range(0, 3, 2, 1),
]);
assert.deepEqual(results[0].ranges, [
new Range(5, 0, 5, 1),
new Range(5, 3, 7, 1),
]);
assert.equal(results[0].preview.text, '6\n7\n8');

assert.deepEqual(results[1].preview.matches, [
new Range(0, 0, 1, 2),
]);
assert.deepEqual(results[1].ranges, [
new Range(8, 0, 9, 2),
]);
assert.equal(results[1].preview.text, '9\n10');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class TestSearchEngine implements ISearchEngine<IRawFileMatch> {

const testTimeout = 5000;

suite('SearchService', () => {
suite('RawSearchService', () => {

const rawSearch: IFileQuery = {
type: QueryType.File,
Expand Down

0 comments on commit 5d68db0

Please sign in to comment.