<commit_before>/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/
'use strict';

import * as assert from 'assert';
import URI from 'vs/base/common/uri';
import { Selection } from 'vs/editor/common/core/selection';
import { SnippetVariablesResolver } from 'vs/editor/contrib/snippet/common/snippetVariables';
import { MockCodeEditor, withMockCodeEditor } from 'vs/editor/test/common/mocks/mockCodeEditor';
import { Model } from 'vs/editor/common/model/model';

suite('Snippet Variables Resolver', function () {

	const model = Model.createFromString('', undefined, undefined, URI.parse('file:///foo/files/text.txt'));

	function variablesTest(callback: (editor: MockCodeEditor, resolver: SnippetVariablesResolver) => any) {


		const lines: string[] = [
			'this is line one',
			'this is line two'
		];

		model.setValue(lines.join('\n'));

		withMockCodeEditor(lines, { model }, editor => {
			callback(editor, new SnippetVariablesResolver(editor));
		});
	}

	test('editor variables, basics', function () {

		variablesTest((editor, resolver) => {
			assert.equal(resolver.resolve('TM_FILENAME'), 'text.txt');
			assert.equal(resolver.resolve('something'), undefined);

			editor.setModel(null);
			assert.equal(resolver.resolve('TM_FILENAME'), undefined);
		});
	});

	test('editor variables, file/dir', function () {

		variablesTest((editor, resolver) => {
			assert.equal(resolver.resolve('TM_FILENAME'), 'text.txt');
			assert.equal(resolver.resolve('TM_DIRECTORY'), '/foo/files');
			assert.equal(resolver.resolve('TM_FILEPATH'), '/foo/files/text.txt');

			editor.setModel(Model.createFromString('', undefined, undefined, URI.parse('http://www.pb.o/abc/def/ghi')));
			assert.equal(resolver.resolve('TM_FILENAME'), 'ghi');
			assert.equal(resolver.resolve('TM_DIRECTORY'), '/abc/def');
			assert.equal(resolver.resolve('TM_FILEPATH'), '/abc/def/ghi');
		});
	});

	test('editor variables, selection', function () {

		variablesTest((editor, resolver) => {

			editor.setSelection(new Selection(1, 2, 2, 3));
			assert.equal(resolver.resolve('TM_SELECTED_TEXT'), 'his is line one\nth');
			assert.equal(resolver.resolve('TM_CURRENT_LINE'), 'this is line two');
			assert.equal(resolver.resolve('TM_LINE_INDEX'), '1');
			assert.equal(resolver.resolve('TM_LINE_NUMBER'), '2');<commit_msg>don't run fwd-slash tests on windows, #4956<commit_after>/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/
'use strict';

import * as assert from 'assert';
import { isWindows } from 'vs/base/common/platform';
import URI from 'vs/base/common/uri';
import { Selection } from 'vs/editor/common/core/selection';
import { SnippetVariablesResolver } from 'vs/editor/contrib/snippet/common/snippetVariables';
import { MockCodeEditor, withMockCodeEditor } from 'vs/editor/test/common/mocks/mockCodeEditor';
import { Model } from 'vs/editor/common/model/model';

suite('Snippet Variables Resolver', function () {

	const model = Model.createFromString('', undefined, undefined, URI.parse('file:///foo/files/text.txt'));

	function variablesTest(callback: (editor: MockCodeEditor, resolver: SnippetVariablesResolver) => any) {


		const lines: string[] = [
			'this is line one',
			'this is line two'
		];

		model.setValue(lines.join('\n'));

		withMockCodeEditor(lines, { model }, editor => {
			callback(editor, new SnippetVariablesResolver(editor));
		});
	}

	test('editor variables, basics', function () {

		variablesTest((editor, resolver) => {
			assert.equal(resolver.resolve('TM_FILENAME'), 'text.txt');
			assert.equal(resolver.resolve('something'), undefined);

			editor.setModel(null);
			assert.equal(resolver.resolve('TM_FILENAME'), undefined);
		});
	});

	test('editor variables, file/dir', function () {

		variablesTest((editor, resolver) => {
			assert.equal(resolver.resolve('TM_FILENAME'), 'text.txt');
			if (!isWindows) {
				assert.equal(resolver.resolve('TM_DIRECTORY'), '/foo/files');
				assert.equal(resolver.resolve('TM_FILEPATH'), '/foo/files/text.txt');
			}

			editor.setModel(Model.createFromString('', undefined, undefined, URI.parse('http://www.pb.o/abc/def/ghi')));
			assert.equal(resolver.resolve('TM_FILENAME'), 'ghi');
			if (!isWindows) {
				assert.equal(resolver.resolve('TM_DIRECTORY'), '/abc/def');
				assert.equal(resolver.resolve('TM_FILEPATH'), '/abc/def/ghi');
			}
		});
	});

	test('editor variables, selection', function () {

		variablesTest((editor, resolver) => {

			editor.setSelection(new Selection(1, 2, 2, 3));
			assert.equal(resolver.resolve('TM_SELECTED_TEXT'), 'his is line one\nth');
			assert.equal(resolver.resolve('TM_CURRENT_LINE'), 'this is line two');
			assert.equal(resolver.resolve('TM_LINE_INDEX'), '1');
			assert.equal(resolver.resolve('TM_LINE_NUMBER'), '2');
{'fraction_non_alphanumeric': 0.22772462952541736, 'fraction_numerical': 0.0030013130744700805, 'mean_word_length': 3.514817950889077, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1694155', 'n_tokens_mistral': 1687, 'n_tokens_neox': 1527, 'n_words': 303}