find.test.ts 2.8 KB
Newer Older
1 2 3 4 5 6 7 8
/*---------------------------------------------------------------------------------------------
 *  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 { Position } from 'vs/editor/common/core/position';
import { Range } from 'vs/editor/common/core/range';
9
import { getSelectionSearchString } from 'vs/editor/contrib/find/findController';
A
Alex Dima 已提交
10
import { withTestCodeEditor } from 'vs/editor/test/browser/testCodeEditor';
11 12 13 14 15


suite('Find', () => {

	test('search string at position', () => {
A
Alex Dima 已提交
16
		withTestCodeEditor([
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
			'ABC DEF',
			'0123 456'
		], {}, (editor, cursor) => {

			// The cursor is at the very top, of the file, at the first ABC
			let searchStringAtTop = getSelectionSearchString(editor);
			assert.equal(searchStringAtTop, 'ABC');

			// Move cursor to the end of ABC
			editor.setPosition(new Position(1, 3));
			let searchStringAfterABC = getSelectionSearchString(editor);
			assert.equal(searchStringAfterABC, 'ABC');

			// Move cursor to DEF
			editor.setPosition(new Position(1, 5));
			let searchStringInsideDEF = getSelectionSearchString(editor);
			assert.equal(searchStringInsideDEF, 'DEF');

		});
	});

	test('search string with selection', () => {
A
Alex Dima 已提交
39
		withTestCodeEditor([
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
			'ABC DEF',
			'0123 456'
		], {}, (editor, cursor) => {

			// Select A of ABC
			editor.setSelection(new Range(1, 1, 1, 2));
			let searchStringSelectionA = getSelectionSearchString(editor);
			assert.equal(searchStringSelectionA, 'A');

			// Select BC of ABC
			editor.setSelection(new Range(1, 2, 1, 4));
			let searchStringSelectionBC = getSelectionSearchString(editor);
			assert.equal(searchStringSelectionBC, 'BC');

			// Select BC DE
			editor.setSelection(new Range(1, 2, 1, 7));
			let searchStringSelectionBCDE = getSelectionSearchString(editor);
			assert.equal(searchStringSelectionBCDE, 'BC DE');

		});
	});

	test('search string with multiline selection', () => {
A
Alex Dima 已提交
63
		withTestCodeEditor([
64 65 66 67 68 69 70 71 72 73 74 75 76 77
			'ABC DEF',
			'0123 456'
		], {}, (editor, cursor) => {

			// Select first line and newline
			editor.setSelection(new Range(1, 1, 2, 1));
			let searchStringSelectionWholeLine = getSelectionSearchString(editor);
			assert.equal(searchStringSelectionWholeLine, null);

			// Select first line and chunk of second
			editor.setSelection(new Range(1, 1, 2, 4));
			let searchStringSelectionTwoLines = getSelectionSearchString(editor);
			assert.equal(searchStringSelectionTwoLines, null);

R
ryenus 已提交
78
			// Select end of first line newline and chunk of second
79 80 81 82 83 84 85
			editor.setSelection(new Range(1, 7, 2, 4));
			let searchStringSelectionSpanLines = getSelectionSearchString(editor);
			assert.equal(searchStringSelectionSpanLines, null);

		});
	});

86
});